# HG changeset patch # User Jeremy Thurgood # Date 1282574847 -7200 # Node ID 23d2c58369fcb722c22293c8e377b8c1ca4c3979 # Parent 9048cf43f61351cba154bca26459a594aeff1eb6 Some game logic test stuff. diff -r 9048cf43f613 -r 23d2c58369fc gamelib/tests/__init__.py diff -r 9048cf43f613 -r 23d2c58369fc gamelib/tests/test_game_logic.py --- /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') diff -r 9048cf43f613 -r 23d2c58369fc scripts/build_unix.sh --- 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