src/proto2/GameState.hh
changeset 25 af75a1894a32
parent 24 b81cb670e6b2
child 26 5685602aeb9c
--- a/src/proto2/GameState.hh	Sun Nov 09 20:40:46 2008 +0000
+++ b/src/proto2/GameState.hh	Sun Nov 09 21:51:13 2008 +0000
@@ -29,12 +29,26 @@
         bool visible;
 
         Coordinate getPosition (void) const {
-            return this->position;
+            return position;
         }
     
     protected:
-        void updatePosition (Coordinate p) {
-            this->position = p;
+        /*
+         * Update position to the given value.
+         *
+         * 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;
         }
 
 };
@@ -44,8 +58,10 @@
         LocalPlayer (Coordinate c, bool visible) : Player(c, visible) { }
     
     public:
-        virtual void move (PositionDelta d) {
-            this->position += d;
+        virtual bool move (PositionDelta d) {
+            return true;
+
+            //return updatePosition(position + d);
         }
 };
 
@@ -66,12 +82,12 @@
         GameState (void) : map_dimensions(MAP_DIM_W, MAP_DIM_H), local_player(NULL) {
 
         }
-
-        LocalPlayer &getLocalPlayer (void) {
-            if (!local_player)
-                throw std::logic_error("getLocalPlayer called with no local player");
-            
-            return *local_player;
+        
+        /*
+         * This will return NULL if we don't have a local player - yet
+         */
+        LocalPlayer *getLocalPlayer (void) {
+            return local_player;
         }
         
         void newLocalPlayer (LocalPlayer *player) {