我正在尝试创建一个简单的游戏,用户在屏幕上移动一个“X”来尝试得到一个“O”。它需要我使用箭头(上,下,左,右),我不知道如何编程。我在网上看了很多例子,比如curses,getch,sys,pygame,但不是太复杂就是不能在我的电脑上运行。你知道吗
有人能提供一个完整的例子和解释如何在Python中检测按键,比如。还需要游戏屏幕的帮助,特别是在某个位置打印一些东西,比如说lie(0,0),有点像turtle在(0,0)处开始绘图:
userposy = 0 (y position of the 'X')
*print 'X' at (0, userposy)*
while True:
char = *detect what key is pressed*
if char == *down arrow*:
userposy -= 1.
*print 'X' at (0, userposy)*
我相信这正是您使用Python turtle所描述的:
首先单击窗口使其成为侦听器。然后你可以单独按下或按住向下箭头键(稍有延迟后),它会自动重复。你知道吗
尝试使用Pygame!它关注所有的细节,并为您提供了一个简单的游戏用户输入界面:
https://www.pygame.org/news
(我想说的是,这可能是阻力最小的路径。但我可能错了)
相关问题 更多 >
编程相关推荐