I am trying to create a basic Pacman game in C ++ (I will use the Java syntax in this question, as it is somewhat easier to demonstrate), but I can not find a good design option.
So far I have 4 classes:
- Monster: can be subclassed for monster-specific behavior and contains all the logic for monsters
- Player: Contains the player’s logic
- Map: contains a 2d array representing the map. This array determines which positions are walls or products. Pacman
- Game: contains a player, a map and a list of monsters.
To make it simple:
public class Game {
Player player;
Map map;
ArrayList<Monster> monsters;
public Game() {
player = new Player();
map = new Map();
monsters = new ArrayList<Monster();
monsters.add(new ScaryMonster());
monsters.add(new DumpMonster());
}
public void update() {
player.update();
map.update();
for (Monster monster: monsters) {
monster.update();
}
public void draw() {
map.draw();
player.draw();
for (Monster monster: monsters) {
monster.draw();
}
}
So now I need to create a Game object and call update () and draw () each time. Very simple. But that does not work.
, update() , ( Pacman of the course) . ( ), 2d-. , , ( ). .
map monster update() draw() . . , , OO.
? Observer ( Game - , , - ), : , , , .
.
:)