changeset 59:23d2c58369fc

Some game logic test stuff.
author Jeremy Thurgood <firxen@gmail.com>
date Mon, 23 Aug 2010 16:47:27 +0200
parents 9048cf43f613
children 90b32447b239
files gamelib/tests/__init__.py gamelib/tests/test_game_logic.py scripts/build_unix.sh
diffstat 2 files changed, 87 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gamelib/tests/test_game_logic.py	Mon Aug 23 16:47:27 2010 +0200
@@ -0,0 +1,86 @@
+import unittest
+
+import pygame
+
+from gamelib import state
+
+from pygame.locals import SWSURFACE
+from gamelib.constants import SCREEN
+
+
+# We need this stuff set up so we can load images and whatnot.
+pygame.display.init()
+pygame.display.set_mode(SCREEN, SWSURFACE)
+
+
+class TestGameLogic(unittest.TestCase):
+    def setUp(self):
+        self.state = state.initial_state()
+
+    def set_game_data(self, key, value, scene, thing=None):
+        gizmo = self.state.scenes[scene]
+        if thing is not None:
+            gizmo = gizmo.things[thing]
+        gizmo.set_data(key, value)
+
+    def assert_game_data(self, key, value, scene, thing=None):
+        gizmo = self.state.scenes[scene]
+        if thing is not None:
+            gizmo = gizmo.things[thing]
+        self.assertEquals(value, gizmo.get_data(key))
+
+    def interact_thing(self, scene_name, thing_name, item_name=None):
+        item = None
+        if item_name is not None:
+            item = self.state.items[item_name]
+        self.state.scenes[scene_name].things[thing_name].interact(item)
+
+    def test_cryo_door_closed_hand(self):
+        "The door is closed and we touch it with the hand. No change."
+
+        self.assert_game_data('accessible', True, 'cryo')
+        self.assert_game_data('accessible', False, 'bridge')
+        self.assert_game_data('open', False, 'cryo', 'cryo.door')
+
+        self.interact_thing('cryo', 'cryo.door')
+
+        self.assert_game_data('accessible', True, 'cryo')
+        self.assert_game_data('accessible', False, 'bridge')
+        self.assert_game_data('open', False, 'cryo', 'cryo.door')
+
+    def test_cryo_door_closed_titanium_leg(self):
+        "The door is closed and we touch it with the titanium leg. It opens."
+
+        self.assert_game_data('accessible', True, 'cryo')
+        self.assert_game_data('accessible', False, 'bridge')
+        self.assert_game_data('open', False, 'cryo', 'cryo.door')
+
+        self.interact_thing('cryo', 'cryo.door', 'titanium_leg')
+
+        self.assert_game_data('accessible', True, 'cryo')
+        self.assert_game_data('accessible', True, 'bridge')
+        self.assert_game_data('open', True, 'cryo', 'cryo.door')
+
+    def test_cryo_door_open_hand(self):
+        "The door is open and we touch it with the hand. No change."
+
+        self.set_game_data('accessible', True, 'bridge')
+        self.set_game_data('open', True, 'cryo', 'cryo.door')
+
+        self.interact_thing('cryo', 'cryo.door')
+
+        self.assert_game_data('accessible', True, 'cryo')
+        self.assert_game_data('accessible', True, 'bridge')
+        self.assert_game_data('open', True, 'cryo', 'cryo.door')
+
+    def test_cryo_door_open_titanium_leg(self):
+        "The door is open and we touch it with the titanium leg. No change."
+
+        self.set_game_data('accessible', True, 'bridge')
+        self.set_game_data('open', True, 'cryo', 'cryo.door')
+
+        self.interact_thing('cryo', 'cryo.door', 'titanium_leg')
+
+        self.assert_game_data('accessible', True, 'cryo')
+        self.assert_game_data('accessible', True, 'bridge')
+        self.assert_game_data('open', True, 'cryo', 'cryo.door')
--- a/scripts/build_unix.sh	Mon Aug 23 15:51:27 2010 +0200
+++ b/scripts/build_unix.sh	Mon Aug 23 16:47:27 2010 +0200
@@ -4,7 +4,7 @@
 
 mkdir -p build/${GAME_NAME} dist
 
-cp -r README.txt run_game.py gamelib Resources build/${GAME_NAME}
+cp -r README.txt run_game.py gamelib tests Resources build/${GAME_NAME}
 
 cd build