gpt4 book ai didi

python - 如何在 Pygame 中获取用户的输入并将其保存为变量?

转载 作者:太空狗 更新时间:2023-10-30 00:02:40 25 4
gpt4 key购买 nike

<分区>

我想在游戏中获取用户的输入(例如他们的名字),然后将其显示在屏幕上。

我尝试了模块(包括 InputBox ),但它们都不起作用。他们只是在屏幕上显示我的文字。

我想将该输入保存到一个变量。有什么办法吗?

Example:

font1 = pygame.font.SysFont("None", 30)
score = 0
text = font1.render("{}".format(score), True,(255,255,255))
...
...
if sneakeattheapple:
score += 1
text = font1.render("{}".format(score), True,(255,255,255))
...
...
screen.blit(text,(275,6))

这会将 score 变量显示在屏幕上。但是 score 已经定义了,我想用用户给定的变量来做到这一点。

EDIT: Let me be more clear. In Python we can do this:

x = input("Do you want to do this? (y/n): ")
if x == "y":
#do something
if x == "n":
#do something

这就是我想在 Pygame 中做的事情。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com