首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Python游戏的拔河

Python游戏的拔河
EN

Stack Overflow用户
提问于 2016-12-14 06:42:21
回答 1查看 276关注 0票数 0

我想做一场拔河比赛,但我遇到了一个问题。我不知道如何在不导入pygame的情况下更改x值。我所需要的就是,当按下“z”时,x向左移动5,当按下“m”时,它向右移动5。

代码语言:javascript
复制
import simplegui
import random
import sys

x = 500
y = 200
num = 0


def draw_handler(canvas):
 global x
 global y
 global num
 color = "RGB(15, 69, 320)"


 x = x + num
 if (x >= 750):
    print ("Red Wins")
    quit()
 if (x <= 250):
    print ("Blue Wins")
    quit()


 canvas.draw_polygon([(0,0),(500,0),(500,500),(0,500)], 2, "Blue", "Blue")
 canvas.draw_polygon([(500,0),(500,500),(1000,0),(500,1000)], 2, "Red", "Red")
 canvas.draw_polygon([(0,0),(250,200),(0,400)], 2, "Black", "Red")
 canvas.draw_polygon([(1000,0),(750,200),(1000,400)], 2, "Black", "Blue")
 #Finish Line - canvas.draw_polygon([(199,0),(201,0),(199,1000),(201,1000)], 2, "Black", "Black")
 canvas.draw_polygon([(0,199),(0,201),(1000,199),(1000,201)], 2, "White", "Black") 
 canvas.draw_line((500,0),(500,500), 5, ("Black"))
 canvas.draw_line((0,0),(0,1000), 5, ("Black"))
 canvas.draw_line((0,0),(1000,0), 5, ("Black"))
 canvas.draw_line((0,400),(1000,400), 5, ("Black"))
 canvas.draw_line((1000,0),(1000,400), 5, ("Black"))

 canvas.draw_circle((x, y), 30, 20, "Black", "White")
 canvas.draw_circle((x, y), 80, 1, "Black")
 canvas.draw_circle((x, y), 90, 1, "Black")
 canvas.draw_circle((x, y), 100, 1, "Black")
 canvas.draw_circle((x, y), 120, 1, "Black")


 for i in range (1,1):
    print""
frame = simplegui.create_frame("Go", 1000, 400)
frame.set_draw_handler(draw_handler)
frame.set_canvas_background("Red")
frame.start() 

代码更新here

EN

回答 1

Stack Overflow用户

发布于 2016-12-14 06:47:34

您可以使用while循环不断请求输入,然后在循环中处理该输入,并在每次迭代中重新绘制画布。我知道这可能会很痛苦,因为他们还必须按enter键,但这可能是您必须要做的。希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41131825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档