Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm a beginner Python coder and this is the first program that I have ever programmed. Please suggest improvements/bugs. Here's the link to the code.

global hp
hp = 20
global dice
import random
dice = random.randint(3,5)
global beardamage
import random
beardamage = random.randint(1,9)
global hunger
hunger = 5
global spiderhp
spiderhp = 5
global bearhp
bearhp = 10
global potion
potion = 0
global xp
xp = 0
#                |Data storage for part 1|
#_______________________________________________________________________________
#
x = ("attack")
passwordcode = ("5665598")
road =("left")
key = ("key")
choicekey = ("yes")
hutchoice = ("gotoit")
menucheat = ("cheat menu")
menureadme = ("readme")
menustart = ("start game")
death = 1
menuhelp = ("help")
potionadd = 1
examinationyes = ("examine")
SmallHealing = random.randint(8,15)
cheat01 = ("cheat_01")
cheat02 = ("shutdown")
bearxp = 100
spiderxp = 350
bow = random.randint(5,10)
passwordcheat = ("password")
#                |End of data storage for adventure part 1.|
#_______________________________________________________________________________
text = ("Loading files....")
import time
import sys
from random import randrange
for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.5)
    time.sleep(0.01)
text = ("-1%||||||||||||||||100%-")
print("")
import time
import sys
from random import randrange
for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.01)
    time.sleep(0.01)
print("")
import time
time.sleep(1)
import os
import sys
os.system("CLS")
print("")
print("")
print("                                                                                     ")
print("    _       _                 _                                _   _                 ")   
print("   / \   __| |_   _____ _ __ | |_ _   _ _ __ ___   _ __  _   _| |_| |__   ___  _ __  ")
print("  / _ \ / _` \ \ / / _ \ '_ \| __| | | | '__/ _ \ | '_ \| | | | __| '_ \ / _ \| '_ \ ")
print(" / ___ \ (_| |\ V /  __/ | | | |_| |_| | | |  __/ | |_) | |_| | |_| | | | (_) | | | |")
print("/_/   \_\__,_| \_/ \___|_| |_|\__|\__,_|_|  \___| | .__/ \__, |\__|_| |_|\___/|_| |_|")
print("                                                  |_|    |___/                       ")

print("  //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\")
print(" //                             ||  Main menu  ||                        \\")                                    
print("||______________________________||_____________||________________________||")
print("||                              ||    HELP     ||                        ||")                                     
print("||______________________________||_____________||________________________||")
print("||                              ||   README    ||                        ||")                                     
print("||______________________________||_____________||________________________||")
print("||                              ||  START GAME ||                        ||")                                  
print("||______________________________||_____________||________________________||")
print(" \\                              || CHEAT MENU  ||                        //")                                
print("  \\|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//")
thing = 2
thini = 1
print(" Enter the selected command")
commandprompt = input("")
while thing > thini:
    if commandprompt == menucheat:
        print("Enter the password")
        commandprompt = input("")
        if commandprompt == passwordcheat:
            print("Access granted")
            print("")
            print("Cheat list")
            print("",(cheat01)," - Walkthrough")
            print("",(cheat02)," - You should know what that one does")
            commandprompt = input("")
            if commandprompt == cheat01:
                print("Cheat activated")
                print("")
                print("")
                import time
                time.sleep(2)
                print("WALKTHROUGH")
                print("HIT/RUN")
                print("Examine")
                print("Left")
                print("yes")
                print("go")
                print("5665598")
                print("HIT/RUN")
            elif commandprompt == cheat02:
                yes = ("yes")
                no = ("no")
                print("Are you sure?")
                commandprompt = input("")
                if commandprompt == yes:
                    print("Shut down in 10 seconds")
                    import os
                    os.system("shutdown -r -t 10 ")
                elif commandprompt == no:
                    print("Terminated")
                    break
                else:
                    print("Unknown command!")





    if commandprompt == menustart:
         print("Press enter to start")
         input("")
         break
    commandprompt = input("")
    if commandprompt == menureadme:
         print("_________________________________")
         print("Made by AO")
         print("Version 1.8")
         print("Dice system inplemented")
         print("Global system")
         print("Part 2 done")
         print("900+ lines of coding")
         print("_________________________________")
         import time
         time.sleep(5)
    if commandprompt == menuhelp:
         print("Help")
         print("Type commands exactly, no caps")




    else:
         print("Invalid command!")
         import time
         time.sleep(5)
import os
import sys
os.system("CLS")

import time
import sys
from random import randrange

text = ("This is a story which set's back long before golden age...")

for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.1)
    time.sleep(0.1)
