I'm making this Pokemon game for Msodude, but the new version is suffering from a run-time error. It makes it so that when you defeat Dark Bulbasaur, you just keep staying in battle-mode rather than going into the shop. I need help. I use Python 3.1.4.
import random
#Setting global variables and such items
loop = 1
level = 1
win = 0
move = ''' '''
#Setting variables and such items for Bulbasaur (player):
hp = 200
armr = 10
sparmr = 10
atk = 5
spatk = 10
speed = 0
pp1 = 20
pp2 = 40
pp3 = 10
pp4 = 15
gold = 0
#Setting variables and such items for Dark Bulbasaur (enemy):
ehp = (190 + level)
earmr = 10
esparmr = 5
eatk = 10
espatk = 10
espeed = 0
def setVar():
#Setting global variables and such items:
loop = 1
level = 1
win = 0
move = ''' '''
#Setting variables and such items for Bulbasaur (player):
hp = 200
armr = 10
sparmr = 10
atk = 5
spatk = 10
speed = 0
pp1 = 20
pp2 = 40
pp3 = 10
pp4 = 15
gold = 0
#Setting variables and such items for Dark Bulbasaur (enemy):
ehp = (190 + level)
earmr = 10
esparmr = 5
eatk = 10
espatk = 10
espeed = 0
global speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
#The function that runs the game:
def playerTurn():
global hp, speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
move = input('''What will Bulbasaur do?\n\n>>> ''')
move = move.lower()
playerMove(move)
#The function that processes the player's chosen move:
def playerMove(move):
global hp, speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
if move == '''tackle''':
if pp1 > 0:
print('''Bulbasaur has used Tackle!''')
atk = random.randint(0, 100)
if atk < (90 + speed):
ehp -= (20 + atk - earmr)
print('''Dark Bulbasaur was hurt!\n''')
else:
print('''Bulbasaur missed!''')
pp1 -= 1
else:
print('''Bulbasaur does not have enough PP to perform Tackle.\n''')
playerTurn()
elif move == '''growl''':
if pp2 > 0:
print('''Bulbasaur has used Growl!''')
atk = random.randint(0, 100)
if atk < (100 + speed):
eatk -= 5
print('''Dark Bulbasaur was weakened\n''')
else:
print('''Bulbasaur missed!\n''')
pp2 -= 1
else:
print('''Bulbasaur does not have enough PP to perform Growl.\n''')
playerTurn()
elif move == '''leech seed''':
if pp3 > 0:
print('''Bulbasaur used Leech Seed!''')
atk = random.randint(0, 100)
if atk > (90 + speed):
ehp -= (10 + spatk - esparmr)
hp += (10 + spatk - esparmr)
print('''Dark Bulbasaur was drained!\n''')
else:
print('''Bulbasaur missed!\n''')
pp3 -= 1
else:
print('''Bulbasaur does not have enough PP to perform Leech Seed.\n''')
playerTurn()
elif move == '''vine whip''':
if pp4 > 0:
print('''Bulbasaur used Vine Whip!''')
atk = random.randint(0, 100)
if atk > (100 + speed):
ehp -= (20 + spatk - esparmr)
print('''Dark Bulbasaur was hurt!\n''')
else:
print('''Bulbasaur missed!\n''')
else:
print('''Bulbasaur does not have enough PP to perform Vine Whip.\n''')
playerTurn()
pp4 -= 1
else:
print('''That is not a recognized move. Please chose from the following moves:\n\t
Tackle\n\t
Growl\n\t
Leech Seed\n\t
Vine Whip\n
If these commands do not work, check the spelling.\n''')
playerTurn()
#The function that controls the Dark Bulbasaur's move:
def enemyMove():
global hp, speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
atk = random.randint(0, 100)
if atk <= 25:
print('''Dark Bulbasaur used Tackle!''')
atk = random.randint(0, 100)
if atk <= (20 + espeed):
hp -= (35 + eatk - armr)
print('''Bulbasaur was hurt!\n''')
else:
print('''Dark Bulbasaur missed!\n''')
elif atk > 25 and atk <= 50:
print('''Dark Bulbasaur used Growl!''')
atk = random.randint(0, 100)
if atk <= (100 + espeed):
atk -= 5
print('''Bulbasaur was weakened!\n''')
else:
print('''Dark Bulbasaur missed!\n''')
elif atk > 50 and atk <= 75:
print('''Dark Bulbasaur used Leech Seed!''')
atk = random.randint(0, 100)
if atk <= (90 + espeed):
hp -= (10 + espatk - sparmr)
print('''Bulbasaur was drained!\n''')
ehp += (10 + espatk)
else:
print('''Dark Bulbasaur missed!\n''')
elif atk > 75:
print('''Dark Bulbasaur used Vine Whip!''')
atk = random.randint(0, 100)
if atk <= (100 + speed):
hp -= (20 + espatk - sparmr)
print('''Bulbasaur was hurt!\n''')
else:
print('''Dark Bulbasaur missed!\n''')
else:
print('''There is a glitch in the program. Please report the event to *name removed*.''')
loop = 0
#The function that reports the HP and PP of the Bulbasaur and Dark Bulbasaur:
def reportStats():
global hp, speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
print('''Bulbasaur has ''', hp, ''' HP!\n\nBulbasaur has ''', pp1, ''' PP for Tackle!\nBulbasaur has ''', pp2, ''' for PP for Growl!\nBulbasaur has ''', pp3, ''' PP for Leech Seed!\nBulbasaur has ''', pp4, ''' PP for Vine Whip!\n''')
print('''Dark Bulbasaur has ''', ehp, ''' HP!\n''')
#The function that checks to see whether someone is KO'ed:
def reportDeath():
global hp, speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
if hp <= 0:
print('''Bulbasaur has been KO'ed!''')
loop = 0
elif ehp <= 0:
print('''Dark Bulbasaur has been KO'ed!''')
atk = random.randint(0, 11)
gold += atk
win = 1
#The function that runs the shop feature:
def shop():
global hp, speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
print('''Welcome to the shop! Feel free to look around!''')
print('''\n
\tAttack Kit 1: +1 to ATK, 25 Gold\n
\tAttack Kit 2: +5 to ATK, 125 Gold\n
\tAttack Kit 3: +10 to ATK, 250 Gold\n
\tSp Attack Kit: +1 to Sp. ATK, 25 Gold\n
\tSp Attack Kit: +5 to Sp. ATK, 125 Gold\n
\tSp Attack Kit: +10 to Sp. ATK, 250 Gold\n
\tDefense Kit 1: +1 to DEF, 25 Gold\n
\tDefense Kit 2: +5 to DEF, 125 Gold\n
\tDefense Kit 3: +10 to DEF, 250 Gold\n
\tSp Defense Kit 1: +1 to Sp. DEF, 25 Gold\n
\tSp Defense Kit 2: +5 to Sp. DEF, 125 Gold\n
\tSp Defense Kit 3: +10 to Sp. DEF, 250 Gold\n
\tSpeed Kit 1: +1 to Speed, 25 Gold\n
\tSpeed Kit 2: +5 to Speed, 125 Gold\n
\tSpeed Kit 3: +10 to Speed, 250\n
\tQuit: Exits the shop\n
\nWhat will Bulbasaur buy?''')
atk = input('''>>> ''')
atk = atk.lower()
if atk == '''attack kit 1''':
if gold >= 25:
atk += 1
gold -= 25
print('''Bulbasaur bought the Attack Kit 1.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''attack kit 2''':
if gold >= 125:
atk += 5
gold -= 125
print('''Bulbasaur bought the Attack Kit 2.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''attack kit 3''':
if gold >= 250:
atk += 10
gold -= 250
print('''Bulbasaur bought the Attack Kit 3.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''sp attack kit 1''':
if gold >= 25:
spatk += 1
gold -= 25
print('''Bulbasaur bought the Sp Attack Kit 1.\nBulbasaur now has ''', gold, ''' Gold''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''sp attack kit 2''':
if gold >= 125:
spatk += 5
gold -= 125
print('''Bulbasaur bought the Sp Attack Kit 2.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''sp attack kit 3''':
if gold >= 250:
spatk += 10
gold -= 250
print('''Bulbasaur bought the Sp Attack Kit 3.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''defense kit 1''':
if gold >= 25:
armr += 1
gold -= 25
print('''Bulbasaur bought the Defense Kit 1.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''defense kit 2''':
if gold >= 125:
armr += 5
gold -= 125
print('''Bulbasaur bought the Defense Kit 2.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''defense kit 3''':
if gold >= 250:
armr += 10
gold -= 250
print('''Bulbasaur bought the Defense Kit 3.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''sp defense kit 1''':
if gold >= 25:
sparmr += 1
gold -= 25
print('''Bulbasaur bought the Sp Defense Kit 1.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''sp defense kit 2''':
if gold >= 125:
sparmr += 5
gold -= 125
print('''Bulbasaur bought the Sp Defense Kit 2.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''sp defense kit 3''':
if gold >= 250:
sparmr += 10
gold -= 250
print('''Bulbasaur bought the Sp Defense Kit 3.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''speed kit 1''':
if gold >= 25:
speed += 1
gold -= 25
print('''Bulbasaur bought the Speed Kit 1.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''speed kit 2''':
if gold >= 125:
speed += 5
gold -= 125
print('''Bulbasaur bought the Speed Kit 2.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''speed kit 3''':
if gold >= 250:
speed += 10
gold -= 250
print('''Bulbasaur bought the Speed Kit 3.\nBulbasaur now has ''', gold, ''' Gold.''')
shop()
else:
print('''Bulbasaur does not have enough Gold to buy that.''')
shop()
elif atk == '''quit''':
win = 0
level += 10
print('''You have reached Level ''', level / 10, '''.\n''')
setVar()
#The function that runs the entire game- funny how simple you can make code with 'def' functions:
def runGame():
global hp, speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
if win == 0:
playerTurn()
enemyMove()
reportStats()
elif win == 1:
shop()
#The part which causes the whole game to go into effect- funny how it's so short and yet so important:
while loop == 1:
global hp, speed, pp1, pp2, pp3, pp4, spatk, ehp, eatk
runGame()
Last edited by maxskywalker (2011-08-01 10:02:23)
Offline