Python: cannot change between specific array-numbers -
i program. text-based game, rooms. want player jump between rooms, when player in rooms.
#-------------***********game************------------- #this module implements pseudo-random number generators various distributions. random import randint import random #-------------------------------------------------------------------- def showinstructions(): #print main menu , commands print ("---------------------------") print ("***game***") print ("---------------------------") print ("commands:") print ("'[direction]'") print ("'get [item]'") def showstatus(): #print player's current status print ("---------------------------") #print current inventory print ("inventory : " , inventory) #print item if there 1 print("you in " , currentroom) ''' if "item" in rooms[currentroom]: print( "you see " + rooms[currentroom]["item"]) print ("---------------------------") ''' #--------------------------------------------------------------------- inventory = [] # list of rooms rooms = [ ["hall","discription of hall", "0", "6", "3",], ["living room","discription of living room", "1", "5", "3", "4"], ["kitchen","discription of kitchen", "0", "2"], ["master bedroom", "discription of master bedroom", "0"], ["bedroom", "discription of bedroom", "0"], ["bathroom", "discription of bathroom", "1"], ] currentroom = rooms[0] #--------------------------------------------------------------------- showinstructions() showstatus() lastcommand = [] commandlist = [] numberofrounds = [] inputlist = [] cannotdothat = ["<<< cannot that\n", "<<< cannot done\n", "<<< impossible\n", "<<< can't that\n"] dontunderstand = ["<<< didn't quite that\n", "<<< don't understand command.\n", "<<< refrase command.\n", "<<< mean?\n", "<<< please refrase command.\n", "<<< not understand command.\n", "<<< don't know mean.\n"] commands = ["command", "commands", "input list", "inputs", "previous input", "last input", "input", "previous commands", "last command", "turn", "rounds", "round", ]
#---------------------------------------------------------------------
while true: print "---------------------------" inputuser = raw_input(">>> ") lastcommand = inputuser inputlist.append(lastcommand) # rooms if(currentroom == [0]): print currentroom[0][1] print "<<< have following options:" print "<<< go east , enter bathroom, or" print "<<< go south , enter living room, or" print "<<< go west , enter kitchen." if(currentroom == [1]): print currentroom[1][1] print "<<< have following options:" print "<<< go north , enter hall, or" print "<<< go east , enter bedroom, or" print "<<< go west , enter master bedroom." if(currentroom == [2]): print currentroom[2][1] print "<<< have following options:" print "<<< go east , enter hall." if(currentroom == [3]): print currentroom[3][1] print "<<< have following options:" print "<<< go east , enter living." if(currentroom == [4]): print currentroom[4][1] print "<<< have following options:" print "<<< go west , enter hall." if(currentroom == [5]): print currentroom[5][1] print "<<< have following options:" print "<<< go west , enter living room."
# direction comamnds #---------------------------------------------------------------------
if(inputuser=="s" or inputuser=="s" or inputuser=="south" or inputuser=="south" or inputuser=="south") , (currentroom==[0]): commandlist.append(lastcommand) currentroom = [1] print "<<< in " , currentroom , "\n"
#---------------------------------------------------------------------
elif(inputuser=="n" or inputuser=="n" or inputuser=="north" or inputuser=="north" or inputuser=="north") , (currentroom == [1]): commandlist.append(lastcommand) currentroom = [0] print("<<< in " + currentroom + "\n")
#---------------------------------------------------------------------
elif(inputuser=="e" or inputuser=="e" or inputuser=="east" or inputuser=="east" or inputuser=="east"): commandlist.append(lastcommand) if(currentroom == [2]): currentroom = [0] elif(currentroom == [3]): currentroom = [1] print("<<< in " + currentroom + "\n")
#---------------------------------------------------------------------
elif(inputuser=="w" or inputuser=="w" or inputuser=="west" or inputuser=="west" or inputuser=="west"): commandlist.append(lastcommand) if(currentroom == [4]): currentroom = [0] elif(currentroom == [5]): currentroom = [1]
#---------------------------------------------------------------------
# item , inventory
elif(inputuser=="inventory"): print "<<< here list of inventory:" print "<<< " , inventory
# i?
elif(inputuser=="where" or inputuser=="where" or inputuser=="where i" or inputuser=="where i" or inputuser=="where?" or inputuser=="where i?"): print "<<< in ", "'",currentroom,"'"
# commandlist , round
elif(inputuser=="commands" or inputuser=="command" or inputuser=="command list"): print "here list of previous commands:" print commandlist elif(inputuser=="last command" or inputuser=="previous command"): print "<<< here last command:" print "<<< '" , commandlist[-1] , "'" elif(inputuser=="round" or inputuser=="rounds" or inputuser=="turn"): if commandlist == none: print "<<< here number of actionable entries:" print "<<< 0" else: print "<<< here number of actionable entries:" print "<<< " , len(commandlist) elif(inputuser=="input list" or inputuser=="input"): print "<<< here list of user inputs:" print "<<< " , inputlist else: print (random.choice(dontunderstand))
#-----------------------------end----------------------------
i know isn't complete, cannot further unless solve problem.
the problem, think, in part of code:
# direction comamnds
#---------------------------------------------------------------------
if(inputuser=="s" or inputuser=="s" or inputuser=="south" or inputuser=="south" or inputuser=="south") , (currentroom==[0]): commandlist.append(lastcommand) currentroom = [1] print "<<< in " , currentroom , "\n"
#---------------------------------------------------------------------
elif(inputuser=="n" or inputuser=="n" or inputuser=="north" or inputuser=="north" or inputuser=="north") , (currentroom == [1]): commandlist.append(lastcommand) currentroom = [0] print("<<< in " + currentroom + "\n")
#---------------------------------------------------------------------
elif(inputuser=="e" or inputuser=="e" or inputuser=="east" or inputuser=="east" or inputuser=="east"): commandlist.append(lastcommand) if(currentroom == [2]): currentroom = [0] elif(currentroom == [3]): currentroom = [1] print("<<< in " + currentroom + "\n")
#---------------------------------------------------------------------
elif(inputuser=="w" or inputuser=="w" or inputuser=="west" or inputuser=="west" or inputuser=="west"): commandlist.append(lastcommand) if(currentroom == [4]): currentroom = [0] elif(currentroom == [5]): currentroom = [1]
#---------------------------------------------------------------------
i want code like: example: if enter direction south, , in hall, enter living room.
any appreciated!!
i suggest setting dictionary system instead of lists. can make set of rooms , give them special connections key store rooms can move there.
bedroom = {'name':'bedroom','decription':'blah'*4} hall = {'name':'hall','decription':'blah'*4} bathroom = {'name':'bathroom','decription':'blah'*4} kitchen = {'name':'kitchen','decription':'blah'*4} hall['connections'] = {'south':bedroom, 'north':bathroom, 'east':kitchen} kitchen['connections'] = {'west':hall} bedroom['connections'] = {'north':hall} bathroom['connections'] = {'south':hall}
this way, can check connections given room easily
for key in hall['connections']: print ("to {} {}".format(key, connection[key]['name']))
and it's lot easier edit, rather rejigging bunch of different numbers re-assign text values aren't dependent on each other.
Comments
Post a Comment