comparison gamelib/tests/test_game_logic.py @ 59:23d2c58369fc

Some game logic test stuff.
author Jeremy Thurgood <firxen@gmail.com>
date Mon, 23 Aug 2010 16:47:27 +0200
parents
children
comparison
equal deleted inserted replaced
58:9048cf43f613 59:23d2c58369fc
1 import unittest
2
3 import pygame
4
5 from gamelib import state
6
7 from pygame.locals import SWSURFACE
8 from gamelib.constants import SCREEN
9
10
11 # We need this stuff set up so we can load images and whatnot.
12 pygame.display.init()
13 pygame.display.set_mode(SCREEN, SWSURFACE)
14
15
16 class TestGameLogic(unittest.TestCase):
17 def setUp(self):
18 self.state = state.initial_state()
19
20 def set_game_data(self, key, value, scene, thing=None):
21 gizmo = self.state.scenes[scene]
22 if thing is not None:
23 gizmo = gizmo.things[thing]
24 gizmo.set_data(key, value)
25
26 def assert_game_data(self, key, value, scene, thing=None):
27 gizmo = self.state.scenes[scene]
28 if thing is not None:
29 gizmo = gizmo.things[thing]
30 self.assertEquals(value, gizmo.get_data(key))
31
32 def interact_thing(self, scene_name, thing_name, item_name=None):
33 item = None
34 if item_name is not None:
35 item = self.state.items[item_name]
36 self.state.scenes[scene_name].things[thing_name].interact(item)
37
38 def test_cryo_door_closed_hand(self):
39 "The door is closed and we touch it with the hand. No change."
40
41 self.assert_game_data('accessible', True, 'cryo')
42 self.assert_game_data('accessible', False, 'bridge')
43 self.assert_game_data('open', False, 'cryo', 'cryo.door')
44
45 self.interact_thing('cryo', 'cryo.door')
46
47 self.assert_game_data('accessible', True, 'cryo')
48 self.assert_game_data('accessible', False, 'bridge')
49 self.assert_game_data('open', False, 'cryo', 'cryo.door')
50
51 def test_cryo_door_closed_titanium_leg(self):
52 "The door is closed and we touch it with the titanium leg. It opens."
53
54 self.assert_game_data('accessible', True, 'cryo')
55 self.assert_game_data('accessible', False, 'bridge')
56 self.assert_game_data('open', False, 'cryo', 'cryo.door')
57
58 self.interact_thing('cryo', 'cryo.door', 'titanium_leg')
59
60 self.assert_game_data('accessible', True, 'cryo')
61 self.assert_game_data('accessible', True, 'bridge')
62 self.assert_game_data('open', True, 'cryo', 'cryo.door')
63
64 def test_cryo_door_open_hand(self):
65 "The door is open and we touch it with the hand. No change."
66
67 self.set_game_data('accessible', True, 'bridge')
68 self.set_game_data('open', True, 'cryo', 'cryo.door')
69
70 self.interact_thing('cryo', 'cryo.door')
71
72 self.assert_game_data('accessible', True, 'cryo')
73 self.assert_game_data('accessible', True, 'bridge')
74 self.assert_game_data('open', True, 'cryo', 'cryo.door')
75
76 def test_cryo_door_open_titanium_leg(self):
77 "The door is open and we touch it with the titanium leg. No change."
78
79 self.set_game_data('accessible', True, 'bridge')
80 self.set_game_data('open', True, 'cryo', 'cryo.door')
81
82 self.interact_thing('cryo', 'cryo.door', 'titanium_leg')
83
84 self.assert_game_data('accessible', True, 'cryo')
85 self.assert_game_data('accessible', True, 'bridge')
86 self.assert_game_data('open', True, 'cryo', 'cryo.door')