Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么赢了';当输入更高的值时,我的游戏不会运行吗?_Python - Fatal编程技术网

Python 为什么赢了';当输入更高的值时,我的游戏不会运行吗?

Python 为什么赢了';当输入更高的值时,我的游戏不会运行吗?,python,Python,我正在用Python3.4制作一个基于文本的游戏,它需要做大量的计算。我的问题是,当我为我的游戏输入一个更高的值时,它不会给出任何输出或错误 此代码从用户处获取输入并将其转换为元组 def getCoords(): mapdata = [] coords = input('Enter 2 numbers without a space from 11 - 99>') coords = tuple(coords) coords = tuple(map(int,

我正在用Python3.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
这是我节目的开始

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时,程序工作正常。再高一点,程序就没反应了。如何使程序运行以获得更高的值?

您的程序在运行时调用
getCoords
?是。我应该添加更多的代码吗?请您具体一点,我无法重新创建程序挂起。这两个变量都没有定义:
forces[0]*lbmstats[0]
您设置了
enemydata=get敌军(coords)
但是
get敌军
没有返回任何内容。此外,变量
place
,设置为
coords
的第一个,在您显示的代码中从未使用过。
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