Created
October 21, 2016 01:13
-
-
Save nicktimko/e3a9777d854621193aa746f2de95fe46 to your computer and use it in GitHub Desktop.
ChipyDojo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cmd | |
import textwrap | |
from collections import Counter | |
dungeon = { | |
(2, 1): 'hat', | |
(2, 2): 'goblin', | |
(2, 4): 'machete', | |
} | |
no_opponent = "The Goblin isn't available" | |
class GameCmd(cmd.Cmd): | |
prompt = '\nWhat would you like to do? ' | |
def __init__(self): | |
super().__init__() | |
self.location = [0, 0] | |
self.inventory = Counter() | |
def default(self, arg): | |
print("I don't know how to do that! ") | |
def do_walk(self, direction): | |
print("You have walked in the direction {}!".format(direction)) | |
if direction == 'north': | |
self.location[0] += 1 | |
elif direction == 'south': | |
self.location[0] -= 1 | |
elif direction == 'east': | |
self.location[1] += 1 | |
elif direction == 'west': | |
self.location[1] -= 1 | |
else: | |
print(direction + " is not a direction!") | |
def do_map(self, arg): | |
print("My coordinates are {} {}".format(self.location[0], self.location[1])) | |
def do_pickup(self, arg): | |
try: | |
item = dungeon[tuple(self.location)] | |
except KeyError: | |
print("There are no items here!") | |
return | |
if item == 'goblin': | |
print("The Goblin isn't available") | |
return | |
print("You got {}".format(item)) | |
self.inventory[item] += 1 | |
dungeon.pop(tuple(self.location)) | |
def do_fight(self, arg): | |
try: | |
item = dungeon[tuple(self.location)] | |
except KeyError: | |
print(no_opponent) | |
return | |
if item != 'goblin': | |
print(no_opponent) | |
return | |
if self.inventory['machete'] > 0: | |
print("You are the WINNER") | |
else: | |
print("You are dead") | |
return True | |
def do_inventory(self, arg): | |
empty = True | |
for item, count in self.inventory.items(): | |
if count <= 0: | |
continue | |
print("I have {} {}(s)".format(count, item)) | |
empty = False | |
if empty: | |
print('Your bags are empty.') | |
def do_look(self, arg): | |
loc = tuple(self.location) | |
try: | |
print('There is a {} here!'.format(dungeon[loc])) | |
except KeyError: | |
print('There is nothing here.') | |
def do_quit(self, arg): | |
return True | |
game = GameCmd() | |
game.cmdloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment