diff -r af75a1894a32 -r 5685602aeb9c src/proto2/GameState.hh --- a/src/proto2/GameState.hh Sun Nov 09 21:51:13 2008 +0000 +++ b/src/proto2/GameState.hh Sun Nov 09 22:02:03 2008 +0000 @@ -16,13 +16,18 @@ #define MAP_DIM_W 800 #define MAP_DIM_H 640 +// forward-declare GameState +class GameState; + class Player { protected: Coordinate position; + GameState &state; + public: - Player(Coordinate c, bool visible) : position(c), dimensions(PLAYER_DIM_W, PLAYER_DIM_H), visible(visible) {} + Player(GameState &state, Coordinate c, bool visible) : position(c), state(state), dimensions(PLAYER_DIM_W, PLAYER_DIM_H), visible(visible) {} PlayerType type; Dimension dimensions; @@ -38,36 +43,23 @@ * * Returns true if valid move (not out of bounds), false otherwise (doesn't change position) */ - bool updatePosition (Coordinate p) { - // unsigned... - if (p.x > dimensions.w || p.y > dimensions.h) { - // out-of-bounds - return false; - } - - // valid - position = p; - - return true; - } + bool updatePosition (Coordinate p); }; class LocalPlayer : public Player { protected: - LocalPlayer (Coordinate c, bool visible) : Player(c, visible) { } + LocalPlayer (GameState &state, Coordinate c, bool visible) : Player(state, c, visible) { } public: virtual bool move (PositionDelta d) { - return true; - - //return updatePosition(position + d); + return updatePosition(position + d); } }; class RemotePlayer : public Player { protected: - RemotePlayer (Coordinate c, bool visible) : Player(c, visible) { } + RemotePlayer (GameState &state, Coordinate c, bool visible) : Player(state, c, visible) { } }; @@ -82,6 +74,14 @@ GameState (void) : map_dimensions(MAP_DIM_W, MAP_DIM_H), local_player(NULL) { } + + /* + * Check if the given coordinate is valid + */ + bool isValidCoordinate (const Coordinate &p) { + // unsigned... + return !(p.x > map_dimensions.w || p.y > map_dimensions.h); + } /* * This will return NULL if we don't have a local player - yet