Hey forum,I just started Python Programming as a hobby recently. I was learning how to make a text-based game called Dragon Realm.

Basically it is a game where there are 2 caves, one with a friendly dragon that gives you treasure, and another cave with a hungry dragon that eats you. The game allows the player to choose a cave and randomly decides whether the player gets the treasure or gets eaten.

def displayIntro(): print('You are in a land full of dragons. In front of you,') print('you see two caves. In one cave, the dragon is friendly') print('and will share his treasure with you. The other dragon') print('is greedy and hungry, and will eat you on sight.') print()

Kebap wrote:I could have sworn I had seen this thread before, with already some answers suggesting maybe using a list for more than 2 rooms.

He originally posted this in the Game Development section. I told him that it would probably be more suitable here as it wasn't really a game development question but rather a python basics question. I also suggested a couple things and essentially told him he needed to experiment and post back after he tried a few things.

@op: this is still my suggestion. Try to add more accepted user inputs; try adding a wider range of random numbers to generate. Make a different room appear on a new random number. Experiment. Once you can't figure out why the approach you are taking isn't working, THEN post back and include what you have tried.

This will be a much more productive experience for all involved parties.

I could have sworn I had seen this thread before, with already some answers suggesting maybe using a list for more than 2 rooms.

That was my fault. I went to move his thread and made a shadow thread. Deleted the shadow thread, and it deleted both the original thread and the shadow thread. I messaged the OP and told him to go ahead and repost

def displayIntro(): print('You are on a planet full of dragons. In front of you, you see two caves.') time.sleep(2) print('In one cave, the dragon is friendly and will share his treasure with you.') time.sleep(2) print('The other dragon is greedy and hungry, and will eat you on sight!') time.sleep(2)

def displayIntro(): print('You are on a planet full of dragons. In front of you, you see two caves.') time.sleep(2) print('In one cave, the dragon is friendly and will share his treasure with you.') time.sleep(2) print('The other dragon is greedy and hungry, and will eat you on sight!') time.sleep(2)

if randCave == 1: print('The dragon greets you and gives you his treasure!') elif randCave == 2: print('The dragon crushes you with it\'s powerful jaws and eats you!') else: print('You realise the cave is empty. Your mind is playing tricks on you ...')

def displayIntro(): print('You are on a planet full of dragons. In front of you, you notice some caves.') time.sleep(2) print('In one cave, the dragon is friendly and will share his treasure with you.') time.sleep(2) print('Another cave holds a greedy and hungry dragon, and will eat you on sight!') time.sleep(2) print('Some caves are a mystery...') time.sleep(2) print('You must also be careful to look out for traps!') time.sleep(2)

def chooseCave(): cave = '' caveList = ['1','2','3','4'] while cave not in caveList: # means, if cave is not in caveList ( it doesn't equals to any of caveList's variables #example: if cave == 1: then it won't print('Which cave...'), but it will return cave #actually "while cave not in caveList:" means the same as "while cave !=1 or cave !=2 or cave !=3 or cave !=4:" #hope, I expained normally ( English is not my native lang xD ) print('Which cave will you enter into?') cave = raw_input()

return cave

def checkCave(chosenCave):

def randCave(): if randomCave == 1: print('The dragon approaches you from the shadows...') print('... and presents you with a treasure box!') print('Confused, you leave the cave wondering how you managed to escape with your life and with treasure.')

elif randomCave == 2: print('You freeze in your spot as you see a dragon licking its lips with eagerness to devour its next meal!') print('With a quick swipe it pins you down as you helplessly squirm under the powerful claws.') time.sleep(8) print('The dragon eats you!')

elif randomCave == 3: print('You realise the cave is empty. Your mind is playing tricks on you ...')

else: print('This cave is empty, except for a large box in the middle of the room.') print('Suddenly, the floor below you starts to rumble! Before you can do anything,') print('the floor below you gives way and you fall to your death!')

#I wanna show you how to make it faster: caveName = {'1':'first','2':'second','3':'third','4':'fourth'} # creating a dictionary with some values. #You will need them for printing which cave do you enter #If you don't know what is a dictionary, look here: http://docs.python.org/3.1/tutorial/datastructures.html#dictionaries

# and now... print('You enter the %s cave...'%caveName[chosenCave]) # Ok... Now i will try to explain. %s is used to assing strings(integers and so on) to it. it is equal to: # print('You enter the',caveName[chosenCave],'cave...') If you didn't understood, don't worry it was hard for me too. Look here: http://docs.python.org/release/2.3.5/lib/typesseq-strings.html # BTW, I am not sure if it will work with Python 3... if so, replace line print('You enter the %s cave...'%caveName[chosenCave]) with # print ('You enter the',caveName[chosenCave],'cave...')

# Now... what does 'caveName[chosenCave]' means??? # Look, you have some variables and their values. For exaple, '1' is variable and its value is 'first'. So when you call (look 1 line up)... # You take VALUE of VARIABLE. When you call you give variable chosenCave, and get its value in the dictionary # Again, read more on http://docs.python.org/3.1/tutorial/datastructures.html#dictionaries randCave()

'''#remove here and down to make it work if chosenCave == '1': print('You enter the first cave...') randCave()

else: print('You enter the fourth cave...') randCave() '''#remove here and upper to make it work

playAgain = 'y' # I made it 'y' just to show you how it works:while playAgain.lower() in 'yes': # playAgain.lower() means all letter will be in the lower case. # ... in 'yes' means that if playAgain.lower() equals part of 'yes' ( or whole word ) it will return True. print() displayIntro()

caveNumber = chooseCave() checkCave(caveNumber)

print('Do you want to play again? (y/n)') playAgain = raw_input()

# I think, thats all... If you find any errors or bugs, please say me ( cuz as i said i use Python 2.7, and i need to replace some stuff to test# scripts, so i may fogot to replace something back... :D# Cheers# -Vik2015 ;)