大家好,我是来自汕头市龙湖实验学校的一名初二级学生。
这个暑假我接触了掌控板,在老师的帮助下我们学习了通过pingpong库与掌控板进行交互的方法。刚好DF举办了这样的一个活动,活动内容很有意思。虽然我之前没有参加过类似的科创活动,就是觉得如果能够作为检验学习成果的一种方式来参加还是很有意义的。
选择主题上,老师建议我们从社会热点方向进行思考和选择。我觉得目前最火热的应该是奥运会吧,于是就选择了这个方向来进行思考,结合掌控板的屏幕显示功能,选择了知识问答的主题。
设计思路
游戏的规则是在掌控板上用文字或图片的方式显示一道题目,玩家可以通过触碰掌控板上的p,y,t,h金手指分别来对应a,b,c,d四个选择项来进行作答。
步骤1 安装pinpong库
步骤2 准备素材
步骤3 编写代码
代码
import time
from pinpong.board import Board,Pin
from pinpong.extension.handpy import HPSensor,HPScreen
Board("handpy").begin()
esp=HPScreen()
s=HPSensor()
esp.fill_screen(color="black")
esp.display_in_line("Welcome to the game",1)
time.sleep(2)
esp.display_in_line("Game rules:",1)
time.sleep(1)
esp.display_in_line("P:A;Y:B;T:C;H:D",2)
esp.display_in_line("你有三秒的思考时间",3)
time.sleep(3)
esp.fill_screen(color="black")
esp.display_image(0,0,128,64,r"d:\coding\sport\5.png")
time.sleep(2)
esp.fill_screen(color="black")
esp.display_in_line("A:游泳",1)
esp.display_in_line("B:射击",2)
esp.display_in_line("C:无法确定",3)
esp.display_in_line("D:击剑",4)
time.sleep(5)
esp.fill_screen(color="black")
if s.touch_Y():
esp.display_image(0,0,128,64,r"d:\coding\sport\11.png")
time.sleep(1)
esp.fill_screen(color="black")
esp.display_in_line("答对了",1)
else:
esp.display_image(0,0,128,64,r"d:\coding\sport\12.png")
time.sleep(1)
esp.fill_screen(color="black")
esp.display_in_line("答错了",1)
esp.display_in_line("正确答案是B",2)
time.sleep(2)
esp.display_in_line("东京奥运会金牌:",1)
esp.display_in_line("女子10米气步gun",2)
esp.display_in_line("混合团体10米气手gun",3)
esp.display_in_line("混合团体10米气步gun",4)
time.sleep(3)
esp.display_image(0,0,128,64,r"d:\coding\sport\6.png")
time.sleep(2)
esp.display_in_line("A:排球",1)
esp.display_in_line("B:棒球",2)
esp.display_in_line("C:乒乓球",3)
esp.display_in_line("D:以上都不是",4)
time.sleep(5)
esp.fill_screen(color="black")
if s.touch_H():
esp.display_image(0,0,128,64,r"d:\coding\sport\11.png")
time.sleep(1)
esp.display_in_line("答对了",1)
else:
esp.display_image(0,0,128,64,r"d:\coding\sport\12.png")
time.sleep(1)
esp.fill_screen(color="black")
esp.display_in_line("答错了",1)
esp.display_in_line("正确答案是D",2)
time.sleep(2)
esp.display_in_line("东京奥运会金牌:",1)
esp.display_in_line("羽毛球混合双打",2)
esp.display_in_line("羽毛球女子单打",3)
time.sleep(3)
esp.display_image(0,0,128,64,r"d:\coding\sport\8.png")
time.sleep(2)
esp.display_in_line("A:游泳",1)
esp.display_in_line("B:跳高",2)
esp.display_in_line("C:跳水",3)
esp.display_in_line("D:以上都不是",4)
time.sleep(5)
esp.fill_screen(color="black")
if s.touch_T():
esp.display_image(0,0,128,64,r"d:\coding\sport\11.png")
time.sleep(1)
esp.display_in_line("答对了",1)
else:
esp.display_image(0,0,128,64,r"d:\coding\sport\12.png")
time.sleep(1)
esp.fill_screen(color="black")
esp.display_in_line("答错了",1)
esp.display_in_line("正确答案是C",2)
time.sleep(2)
esp.display_in_line("东京奥运会金牌:",1)
esp.display_in_line("跳水女子双人3米跳板",2)
esp.display_in_line("跳水女子双人10米跳台",3)
esp.display_in_line("跳水男子双人3米跳板",4)
time.sleep(3)
esp.fill_screen(color="black")
esp.display_in_line("跳水女子3米跳板",1)
esp.display_in_line("跳水女子10米跳台",2)
esp.display_in_line("跳水男子10米跳台",3)
time.sleep(3)
esp.display_image(0,0,128,64,r"d:\coding\sport\9.png")
time.sleep(3)
esp.display_in_line("A:赛跑",1)
esp.display_in_line("B:田径",2)
esp.display_in_line("C:相扑",3)
esp.display_in_line("D:以上都不是",4)
time.sleep(5)
esp.fill_screen(color="black")
if s.touch_Y():
esp.display_image(0,0,128,64,r"d:\coding\sport\11.png")
time.sleep(1)
esp.display_in_line("答对了",1)
else:
esp.display_image(0,0,128,64,r"d:\coding\sport\12.png")
time.sleep(1)
esp.fill_screen(color="black")
esp.display_in_line("答错了",1)
esp.display_in_line("正确答案是C",2)
time.sleep(2)
esp.display_in_line("东京奥运会金牌:",1)
esp.display_in_line("田径女子铅球",2)
time.sleep(1)
esp.display_image(0,0,128,64,r"d:\coding\sport\10.png")
time.sleep(3)
esp.display_in_line("A:乓乒球",1)
esp.display_in_line("B:乒乓球",2)
esp.display_in_line("C:羽毛球",3)
esp.display_in_line("D:无法确定",4)
time.sleep(5)
esp.fill_screen(color="black")
if s.touch_Y():
esp.display_image(0,0,128,64,r"d:\coding\sport\11.png")
time.sleep(1)
esp.display_in_line("答对了",1)
else:
esp.display_image(0,0,128,64,r"d:\coding\sport\12.png")
time.sleep(1)
esp.fill_screen(color="black")
esp.display_in_line("答错了",1)
esp.display_in_line("正确答案是B",2)
time.sleep(2)
esp.display_in_line("东京奥运会金牌:",1)
esp.display_in_line("乒乓球女子单打",2)
esp.display_in_line("乒乓球男子单打",3)
esp.display_in_line("乒乓球女子团体",4)
time.sleep(3)
esp.fill_screen(color="black")
esp.display_in_line("乒乓球男子团体",1)
time.sleep(0.5)
esp.display_image(0,0,128,64,r"d:\coding\sport\7.png")
time.sleep(3)
esp.display_in_line("A:引体向上",1)
esp.display_in_line("B:举轻",2)
esp.display_in_line("C:举重",3)
esp.display_in_line("D:无法确定",4)
time.sleep(3)
esp.fill_screen(color="black")
if s.touch_Y():
esp.display_image(0,0,128,64,r"d:\coding\sport\11.png")
time.sleep(1)
esp.display_in_line("答对了",1)
else:
esp.display_image(0,0,128,64,r"d:\coding\sport\12.png")
time.sleep(1)
esp.fill_screen(color="black")
esp.display_in_line("答错了",1)
esp.display_in_line("正确答案是B",2)
time.sleep(2)
esp.display_in_line("东京奥运会中国首金是:",1)
esp.display_in_line("举重女子49公斤级",2)
esp.display_in_line("举重男子61公斤级",3)
esp.display_in_line("举重男子67公斤级",4)
time.sleep(5)
esp.fill_screen(color="black")
esp.display_in_line("举重男子73公斤级",1)
esp.display_in_line("举重男子81公斤级",2)
esp.display_in_line("举重女子87公斤级",3)
esp.display_in_line("举重女子87公斤以上级",4)
time.sleep(1)
esp.display_in_line("Game over",1)
esp.display_in_line("Thanks for joining us",2)
项目后记
mind+软件和掌控板真的是绝配,使用起来真的非常方便。而接触了pinpong库,感觉又打开了一道新大门,硬件居然还可以这样调用,真的非常有趣。我们学习的时候查阅了pinpong的文档,中间还是遇到很多问题.后来我们在老师的帮助下,阅读了pinpong库自带的范例。里面有非常多的样例,真是一个宝藏,给了我们很多启发。
81rum19wCJjs2023.09.16
6