import time
time.sleep(1)
print("")
text = ("In a time of witchcraft, mysteries and myths.")

for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.1)
    time.sleep(0.1)
import time
time.sleep(1)
print("")
import time
time.sleep(1)
print("")
text = ("!||SLENDER THE GAME||!")

for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.1)
    time.sleep(0.1)

print("")
print("You have 20 hitpoints.")
print("You have 5 hunger bars.")
import time
time.sleep(3)
print("")
import time
time.sleep(1)
text = ("You - Where I'm i?")

for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.1)
    time.sleep(0.1)
print("")
print("You stand up")
import time
time.sleep(1)
text = ("You - Hmm.")
import os
import sys
os.system("CLS")

for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.1)
    time.sleep(0.1)

print("")
print("You approach the door")
print("But you hear a growling noise.")
import time
time.sleep(2)
print("The door is smashed in half as a monster sees you.")
import time
time.sleep(2)
print("It's a giant bear!")
import time
time.sleep(2)
text = ("You - Ahhhh! Wait, It's so small!")

for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.1)
    time.sleep(0.1)
print("")
text = ("You - What could possibly go wrong?")

for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.1)
    time.sleep(0.1)
print("")
print("The bear looks agressive. The bear has",(bearhp)," hp. Type attack or run") 
y =input("")
if (y) == (x):
     while (bearhp > death):
         print("You hit the bear")
         print("")
         import time
         time.sleep(3)
         print("You do",(dice),"damage")
         print("")
         import time
         time.sleep(2)
         import os
         import sys
         os.system("CLS")
         bearhp = bearhp - dice
         if bearhp < death:
             print("You do a final blow against the bear")
             print("")
             print("The bear has died")
             import os
             import sys
             os.system("CLS")
             break
         import time
         time.sleep(3)
         print("The bear does ",(beardamage),"damage")
         hp = hp - beardamage
         import time
         time.sleep(2)
         import os
         import sys
         os.system("CLS")
         print("")
         if hp < death:
             print("OW! The bear does final blow against you!")
             print("You have died")
             import time
             time.sleep(2)
             print("Game over")
             import time
             time.sleep(99999)
             break      
         import time
         time.sleep(3)
         if bearhp < death:
             print("You do a final blow against the bear")
             print("")
             print("The bear has died")
             break
         import time
         print("You have",(hp),"left")
         print("")
         import time
         time.sleep(1)
         print("The bear has",(bearhp),"left")
         import time
         time.sleep(1)
         import os
         import sys
         os.system("CLS")

else:
     print("You run away.")
     import time
     time.sleep(2)
     print("You have wasted your hunger bar")
     hungerbar = 1
     hunger = hunger - hunger
     print("Hunger is",(hungerbar)," ")
     import time
     time.sleep(3)



time.sleep(2)
import time
import sys
from random import randrange
text = ("You are in a strange room")

for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.1)
    time.sleep(0.1)
print("")
print("You see a shelf")
import time
time.sleep(2)
print("Hint - try examining it.","examine")
examination = input("")
if (examination) == (examinationyes):
    print("You find a small vial")
    import time
    time.sleep(2)
    print("It's a potion of healing!")
    import time
    time.sleep(2)
    print("You take the potion")
    potion = potion + potionadd
    import time
    time.sleep(2)
    print("You have",(potion),"in your inventury")
    import time
    time.sleep(2)
    print("You walk out of the door and you see a path")
    import time
    time.sleep(2)
    print("You go down the road")
else:
    print("You walk out of the door and you see a path")
    import time
    time.sleep(2)
    print("You go down the road")
print("You see a road which splits into 2 paths.")
print("Do you wish to go left or right?")
roadchoice = input("")
if (roadchoice) == (road):
     print("You go left")
