Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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_Python 3.x - Fatal编程技术网

如何使用python设置时间限制

如何使用python设置时间限制,python,python-3.x,Python,Python 3.x,我正在尝试用python创建一个小游戏。我已经设定了一切,但我想设定一个时间限制。我在互联网上找到了一些东西,但它不适用于这个项目,但适用于另一个项目 c.create_text(450, 20, text = 'Time', fill = 'red') c.create_text(650, 20, text = 'Score', fill = 'red') time_text = c.create_text(450, 20, text = 'Time', fill = 'red') score

我正在尝试用python创建一个小游戏。我已经设定了一切,但我想设定一个时间限制。我在互联网上找到了一些东西,但它不适用于这个项目,但适用于另一个项目

c.create_text(450, 20, text = 'Time', fill = 'red')
c.create_text(650, 20, text = 'Score', fill = 'red')
time_text = c.create_text(450, 20, text = 'Time', fill = 'red')
score_text = c.create_text(650, 20, text = 'Score', fill = 'red')
def print_score(score) :
    c.itemconfig(score_text, text = str(score))
def print_time(time) :
    c.itemconfig(time_text, text = str(time))


ENNEMY_CHANCE = 10
TIME_LIMIT = 30
SCORE_BONUS = 1000
score = 0
bonus = 0
end = time() + TIME_LIMIT

#Main
while True :
    if randint(1, ENNEMY_CHANCE) == 1:
        create_ennemy()
    move_ennemies()
    hide_ennemies()
    score += ennemy_kill()
    if(int(score/SCORE_BONUS)) > bonus:
        bonus += 1
        end += TIME_LIMIT
    print_score(score)
    print_time(int(end - time()))
    window.update()
但我明白了:

    end = time() + TIME_LIMIT
TypeError: 'int' object is not callable

如果你知道一个更简单的方法来设定一个时间限制,那将是超级的。

你导入了时间吗?我认为您在代码的某个地方使用了“time”名称作为整数变量,并且代码不明确。请尝试以下操作以获取当前时间:

import time as time_module
now = time_module.time()
试试这个

import time   
start = time.time()         #the variable that holds the starting time  
elapsed = 0                 #the variable that holds the number of seconds elapsed.  
while elapsed < 30:         #while less than 30 seconds have elapsed    

elapsed = time.time() - start #update the time elapsed
导入时间
start=time.time()#保存开始时间的变量
已用=0#保存已用秒数的变量。
经过时间<30时:#经过时间小于30秒时
已用时间=time.time()-start#更新已用时间

int
确实不可调用,您可能用您的值重新声明了
time
import。是的。你是对的。我将时间设置为高于此值的变量。