author | terom |
Sat, 08 Nov 2008 20:34:14 +0000 | |
changeset 22 | b70d30e1b0fe |
parent 8 | 2de58a6d0395 |
child 24 | b81cb670e6b2 |
permissions | -rw-r--r-- |
3 | 1 |
#ifndef GAMESTATE_HH |
2 |
#define GAMESTATE_HH |
|
3 |
||
4
e28b28b8817c
Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents:
3
diff
changeset
|
4 |
#include "Dimension.hh" |
e28b28b8817c
Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents:
3
diff
changeset
|
5 |
|
5 | 6 |
#include <list> |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
7 |
#include <stdexcept> |
5 | 8 |
|
3 | 9 |
enum PlayerType { |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
10 |
PLAYER_LOCAL, |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
11 |
PLAYER_REMOTE |
3 | 12 |
}; |
13 |
||
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
14 |
#define PLAYER_DIM_W 10 |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
15 |
#define PLAYER_DIM_H 10 |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
16 |
#define MAP_DIM_W 800 |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
17 |
#define MAP_DIM_H 640 |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
18 |
|
3 | 19 |
class Player { |
6 | 20 |
protected: |
3 | 21 |
Coordinate position; |
22 |
||
23 |
public: |
|
4
e28b28b8817c
Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents:
3
diff
changeset
|
24 |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
25 |
Player(Coordinate c, bool visible) : position(c), dimensions(PLAYER_DIM_W, PLAYER_DIM_H), visible(visible) {} |
4
e28b28b8817c
Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents:
3
diff
changeset
|
26 |
|
3 | 27 |
PlayerType type; |
6 | 28 |
Dimension dimensions; |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
29 |
bool visible; |
3 | 30 |
|
4
e28b28b8817c
Drawer lis?tty. Pari metodia gamestateen ja dimensioniin.
ekku
parents:
3
diff
changeset
|
31 |
Coordinate getPosition (void) const { |
3 | 32 |
return this->position; |
33 |
} |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
34 |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
35 |
protected: |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
36 |
void updatePosition (Coordinate p) { |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
37 |
this->position = p; |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
38 |
} |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
39 |
|
3 | 40 |
}; |
41 |
||
42 |
class LocalPlayer : public Player { |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
43 |
protected: |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
44 |
LocalPlayer (Coordinate c, bool visible) : Player(c, visible) { } |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
45 |
|
3 | 46 |
public: |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
47 |
virtual void move (PositionDelta d) { |
3 | 48 |
this->position += d; |
49 |
} |
|
50 |
}; |
|
51 |
||
52 |
class RemotePlayer : public Player { |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
53 |
protected: |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
54 |
RemotePlayer (Coordinate c, bool visible) : Player(c, visible) { } |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
55 |
|
6 | 56 |
}; |
57 |
||
58 |
class GameState { |
|
59 |
public: |
|
60 |
Dimension map_dimensions; |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
61 |
std::list<Player*> player_list; |
6 | 62 |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
63 |
// only one local player is supported |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
64 |
LocalPlayer *local_player; |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
65 |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
66 |
GameState (void) : map_dimensions(MAP_DIM_W, MAP_DIM_H), local_player(NULL) { |
8 | 67 |
|
68 |
} |
|
69 |
||
6 | 70 |
LocalPlayer &getLocalPlayer (void) { |
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
71 |
if (!local_player) |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
72 |
throw std::logic_error("getLocalPlayer called with no local player"); |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
73 |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
74 |
return *local_player; |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
75 |
} |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
76 |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
77 |
void newLocalPlayer (LocalPlayer *player) { |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
78 |
if (local_player) |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
79 |
throw std::logic_error("newLocalPlayer called even though we already have a local player"); |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
80 |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
81 |
player_list.push_back(player); |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
82 |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
83 |
local_player = player; |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
84 |
} |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
85 |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
86 |
void newRemotePlayer (RemotePlayer *player) { |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
87 |
player_list.push_back(player); |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
88 |
} |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
89 |
|
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
90 |
void removePlayer (Player *player) { |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
8
diff
changeset
|
91 |
player_list.remove(player); |
6 | 92 |
} |
93 |
}; |
|
94 |
||
3 | 95 |
#endif |