else:
    print("You go right")
    import time
    time.sleep(5)

    print("You are walking slowly down the road.")
    import time
    time.sleep(3)
    print("You see a slender man.")
    import time
    time.sleep(3)
    import webbrowser
    webbrowser.open('http://www.google.co.uk/imgres?q=slender+screen&um=1&hl=en&safe=active&sa=N&tbo=d&tbm=isch&tbnid=evaUdI26IM5C9M:&imgrefurl=http://templardigital.blogspot.com/2012/07/video-game-review-slender.html&docid=gV0cU5I4FRgbLM&imgurl=http://3.bp.blogspot.com/-_BUhzLBaxQM/UBMEEXFKthI/AAAAAAAABa8/Miacjv_EtQs/s1600/Slender%252B2.png&w=474&h=348&ei=wpy0UNv_IsWy0QXKvoD4CA&zoom=1&iact=rc&dur=1&sig=117123526119168881900&page=1&tbnh=145&tbnw=202&start=0&ndsp=26&ved=1t:429,r:17,s:0,i:135&tx=140&ty=96&biw=1280&bih=876')
    print("GAME OVER")
    time.sleep(3)
    print("SLENDER MAN HAS GOT YOU")
    import time
    time.sleep(5)
    print("END OF GAME! SLENDER TEXT. THE GAME")
    import time
    time.sleep(60)
print("As you are walking down the misty road...")
import time
time.sleep(3)
print("You see a small, old note.")
print("Do you want to look at it?")
keychoices = input("")
if (keychoices) == (choicekey):
         print("Note - To open the ancient door, you must say 5665598")
         import time
         time.sleep(5)
         print("Remember not to forget it, otherwise you will die!")
         import time
         time.sleep(2)
         print("SteveXI - If you are reading this, then i am dead.")
         import time
         time.sleep(2)
         print("SteveXI - Good luck!")
         import time
         time.sleep(10)
         import os
         import sys
         os.system("CLS")

else:
    print("You leave the note alone.")

import os
import sys
os.system("CLS")

import time
time.sleep(3)
print("In the distance, you see a small hut. It stands on a small hill.")
import time
time.sleep(3)
print("You make a camp")
import time
time.sleep(2)
print("What do you want to do now?")
print(" 1) go 2) or do nothing")
hutchoices = input("")
something = 10
somethings = 1
hutchoiceyes = ("go")
while something > somethings:
    if (hutchoices) == (hutchoiceyes):
        print("You walk to the hut.")
        import time
        time.sleep(5)
        break


    else:
        print("You do nothing.")
        hutchoices = input("")


import time
time.sleep(3)
import time
time.sleep(5)
print("You find an ancient sandstone door.")
import time
time.sleep(5)
print("Say the inscription, if you know it.")
password = input("")
if (password) == (passwordcode):
     print("The door slides slowly out of the way.")
     print("You go down a cobweb filled passage")
     import time
     time.sleep(3)
     print(" You have completed the game, Welldone!")
else:
     print("A trapdoor opens beneath you!")
     print("You fall down to your doom.")
     import webbrowser
     webbrowser.open('http://www.google.co.uk/imgres?q=slender+screen&um=1&hl=en&safe=active&sa=N&tbo=d&tbm=isch&tbnid=evaUdI26IM5C9M:&imgrefurl=http://templardigital.blogspot.com/2012/07/video-game-review-slender.html&docid=gV0cU5I4FRgbLM&imgurl=http://3.bp.blogspot.com/-_BUhzLBaxQM/UBMEEXFKthI/AAAAAAAABa8/Miacjv_EtQs/s1600/Slender%252B2.png&w=474&h=348&ei=wpy0UNv_IsWy0QXKvoD4CA&zoom=1&iact=rc&dur=1&sig=117123526119168881900&page=1&tbnh=145&tbnw=202&start=0&ndsp=26&ved=1t:429,r:17,s:0,i:135&tx=140&ty=96&biw=1280&bih=876')
     import time
     time.sleep(5)
     print("You die, End of game.")
     import time
     time.sleep(5)
     print("SLENDERTEXT THE GAME")
     import time
     time.sleep(60)
