From 92591cd60f6346d318735b9a1adf778b57177917 Mon Sep 17 00:00:00 2001 From: adrianna Date: Sun, 6 Mar 2016 00:46:57 +0200 Subject: [PATCH] smartness now required for keypads --- koperkapel/gamelib/keypad.py | 19 +++++++++++-------- koperkapel/gamelib/level.py | 4 ++-- koperkapel/levels/level1.json | 9 ++++++--- koperkapel/loaders/levelloader.py | 2 +- koperkapel/scenes/level.py | 2 +- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/koperkapel/gamelib/keypad.py b/koperkapel/gamelib/keypad.py index b328f39..bf9e084 100644 --- a/koperkapel/gamelib/keypad.py +++ b/koperkapel/gamelib/keypad.py @@ -8,16 +8,19 @@ from ..constants import TILE_SIZE class Keypad(SurfActor): - def __init__(self, x, y, doors): + def __init__(self, x, y, doors, required_smart=0): self._doors = doors self.game_pos = (x, y) + self.required_smart = required_smart surf = images.load(os.path.join('fixtures', 'keypad')) super().__init__(surf, anchor=(0, 0)) - def activate(self, roaches): - # FIXME: Check stats - for door in self._doors: - if door.is_closed(): - door.open() - else: - door.close() + def activate(self, smart): + if smart >= self.required_smart: + for door in self._doors: + if door.is_closed(): + door.open() + else: + door.close() + else: + print("You are not smart enough for this keypad.") diff --git a/koperkapel/gamelib/level.py b/koperkapel/gamelib/level.py index cfbf45e..7641fbc 100644 --- a/koperkapel/gamelib/level.py +++ b/koperkapel/gamelib/level.py @@ -65,10 +65,10 @@ class Level(object): return True return False - def press_keypad(self, x, y, roaches): + def press_keypad(self, x, y, smart): for keypad in self.keypads: if (x, y) == keypad.game_pos: - keypad.activate(roaches) + keypad.activate(smart) def get_friends(self): return self._friends[:] diff --git a/koperkapel/levels/level1.json b/koperkapel/levels/level1.json index f5e920a..7fad44f 100644 --- a/koperkapel/levels/level1.json +++ b/koperkapel/levels/level1.json @@ -4291,7 +4291,8 @@ "keypads": [ [ 6, - 7 + 7, + 0 ] ], "doors": [ @@ -4305,7 +4306,8 @@ "keypads": [ [ 5, - 12 + 12, + 0 ] ], "doors": [ @@ -4323,7 +4325,8 @@ "keypads": [ [ 18, - 9 + 9, + 1 ] ], "doors": [ diff --git a/koperkapel/loaders/levelloader.py b/koperkapel/loaders/levelloader.py index 14db3be..9c3b6cf 100644 --- a/koperkapel/loaders/levelloader.py +++ b/koperkapel/loaders/levelloader.py @@ -65,7 +65,7 @@ class LevelLoader(ResourceLoader): doors.append(new_door) # Add the keypads for keypad in door_info['keypads']: - new_keypad = Keypad(keypad[0], keypad[1], doors) + new_keypad = Keypad(keypad[0], keypad[1], doors, keypad[2]) self._level.keypads.append(new_keypad) for pos in level_data['friendly roaches']: roach = get_friendly_roach(pos[0], pos[1]) diff --git a/koperkapel/scenes/level.py b/koperkapel/scenes/level.py index 54041ba..ca85884 100644 --- a/koperkapel/scenes/level.py +++ b/koperkapel/scenes/level.py @@ -386,7 +386,7 @@ class GameLevelScene(BaseLevelScene): self._level_layer = 'floor' self._mode = 'walk' elif self._level.is_keypad(x, y): - self._level.press_keypad(x, y, self._roaches) + self._level.press_keypad(x, y, self._stats.smart) elif self._level.friend_at(x, y): friend = self._level.friend_at(x, y) self._level.remove_friend(friend) -- 2.34.1