我在python 3.4中制作一个基于文本的游戏,需要做很多计算。我的问题是,当我为游戏输入更高的值时,它不会给出任何输出或错误。
此代码获取用户的输入并将其转换为元组。
def getCoords():
mapdata = []
coords = input('Enter 2 numbers without a space from 11 - 99>')
coords = tuple(coords)
coords = tuple(map(int, coords))
for x in range(1, 10):
for y in range(1, 10):
mapdata.append((x,y))
while coords not in mapdata:
print('Invalid target.')
coords = input('Enter 2 numbers without a space from 11 - 99>')
coords = tuple(coords)
coords = tuple(map(int, coords))
return coords
此元组将传递给此函数以计算敌人。
def getEnemy(coords):
place = coords[0]
level = coords[1]
elbm = level * level * 500
emino = level * level * 300
egiant = level * level * 150
enemy = [elbm, emino, egiant]
p = 0
for i in etroops:
etroops[p] = enemy[p]
p =+ 1
然后将其传递给此函数。
def battle():
#setup attacker
lbmhealth = troops[0] * lbmstats[0]
minohealth = troops[1] * minostats[0]
gianthealth = troops[2] * giantstats[0]
#setup defender
elbmhealth = etroops [0] * lbmstats[0]
eminohealth = etroops[1] * minostats[0]
egianthealth = etroops[2] * giantstats[0]
#battle calculate
turn = getTurn()
game = 1
while game == 1:
while turn == 1:
if elbmhealth > 0:
p = 0
for i in troops:
if i > 0:
elbmhealth = elbmhealth - int(troops[p] * allstats[p][1] / allstats[0][2])
etroops[0] = int(elbmhealth / lbmstats[0])
if etroops[0] < 0:
etroops[0] = 0
p += 1
调用其他功能。
def setup():
coords = getCoords()
enemydata = getEnemy(coords)
battle()
setup()
这是我的计划的开始。
import random
#variables
lbm = 5000
mino = 4000
giant = 500
troops = []
troops.extend([lbm, mino, giant])
etroops = [0, 0, 0]
#troops stats
lbmstats = [100, 200, 50, 50,50]
minostats = [300, 100, 150, 70, 200]
giantstats = [800, 150, 400, 25, 650]
allstats = [lbmstats, minostats, giantstats]
这只返回1或2以确定是谁。
def getTurn():
attackerspd = 0
defenderspd = 0
p = 0
for i in troops:
attackerspd = attackerspd + allstats[p][4] * troops[p]
p += 1
if p == 2:
p = 0
for i in troops:
defenderspd = defenderspd + allstats[p][4] * etroops[p]
p += 1
if p == 2:
p = 0
if attackerspd > defenderspd:
turn = 1
elif defenderspd > attackerspd:
turn = 0
else:
turn = random.randint(0, 1)
return turn
当我运行程序时,它会询问我的输入。当我输入11或12时,程序运行正常。任何更高的和程序都没有回应。如何使程序运行以获得更高的值?