dodle
September 1st, 2008, 01:58 AM
Here is a little text game (very simple) that I have made. I could use a little constructive criticism. I'm sorry if the code is messy, I'm not very good with functions yet. Functions were always a weak spot for me in mathematics, and I guess it is the same for me in programming. You'll noticed that I defined some functions, but I never used them anywhere in the code.
Also at the end of the game the option is given to start over. Is there a way to do this without importing. Importing to restart doesn't seem like a good idea.
instructions = "To move press one of the following keys + 'enter':\nn (north), \
s (south), e (east), w (west)\nTo see your status type 'stats'.\
\n\nThe purpose of this game is to find and defeat the dragon.\n\
There are three locations on the map that will give you enhanced stats\n\
but, there are also three locations that will deplete your hp."
# Stats
# Player's Initial Health
hp = 30
# Dragon's Health
dhp = 100
# Equipment
equip1 = "none" #sword
equip2 = "none" #shield
equip3 = "none" #armor'
def user_name():
print name, surname
def user_name1():
print name
def user_name2():
print surname
name = raw_input("What is your first name?")
surname = raw_input("what is your last name?")
print
print 'Welcome', name, surname, 'to my game!'
print
print 'To see instructions type "inst"'
print
# Controls & Commands
x = 0
y = 0
n = "north"
s = "south"
e = "east"
w = "west"
spring = "none"
trap1 = "none"
trap2 = "none"
trap3 = "none"
# The Borders of the Map
while (x,y) != (-3,-1):
if x > 10:
x = x - 1
print
print "This is as far as you can go."
if x < -10:
x = x + 1
print
print "This is as far as you can go."
if y > 10:
y = y - 1
print
print "This is as far as you can go."
if y < -10:
y = y + 1
print
print "This is as far as you can go."
# Current Location
print
print "You are at", (x,y)
# Areas Where Equipment and Health Can Be Found
if equip2 == "none" and (x,y) == (9,-9):
equip2 = "shield"
print
print "You have acuired the shield!"
if equip1 == "none" and (x,y) == (-1,-3):
equip1 = "sword"
print
print "You have acuired the sword!"
if spring == "none" and (x,y) == (10,8):
spring = "entered"
hp = hp + 30
print
print "You have entered the Holy Spring.\nYou have received +30 Health."
# Traps!
if (x,y) == (-2,-1) and trap1 == "none":
hp = hp - 5
trap1 = "entered"
print
print "You have walked into a sand trap and lost 5 Health."
if (x,y) == (-6,5) and trap2 == "none":
hp = hp - 8
trap2 = "entered"
print
print "you are attacked by wolves and barely escape with your life.\nYou lose 8 Health."
if (x,y) == (-2,-7) and trap3 == "none":
hp = hp - 10
trap3 = "entered"
print
print "Your are stranded in the desert without food or water.\nYou lose 10 health."
# Begin Game
answer = raw_input("Which direction would you like to go? \n:")
if answer == "stats":
print
print "Health: ", hp, "\n" "Right Hand: ", equip1, "\n", "Left Hand: ", equip2
if answer == "inst":
print
print instructions
if answer == "n":
y = y + 1
if answer == "s":
y = y - 1
if answer == "e":
x = x + 1
if answer == "w":
x = x - 1
# Response to invalid commands.
elif answer != "n" and answer != "s" and answer != "e" and answer != "w" and answer != "stats" and answer != "inst":
print
print 'I don\'t understand "%s", try again.' % answer
# Final Battle
battle = "active"
print
print "You stand before the drawbridge of the castle, \nbefore the bridge a green dragon stands guard."
while battle == "active":
print
print "What will you do?"
choice = raw_input('"r" for Run, "f" for Fight":')
if choice == "stats":
print
print "Health: ", hp, "\n", "Right Hand: ", equip1, "\n", "Left Hand:", equip2
if choice == "r":
battle = "escaped"
if choice == "f":
if equip1 == "none":
print
print "You hit the dragon causing 4 damage."
dhp = dhp - 4
if equip1 == "sword":
print
print "you hit the dragon causing 10 damage!"
dhp = dhp - 10
if equip2 == "none":
print
print "The dragon attacks, causing you 7 damage."
hp = hp - 7
print "Your hp is ", hp, "\b."
if equip2 == "shield":
print
print "The dragon attacks, only causing you 4 damage."
hp = hp - 4
print "Your Health is ", hp, "\b."
if choice != "f" and "r" and "stats" and "inst":
print
print "You miss the dragon and hit yourself!"
print "You lose 6 health."
hp = hp - 6
print "your hp is ", hp, "\b."
if hp <= 0:
battle = "lost"
elif dhp <= 0:
battle = "won"
if battle == "escaped":
print "Too bad you are chicken!"
print
if battle == "lost":
print "You have lost your life to the dragon.\nGame Over"
print
if battle == "won":
print "Congratulations! You have slain the dragon and saved the Kingdom."
print
rebt = "no"
while rebt == "no":
GameOver = raw_input('Would you like to play again?\ny or n: ')
if GameOver == "n":
rebt = "yes"
if GameOver == "y":
import MyGameNoImport
print
Attached is a little map, so that nobody gets too bored trying to find stuff.
Orange - starting point
Yellow - equipment
Blue - spring
Red - traps
Violet - target
Also at the end of the game the option is given to start over. Is there a way to do this without importing. Importing to restart doesn't seem like a good idea.
instructions = "To move press one of the following keys + 'enter':\nn (north), \
s (south), e (east), w (west)\nTo see your status type 'stats'.\
\n\nThe purpose of this game is to find and defeat the dragon.\n\
There are three locations on the map that will give you enhanced stats\n\
but, there are also three locations that will deplete your hp."
# Stats
# Player's Initial Health
hp = 30
# Dragon's Health
dhp = 100
# Equipment
equip1 = "none" #sword
equip2 = "none" #shield
equip3 = "none" #armor'
def user_name():
print name, surname
def user_name1():
print name
def user_name2():
print surname
name = raw_input("What is your first name?")
surname = raw_input("what is your last name?")
print 'Welcome', name, surname, 'to my game!'
print 'To see instructions type "inst"'
# Controls & Commands
x = 0
y = 0
n = "north"
s = "south"
e = "east"
w = "west"
spring = "none"
trap1 = "none"
trap2 = "none"
trap3 = "none"
# The Borders of the Map
while (x,y) != (-3,-1):
if x > 10:
x = x - 1
print "This is as far as you can go."
if x < -10:
x = x + 1
print "This is as far as you can go."
if y > 10:
y = y - 1
print "This is as far as you can go."
if y < -10:
y = y + 1
print "This is as far as you can go."
# Current Location
print "You are at", (x,y)
# Areas Where Equipment and Health Can Be Found
if equip2 == "none" and (x,y) == (9,-9):
equip2 = "shield"
print "You have acuired the shield!"
if equip1 == "none" and (x,y) == (-1,-3):
equip1 = "sword"
print "You have acuired the sword!"
if spring == "none" and (x,y) == (10,8):
spring = "entered"
hp = hp + 30
print "You have entered the Holy Spring.\nYou have received +30 Health."
# Traps!
if (x,y) == (-2,-1) and trap1 == "none":
hp = hp - 5
trap1 = "entered"
print "You have walked into a sand trap and lost 5 Health."
if (x,y) == (-6,5) and trap2 == "none":
hp = hp - 8
trap2 = "entered"
print "you are attacked by wolves and barely escape with your life.\nYou lose 8 Health."
if (x,y) == (-2,-7) and trap3 == "none":
hp = hp - 10
trap3 = "entered"
print "Your are stranded in the desert without food or water.\nYou lose 10 health."
# Begin Game
answer = raw_input("Which direction would you like to go? \n:")
if answer == "stats":
print "Health: ", hp, "\n" "Right Hand: ", equip1, "\n", "Left Hand: ", equip2
if answer == "inst":
print instructions
if answer == "n":
y = y + 1
if answer == "s":
y = y - 1
if answer == "e":
x = x + 1
if answer == "w":
x = x - 1
# Response to invalid commands.
elif answer != "n" and answer != "s" and answer != "e" and answer != "w" and answer != "stats" and answer != "inst":
print 'I don\'t understand "%s", try again.' % answer
# Final Battle
battle = "active"
print "You stand before the drawbridge of the castle, \nbefore the bridge a green dragon stands guard."
while battle == "active":
print "What will you do?"
choice = raw_input('"r" for Run, "f" for Fight":')
if choice == "stats":
print "Health: ", hp, "\n", "Right Hand: ", equip1, "\n", "Left Hand:", equip2
if choice == "r":
battle = "escaped"
if choice == "f":
if equip1 == "none":
print "You hit the dragon causing 4 damage."
dhp = dhp - 4
if equip1 == "sword":
print "you hit the dragon causing 10 damage!"
dhp = dhp - 10
if equip2 == "none":
print "The dragon attacks, causing you 7 damage."
hp = hp - 7
print "Your hp is ", hp, "\b."
if equip2 == "shield":
print "The dragon attacks, only causing you 4 damage."
hp = hp - 4
print "Your Health is ", hp, "\b."
if choice != "f" and "r" and "stats" and "inst":
print "You miss the dragon and hit yourself!"
print "You lose 6 health."
hp = hp - 6
print "your hp is ", hp, "\b."
if hp <= 0:
battle = "lost"
elif dhp <= 0:
battle = "won"
if battle == "escaped":
print "Too bad you are chicken!"
if battle == "lost":
print "You have lost your life to the dragon.\nGame Over"
if battle == "won":
print "Congratulations! You have slain the dragon and saved the Kingdom."
rebt = "no"
while rebt == "no":
GameOver = raw_input('Would you like to play again?\ny or n: ')
if GameOver == "n":
rebt = "yes"
if GameOver == "y":
import MyGameNoImport
Attached is a little map, so that nobody gets too bored trying to find stuff.
Orange - starting point
Yellow - equipment
Blue - spring
Red - traps
Violet - target