I have decided that a text adventure would be better for me to learn from, as a visual game is confusing to me still. So, I was reading Chris O'leary's post about his text adventure game, Advent House, and got many ideas from there. I want to perfect his battle sequence though.
Here is the code he used with minor adjustments on my part in the random module. If someone could tell me where I am going wrong and give me an example I would greatly appreciate it!
# adding to christ o'leary's fight function
# to have integer returned use
# x = random.choice([0, 1])
# print x, type(x) # testing
# or x = random.randrange(0, 2)
# print x, type(x)
def main():
global monster_HP1
monster_HP1 = 5
global hp
hp = 10
print """you are in a fight!
Type 'h' to fight"""
x = raw_input(': ')
if x == 'h':
fight_unicorn()
else:
print "Error"
main()
def fight_unicorn():
global monster_HP1
global hp
hit_miss = random.randrange(0, 2)
print x, type(x)
if hit_miss == 1:
print "You hit the monster!"
monster_HP1 = monster_HP1 - 1
if monster_HP1 == 0:
print "You win!"
master_bedroom()
else:
monster_turn1()
else:
print "You Missed"
monster_turn1()
def monster_turn1():
monster_hit = random.randrange(0, 2)
print x, type(x)
if monster_hit == 1:
print "You are hit!"
hp = hp-1
if hp == 0:
print "Game Over"
else:
print "The monster missed"
fight_unicorn()
main()