def clearscreen():
    if os.name == "posix":
       # Unix/Linux/MacOS/BSD/etc
       os.system('clear')
    elif os.name in ("nt", "dos", "ce"):
       # DOS/Windows
       os.system('CLS')
print("Adventure part 2")
import time
time.sleep(4)
print("Adventure start's now!")
import time
time.sleep(2)

#This is part 2 of the adventure. All data must be below.
#All data will be stored and loaded below.
#_____________________________________________________________________________
spiderchoiseyes = ("hit")
spiderchoiseno = ("no")
reservespace = ("")
roadchoice1exec = ("1")
roadchoice2exec = ("2")
villager = ("yes")
hammerchoiceexec = ("yes")
hungertakeaway = 1
spiderdamage = random.randint(1,8)
global acid
acid = 0
global portion
potion = 0
global queenhp
queenhp = 30
queendamage = random.randint(3,6)
#_____________________________________________________________________________

print("You start the adventure")
print("As you walk to the entrance, you see a giant spider!")
import time
time.sleep(3)
print("You need to hit it")
import time
time.sleep(3)
print("Hit it as many times as it takes to kill it.")
import time
time.sleep(2)
spider = input("")
if (spider) == (spiderchoiseyes):
     while (spiderhp > death):
         print("You hit the spider")
         print("")
         import time
         time.sleep(3)
         print("You do",(dice),"damage")
         print("")
         spiderhp = spiderhp - dice
         if spiderhp < death:
             print("You do a final blow against the spider")
             print("")
             print("The spider has died")
             break
         import time
         time.sleep(3)
         print("The spider does ",(spiderdamage),"damage")
         print("")
         if hp < death:
             print("OW! The spider does final blow against you!")
             print("You have died")
             import time
             time.sleep(120)
             break
         hp = hp - spiderdamage


         import time
         time.sleep(3)
         if spiderhp < death:
             print("You do a final blow against the spider")
             print("")
             print("The spider has died")
             break
         import time
         print("You have",(hp),"left")
         import time
         time.sleep(1)
         print("The spider ",(spiderhp),"left")


else:
    print("You run away!")
    import time
    time.sleep(2)
    print("As you walk down the read slowly.")
    import time
    time.sleep(2)
    print("You see 2 roads again.")
    import time
    time.sleep(2)
    print("There's two roads.")
    import time
    time.sleep(2)
    #Road choices start's from here!
print("There's 2 choises")
print("Press enter to see the roads")
input("")
print("2 There's a road leading to a cave")
input("")
print("1 There's second road, it's leading to a dark forest")
import time
time.sleep(2)
print("Which road do you want to go to? 1 or 2.")
roadchoice2 = input("")
if (roadchoice2) == (roadchoice2exec):
      print("You have gone left")
      import time
      time.sleep(3)
      print("You are walking to the cave")
      import time
      time.sleep(2)
      print("You see a muddy footsteps leading to a massive cave.")
      import time
      time.sleep("1")
      print("You see a pickaxe, do you want to examine and add it to your inventury?")
      hammerchoice = input("")
      if (hammerchoice) == (hammerchoiceexec):
          print("You examine the pickaxe")
          import time
          time.sleep(2)
          print("The axe looks a bit rusty")
          import time
          time.sleep(2)
          print("It might have a use later on.")
      else:
           print("You walk past it")
      import time
      time.sleep(2)
      print("You continue to walk towards the cave")

      import time
      time.sleep
      print("Your hunger level",hunger)
      import time
      time.sleep(1)
      print("You - You feel hungry, try seaching for a food source")

elif  (roadchoice2) == (roadchoice1exec):
      print("You have gone right")
      import time
      time.sleep(3)
      print("As are walking to the dark forest.")
      import time
      time.sleep(2)
      print("Mist slowly decends down to the forest floor")
      import time
      time.sleep(3)
      print("You are a bit lost")
      import time
      time.sleep(3)
      print("There's a full moon, but the mist is blinding your view.")
      import time
      time.sleep(3)
      print("There's a villager")
      import time
      time.sleep(3)
      print("Do you wish to talk to him?")
      villagertalk = input("")
else:
     print("Slenderman killed you")
     print("End of the game")
     import time
     time.sleep(60)


