From 8ac7a65685ffe58529087bbe5a0063d1e0168f5c Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 13 Jan 2013 15:23:46 +0000 Subject: New framework to allow combining items. --- weatbag/action.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'weatbag/action.py') diff --git a/weatbag/action.py b/weatbag/action.py index 9ef0f47..c2274ac 100644 --- a/weatbag/action.py +++ b/weatbag/action.py @@ -1,5 +1,6 @@ import sys from . import words +from weatbag.items import combine def get_action(): """Prompts for an action, splits it into words, and removes any prepositions. @@ -18,7 +19,7 @@ def get_action(): move_directions = {'n','e','s','w','north','east','south','west'} def is_move(do): - return len(do) == 2 and (do[0] in words.move) and (do[1] in move_directions) + return len(do) == 2 and (do[0] in words.move) and (do[1] in move_directions) def handle_action(tile, player, do): if len(do) == 1 and do[0] == 'quit': @@ -35,6 +36,32 @@ def handle_action(tile, player, do): break print(item, '(%d)' % n) + elif len(do) >= 3 and (do[0] in words.combine): + for split in range(2, len(do)): + item1 = ' '.join(do[1:split]) + item2 = ' '.join(do[split:]) + if player.has(item1): + if player.has(item2): + results = combine(item1, item2) + if results is not None: + player.take(item1) + player.take(item2) + player.inventory.update(results) + else: + print("You can't combine {} with {}".format(item1, item2)) + + else: + print("You don't have a {}".format(item2)) + + return + + elif player.has(item2): + print("You don't have a {}".format(item1)) + return + + else: + print("You don't have those items.") + else: tile.action(player, do) -- cgit v1.3 From b95c7a7278ed87863ffc9086ed0eebb6c6227e72 Mon Sep 17 00:00:00 2001 From: Smart Viking Date: Mon, 14 Jan 2013 17:24:17 +0100 Subject: Changed action.get_action to handle prepositions differently --- weatbag/action.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'weatbag/action.py') diff --git a/weatbag/action.py b/weatbag/action.py index c2274ac..73e5a47 100644 --- a/weatbag/action.py +++ b/weatbag/action.py @@ -4,16 +4,14 @@ from weatbag.items import combine def get_action(): """Prompts for an action, splits it into words, and removes any prepositions. - + movement actions will be represented by the move token object in this module, followed by a one-letter direction. """ action = [] while len(action) == 0: action = input('> ').lower().split() - for prep in words.prepositions.intersection(action): - action.remove(prep) - + action = [w for w in action if w not in words.prepositions] return action move_directions = {'n','e','s','w','north','east','south','west'} -- cgit v1.3