gpt4 book ai didi

python - 微型 :bit python Rock Paper Scissors debugging

转载 作者:行者123 更新时间:2023-11-28 19:09:15 25 4
gpt4 key购买 nike

我是 Micro:bit python 的初学者。我正在为带有计分系统的“剪刀石头布”游戏编写代码。但是,它会响应一次摇动,然后即使没有人摇动它也会自动显示一张图片。您能建议一种解决此问题的方法吗?

from microbit import *
import random

count = 0

paper = Image("99999:"
"90009:"
"90009:"
"90009:"
"99999")
rock = Image("00000:"
"09990:"
"09990:"
"09990:"
"00000:")
scissors = Image("00099:"
"99090:"
"00900:"
"99090:"
"00099:")
while True:
while True:
if accelerometer.is_gesture("shake"):
display.clear()
choice = random.randint(0, 2)
if choice == 0:
display.show(rock)
break
elif choice == 1:
display.show(paper)
break
else:
display.show(scissors)
break
while True:
if button_a.is_pressed():
count = count + 1
display.scroll(str(count))
break
elif button_b.is_pressed():
count = count - 1
display.scroll(str(count))
break
elif pin0.is_touched():
display.scroll(str(count))
break

最佳答案

根据我从文档中可以理解的内容, 尝试更改这行代码:if accelerometer.is_gesture("shake"):if accelerometer.was_gesture("shake"):

他们的区别,来自文档:
对于 is_gesture:

Return True or False to indicate if the named gesture is currently active.

对于 was_gesture:

Return True or False to indicate if the named gesture was active since the last call.

关于python - 微型 :bit python Rock Paper Scissors debugging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42651623/

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