krotscore.blogg.se

Write an online text adventure game in python
Write an online text adventure game in python













write an online text adventure game in python

Write an online text adventure game in python code#

I haven't really changed anything, but noticed how it's much easier to read and understand? Of course you will have to move some code into the new methods i've named above. You should hide implementations details to make your code look something like this: SetUpAllBooleanValues() that way if you need to repeat it, you can do so easily. This type of code: can be placed in a method. too many of them and it may mean that your code will be very difficult to change and understand. The only place where you actually want to see if statements are in factory methods (actually this is not true - but you gotta be very skeptical of if statements as a developer starting out). In other words you want to see objects send "messages" to each other. apologies if that's the wrong python syntax - i don't know any python. You don't want to see if statements too much. Lastly, what is it that you are trying to accomplish with all these booleans: you don't want two actions to be repeated twice? i don't quite understand what's going on here.

write an online text adventure game in python

so you can safely remove this bit from the loop: if spawn = True: How will the game ever end: you don't set gamestart to false? also the wakeup statement is run only once so you needn't put it in the loop. cleaning up the print statements with \n alone improves the code.Īlso look up string interpolation in python. You can also print a new line with print "\n\nYou wake up in a room you don't recognise." there's no need to repeat the print method more than once. sometimes i see methods like this: DoStuff(). I can't emphasise the importance of giving useful names. Why do you have so many boolean variables? and they all sound the same: spawnStart, Spawn, SpawnIn, GameStart, wardrobeSpawn please use useful names. if once comes back in 3 months to read the code - it might be difficult for the author to understand an explanation would be very helpful and handy to understand what is going on. i have no experience with python or any functional languages, so please keep in mind.įar too many if statements in the one block. Please note that i'm from an OOP background and my answers will necessarily reflect that bias. Also, you should leave enough whitespace in between blocks of code to make it easier to read and manage. It states that you should, for example, use snake_case for variables and function names. I suggest splitting the game up into several functions, perhaps like this: def Level1(): This is easier for you and other developers.į-strings are only available in Python 3.6 and later. You might want to use a so-called f-string: print(f"You have coins") Instead of doing: print("You have: " + str(coins) + " coins") what this also means is that instead of writing: if wardrobeSpawn = False Therefore, you can shorten this: while gameStart = True: Python automatically compares to True in if / elif / else / while statements. I'm starting to think you've used a wrong tag. there's no such thing as raw_input in Python 3.

write an online text adventure game in python

Your tags include python-3.x, so you should fix that. You've also used print inconsistently, sometimes just leaving out the parentheses. If you meant to print a newline, use print() instead. The same applies to other parts of your code where you used this. Print("You look around and see a wardrobe and a door") Print "This wardrobe looks oddly familiar, you have Print "The wardrobe seems quite empty, but you doįind a coin in the far left corner, you put it in your pocket" Print(bcolors.ENDC + "You look around and see a wardrobe Recognise, with no idea how you got there") Print(bcolors.FAIL + "You wake up in a room you don't

write an online text adventure game in python

Print("You have: " + str(coins) + " coins") I decided to only submit the code for the first room as I don't want to submit too much code at once. Please comment any tips and general help regarding with making my code better, faster or more organised! I only started Python two weeks ago so any help would be greatly appreciated. I am a beginner so I am seeking help with my code. I'm currently working on a text adventure game for my first project.















Write an online text adventure game in python