summaryrefslogtreecommitdiffstats
path: root/Game.h
blob: f9a59695252a0a6e68dd0fb9f2ba1cdedcf3c0fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef _GAME_H
#define _GAME_H

#include "Player.h"
#include "Field.h"
#include <math.h>
#include <stdlib.h>

const PlayerColor playerColors[] = { 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0x88FF88, 0xFF8888};
const uint numColors = sizeof(playerColors)/sizeof(PlayerColor);

class Game
{
public:
	Game(int width, int height);
	virtual ~Game(void);

public:
	/**
	 * Pauses the game
	 **/
	void pauseGame();
	/**
	 * Resumes the game
	 **/
	void resumeGame();
	/**
	 * Toggle between pause & resume
	 **/
	void toggleGame();
	/**
	 * Returns true if the game is not paused
	 **/
	bool isRunning();
	/**
	 * Restarts the game. It will not be paused. All dead player will live again, at original positions and original directions.
	 **/
	void restart();
	/**
	 * Starts the game the first time. The game will be paused.
	 **/
	void start();
	/**
	 * Go for 1 round if enough time passed
	 **/
	void updateGame(uint timeElapsedMs);
	/**
	 * Returns a specific player giver its ID
	 **/
	Player* getPlayerByID(PlayerNumber id);
	/**
	 * Returns the field
	 **/
	Field& getField();
	/**
	 * Changed the size of the game and the field
	 **/
	void setSize(int width, int height);
	/**
	 * Adds a new player with default parameters.
	 **/
	Player* addPlayer();

private:
	void initField(int width, int height);
	void initPlayer(Player* pPlayer, PlayerNumber playerID);
	void placePlayers();
	static PlayerColor getColor(PlayerNumber n);
	void killPlayer(Player *player);

	std::vector<Player*> m_vpPlayers;
	bool m_gameRunning;
	Field m_Field;
	int m_width;
	int m_height;
};

#endif