【发布时间】:2014-04-02 17:58:28
【问题描述】:
我试图找出谁在我的游戏中获胜,然后,除了打印所有玩家的得分外,还说谁赢了。但是,我做 Python 的时间不长,也不知道该怎么做。以下是代码的相关部分:
w = 19 #When any of the scores reach more than 19, the game ends.
x = 19
y = 19
z = 19
while gamealive ==1:
if ball.score1 > w or ball.score2 > x or ball.score3 > y or ball.score4 > z:
gamealive=0 # stops the game trying to redraw everything
canvas.delete(ALL) #clears the canvas
canvas.create_text(350, 160, font=("Bauhaus 93",30), fill = 'Red', text='Game Over') #Puts Text on Canvas OGBP
txtpad1score = canvas.create_text(440, 350, font=("Bauhaus 93",40), fill = 'white', text='0') #Puts scores on end canvas
txtpad2score = canvas.create_text(440, 400, font=("Bauhaus 93",40), fill = 'white', text='0')
txtpad3score = canvas.create_text(440, 450, font=("Bauhaus 93",40), fill = 'white', text='0')
txtpad4score = canvas.create_text(440, 500, font=("Bauhaus 93",40), fill = 'white', text='0')
canvas.itemconfig(txtpad1score,text = str(ball.score1))
canvas.itemconfig(txtpad2score,text = str(ball.score2))
canvas.itemconfig(txtpad3score,text = str(ball.score3))
canvas.itemconfig(txtpad4score,text = str(ball.score4))
tk.update_idletasks()
tk.update()
time.sleep(0.001)
我想要它,以便当其中一个分数达到 19 或更高时,游戏结束并打印每个玩家的分数。这行得通,但我也希望它显示“玩家 1(或任何先达到 19 岁以上的玩家)获胜!”但我不知道如何让程序显示哪个分数首先达到 19 或更高。因此,如果玩家 3 或 txtpad3score 达到 20,我希望它说“玩家 3 获胜!”。任何帮助都会很棒。
【问题讨论】:
-
你只有一个赢家吗?你试过什么了?
if怎么样? -
只有一位获胜者。两个玩家的分数不可能同时上升。到目前为止,还没有尝试过任何接近成功的方法。
-
啊修好了,你的“如果”帮助很大。
标签: python tkinter game-engine