if (villagertalk) == (villager):        
        print("You start a conversation with him")
        import time
        time.sleep(3)
        print("Villagersteve - Watch out for those woods")
        import time
        time.sleep(3)
        print("Villagersteve - These woods contain the most brutal undead.")
        import time
        time.sleep(2)
        print("Villagersteve - Here, Take this bow.")
        import time
        time.sleep(3)
        print("You - Item aquired.")
        import time
        time.sleep(2)
        print("Villagersteve - Wait, I must tell you...")
        import time
        time.sleep(3)
        print("You - You hear a screeching noise.")
        import time
        time.sleep(3)
        print("Villagerbob - I must runnnnnn.......THEY ARE COMING FOR ME!")
        import time
        time.sleep(3)
        print("Villagersteve runs away.")
        import time
        time.sleep(3)
value = 0
print("Suddenly, You blacked out")
time.sleep(2)
print("You find yourself in a strange cave...")
import time
time.sleep(2)
if value < potion:
    print("You think, you need to use a portion now.")
    import time
    time.sleep(2)
    print("Do you want to use potion now?")
    rawinput = input("")
    boolean = ("yes")
    if rawinput == boolean:
        decreasevalue = 1
        print("You have used the potion!")
        potion = potion - decreasevalue
        import time
        time.sleep(2)
        print("You have",(potion),"left")
        import time
        time.sleep(2)
        print("You gain",(SmallHealing),"hp")
        hp = hp + SmallHealing
        import time
        time.sleep(2)
        print("You have now",(hp),"left")


import time
time.sleep(2)
print("Suddenly, you see a gigantic spider!")
import time
time.sleep(2)
print("The queen has",(queenhp),"hp")
import time
time.sleep(2)
print("The battle beggins!")
while queenhp > death:
        print("You hit queen spider")
        print("")
        import time
        time.sleep(3)
        print("You do",(dice),"damage")
        print("")
        import time
        time.sleep(2)
        print("Spider queen has",(queenhp),"left")
        print("")
        queenhp = queenhp - dice
        if queenhp == death:
            print("You do a final blow against the queen!")
            print("")
            print("The queen spider has died")
            import time
            time.sleep(2)
            print("You finish the game!")
            import time
            time.sleep(2)
            print("To be continued....")
            break
            import time
            time.sleep(3)
            print("The spider does ",(queendamage),"damage")
            queendamage = queendamage - hp
            print("You have",(hp),"left")
            hp = hp - queendamage
            print("")
        if hp == death:
             print("OW! The spider rips you in half.")
             print("You have died")
             import time
             time.sleep(120)
             break
share|improve this question
    
For a start, please put all the import at the beginning of your file. –  Josay Jan 16 '13 at 23:54

1 Answer 1

global hp
hp = 20

Global only has an effect inside a function. It does absolutely nothing here. At any rate you should avoid using global.

global dice
import random
dice = random.randint(3,5)
global beardamage
import random
beardamage = random.randint(1,9)

You only need to import things once. Here you have imported random twice, the second time doesn't do anything. Instead, just import everything that you need at the beginning.

x = ("attack")
passwordcode = ("5665598")
road =("left")
key = ("key")

The parentheses do nothing here. Also, if these are global constants, they should be named in ALL_CAPS.

text = ("Loading files....")
import time
import sys
from random import randrange
for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.5)
    time.sleep(0.01)
text = ("-1%||||||||||||||||100%-")
print("")
import time
import sys
from random import randrange
for c in text:
    sys.stdout.write(c)
    sys.stdout.flush()
    seconds = "0." + str(randrange(1, 4, 1))
    seconds = float(0.01)
    time.sleep(0.01)

See you've done the exact same thing twice. This means you should write a function like this:

def slow_print(text):
    for character in text:
        sys.stdout.write(c)
        time.sleep(0.01)

slow_print("Loading Files...")
slow_print("-1%||||||||||||||||100%-")

That way you've only need one copy of the actual logic.

def clearscreen():
    if os.name == "posix":
       # Unix/Linux/MacOS/BSD/etc
       os.system('clear')
    elif os.name in ("nt", "dos", "ce"):
       # DOS/Windows
       os.system('CLS')

You define this, but don't actually use it above.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.