import time import sys import random #Make an action trade so that you can buy stuff color = 'red green orange white yellow pink purple blue brown black'.split() #begin definitions def ShowInstructions(): print ("Do you want to see the instructions? Yes/No") if input().lower().startswith('y'): print('''instructions, instructions, instructions''') print() def GetRandomColor(colorList): colorIndex = random.randint(0, len(colorList) - 1) return colorList[colorIndex] #explore, attack, open door, class MyRoom(object): def __init__( self, my_room_id=None, my_monster_id=None, my_left_door_room_id=None, my_right_door_room_id=None, my_center_door_room_id=None, my_description=None, ): self.room_id=my_room_id self.monster_id=my_monster_id self.left_door_room_id=my_left_door_room_id self.right_door_room_id=my_right_door_room_id self.center_door_room_id=my_center_door_room_id self.description=my_description self.explore_count=0 def ChangeExploreCount(self): self.explore_count=self.explore_count+1 class MyMonster(object): def __init__( self, my_monster_id=None, my_hit_points=None, my_attack_points=None, my_name=None, my_description=None ): self.monster_id=my_monster_id self.hit_points=my_hit_points self.name=my_name self.attack_points=my_attack_points self.description=my_description def change_hit_points(self, change): self.hit_points=self.hit_points+change class MyHuman: def __init__( self, my_hit_points=500, my_attack_points=50, my_gold=0, my_health_potions=0, my_attack_potions=0, my_weapon_attack_points=0 ): self.hit_points=my_hit_points self.attack_points=my_attack_points self.gold=my_gold, self.health_potions=my_health_potions self.attack_potions=my_attack_potions self.weapon_attack_points=my_weapon_attack_points def change_hit_points(self, change): self.hit_points=self.hit_points+change class MyExploreItem(object): def __init__( self, my_explore_item_id=None, my_gold_amount=None, my_health_points=None, my_attack_points=None, my_defense_points=None, my_item_description=None, ): self.explore_item_id=my_explore_item_id self.gold_amount=my_gold_amount self.health_points=my_health_points self.attack_points=my_attack_points self.defense_points=my_defense_points self.item_description=my_item_description self.explore_count=0 def Describe(self): print(self.item_description) MyRoomList[MyCurrentRoomId].ChangeExploreCount() def ActionAttack(): global attack_mode attack_mode='y' print('attack') print(' You: ',h.hit_points, ' ', 'Monster: ', MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].hit_points) print(' Damage to you:', MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].attack_points\ , ' Damage to monster:', h.attack_points) h.change_hit_points(-MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].attack_points) MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].change_hit_points(-h.attack_points) if MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].hit_points<=0: attack_mode='n' print('YOU WON!') print(' | |') print(' \____/') #print starting hit points for human and monster #show damage from human #show damage from monster #ending hitpoints for human and monster def ActionRetreat(): global attack_mode attack_mode='n' print('You safely fled from battle') if MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].hit_points<=0: print(' You: ',h.hit_points, ' ', 'Monster: ', MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].hit_points) def ActionContinue(): MyRoomCount=0 if MyRoomList[MyCurrentRoomId].left_door_room_id!=None: MyRoomCount=MyRoomCount+1 RoomChoice='l' if MyRoomList[MyCurrentRoomId].center_door_room_id!=None: MyRoomCount=MyRoomCount+1 RoomChoice='c' if MyRoomList[MyCurrentRoomId].right_door_room_id!=None: MyRoomCount=MyRoomCount+1 RoomChoice='r' if MyRoomCount!=1: RoomChoice=None if MyRoomList[MyCurrentRoomId].left_door_room_id!=None: print('(L) Open Left Door') if MyRoomList[MyCurrentRoomId].center_door_room_id!=None: print('(C) Open Center Door') if MyRoomList[MyCurrentRoomId].right_door_room_id!=None: print('(R) Open Right Door') print('Which door do you want to go into?') RoomChoice=input().lower() if RoomChoice=='l': return MyRoomList[MyCurrentRoomId].left_door_room_id #print(MyRoomList[MyCurrentRoomId].description) if RoomChoice=='c': return MyRoomList[MyCurrentRoomId].center_door_room_id #print(MyRoomList[MyCurrentRoomId].description) if RoomChoice=='r': return MyRoomList[MyCurrentRoomId].right_door_room_id #print(MyRoomList[MyCurrentRoomId].description) def ActionExplore(): MyRoomList[MyCurrentRoomId].ChangeExploreCount() ExploreIndex = random.randint(0,11) #print(MyExploreItemList[ExploreIndex].item_description) MyExploreItemList[ExploreIndex].Describe() def ActionStandStill(): time.sleep(0.5) print('You stand quietly.') time.sleep(3) def GetAction(): print() if attack_mode=='y': print('(A) Attack') print('(R) Retreat') else: if MyRoomList[MyCurrentRoomId].monster_id!=None: if MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].hit_points>0: print('(A) Attack') print('(C) Continue to next room') #print ('explore_count:' , MyRoomList[MyCurrentRoomId].explore_count) if MyRoomList[MyCurrentRoomId].explore_count < 1: print('(E) Explore') print('(S) Stand Still') print('(Q) Quit') print('What do you want to do?') return input().lower() #Only have attack as an option in rooms with a monster #define rooms MyRoomList=[] #MyRoom(room ID, monster ID, left door room ID, right door room ID, center door room ID, room description) MyRoomList.append(MyRoom(0,None,1,2,None,'''You wake up in a room, and can`t remember how you got there. The room is painted %s.''' %(GetRandomColor(color)))) MyRoomList.append(MyRoom(1,3,None,None,3,'The room is dark and has a bookshelf. A grandfather clock chimes, and ticks. Its golden gem studded hands move speedily across its face.')) MyRoomList.append(MyRoom(2,5,4,None,None,'The room is lit by a candle light and a pile of wood sits by a fireplace.')) MyRoomList.append(MyRoom(3,2,None,5,None,'The room has a bright light in the far corner. There is a chest to your right. A potted plant sits next to the door. You can see what is in it. ')) MyRoomList.append(MyRoom(4,4,6,7,8,'The room is filled with the sound of heavy breathing. There are no doors in sight, and a piano is playing by itself on in the right corner.')) MyRoomList.append(MyRoom(5,1,None,9,None,'A very large dragon takes up most of the room. His shiny, rock hard scales protect piles of gold.')) MyRoomList.append(MyRoom(6,7,None,None,9,'The room is dark and you can not see a thing. A loud hissing comes from the back of the room.')) MyRoomList.append(MyRoom(7,8,9,None,None,'A blinding light fills the room. The room is horribly hot. You can make out the outline of a couch, singed black by the heat.')) MyRoomList.append(MyRoom(8,6,None,None,9,'The room is filled with a dim light even though there are no lights or windows. A dark alcove stands on the left side of the room, beckoning you to explore it.')) MyRoomList.append(MyRoom(8,None,None,None,9,'This is your workshop, this is where the tiki statue trades with you, this is a safe place.')) #Make a room nine that they all lead to. Make it a long hallway that has a door at the end. It could could start crumbling behind you, so you have to type in a sequence of letters that shows up on the scrren. If you type them in fast enough, then you run fast enough. #define monsters MyMonsterList=[] #MyMonster(monster ID, hit points, attack points, name, description) MyMonsterList.append(MyMonster(1,500,50,'dragon','This dreaded beast has crushed castles, and wants to do the same to you.')) MyMonsterList.append(MyMonster(2,200,20,'giant porcupine','You can faintly remember stories about poison on their quills.')) MyMonsterList.append(MyMonster(3,150,15,'man eating plant','Vibrant colors cover its body, and six inch long teeth hang out of its mouth.')) MyMonsterList.append(MyMonster(4,300,30,'minotaur','The minotaur towers over you. He is black, and the light glints off his razor sharp, swordlike horns. ')) MyMonsterList.append(MyMonster(5,30,30,'bats','Bats are only pests, but come in numbers.')) MyMonsterList.append(MyMonster(6,100,10,'mummy','Old and decaying, it moans and slowly walks toward you.')) MyMonsterList.append(MyMonster(7,100,10,'hissing spider','')) MyMonsterList.append(MyMonster(8,300,30,'fire ghoul','')) #define explore MyExploreItemList=[] #MyExploreItem(Item id, Gold Amount, HealthPoints, AttackPoints, DefensePoints, Item Description MyExploreItemList.append(MyExploreItem(0,None,5,5,5,'You found a magic potion! (+5 health points, +5 defense points, +5 attack points)')) MyExploreItemList.append(MyExploreItem(1,None,None,None,None,'''You found a crumpled piece of parchment. It looks to be a ripped of part of something bigger. Can't tell if it is important.''')) MyExploreItemList.append(MyExploreItem(2,None,None,5,None,'You gained five attack points!')) #The piece of parchment is a piece of a map and to win the game you must get a certain amount of them to form a map that you can use to get out and win the game+the player does not know that it is important MyExploreItemList.append(MyExploreItem(3,None,None,None,5,'You gained five defense points!')) MyExploreItemList.append(MyExploreItem(4,200,None,None,None,'You found 200 gold pieces!')) MyExploreItemList.append(MyExploreItem(5,None,None,None,10,'You gained fifteen health points!')) MyExploreItemList.append(MyExploreItem(6,None,10,None,None,'You gained ten health points!')) MyExploreItemList.append(MyExploreItem(7,None,None,15,None,'You found a sword! (+15 attack points)')) MyExploreItemList.append(MyExploreItem(8,50,None,None,None,'You found fifty gold pieces!')) MyExploreItemList.append(MyExploreItem(9,100,None,None,None,'You found 100 gold pieces!')) MyExploreItemList.append(MyExploreItem(10,None,None,None,15,'You found a new helmet! (+15 defense points)')) MyExploreItemList.append(MyExploreItem(11,None,None,None,None,'You found nothing :(')) #test #print('test') #print('Room 0 left door room ID: ',MyRoomList[0].left_door_room_id) #print('Room 1 left room ID: ',MyRoomList[1].left_door_room_id) #begin game print ("Welcome") time.sleep(1) ShowInstructions() MyCurrentRoomId=0 DescriptionCount=0 h=MyHuman() Quit='n' attack_mode='n' print(MyRoomList[MyCurrentRoomId].description) while Quit=='n': #print (monster_id) #if MyRoomList[MyCurrentRoomId].monster_id!=None: #print('Response: ',GetAction()) #print (' Human: ',h.hit_points, ' ', 'Monster: ', MyRoomList[MyCurrentRoomId].monster_id,\ #MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].hit_points) action=GetAction() if attack_mode=='y': print('') if MyRoomList[MyCurrentRoomId].monster_id!=None: if action=='a': ActionAttack() print(attack_mode) #if action=='r': if action=='r': ActionRetreat() print(attack_mode) #print(' Human: ',h.hit_points, ' ', 'Monster: ', MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].hit_points) if action=='e': ActionExplore() if action=='s': ActionStandStill() if action=='c': MyCurrentRoomId=ActionContinue() print('Room: ',MyCurrentRoomId) print(MyRoomList[MyCurrentRoomId].description) if MyCurrentRoomId==9: Quit='y' if action=='q': Quit='y' #h.change_hit_points(-20) #if action=='r' or MyMonsterList[MyRoomList[MyCurrentRoomId].monster_id].hit_points<=0: #attack_mode='n' print('')
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question