8浏览
查看: 8|回复: 4

[项目] 【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师

[复制链接]
【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师图1

Kitronik ARCADE 使用 Microsoft MakeCode 平台,具有以下优势:
图形化编程界面:适合初学者,支持拖拽式编程。
即时模拟器:可以实时测试游戏效果。
硬件兼容性:可部署到 Kitronik ARCADE 设备,实现实体游戏体验。
支持 Python/JavaScript:便于进阶学习。


【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师图2

驴友花雕  中级技神
 楼主|

发表于 2 小时前

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师

作为学习、练习与尝试,这里创建一个记忆大师的小游戏。
打开网页版:https://arcade.makecode.com/,设置项目名称:记忆大师

MicroPython实验代码

  1. @namespace
  2. class SpriteKind:
  3.     glyph = SpriteKind.create()
  4.     UI = SpriteKind.create()
  5. def InitUI():
  6.     global mySprite, CursorSprite, curX, curY
  7.     mySprite = sprites.create(imageList[0], SpriteKind.UI)
  8.     mySprite.set_position(60, 90)
  9.     mySprite = sprites.create(imageList[1], SpriteKind.UI)
  10.     mySprite.set_position(80, 90)
  11.     mySprite = sprites.create(imageList[2], SpriteKind.UI)
  12.     mySprite.set_position(100, 90)
  13.     mySprite = sprites.create(imageList[3], SpriteKind.UI)
  14.     mySprite.set_position(60, 108)
  15.     mySprite = sprites.create(imageList[4], SpriteKind.UI)
  16.     mySprite.set_position(80, 108)
  17.     mySprite = sprites.create(imageList[5], SpriteKind.UI)
  18.     mySprite.set_position(100, 108)
  19.     CursorSprite = sprites.create(img("""
  20.             1 1 1 1 1 . . . . . . 1 1 1 1 1
  21.             1 . . . . . . . . . . . . . . 1
  22.             1 . . . . . . . . . . . . . . 1
  23.             1 . . . . . . . . . . . . . . 1
  24.             1 . . . . . . . . . . . . . . 1
  25.             1 . . . . . . . . . . . . . . 1
  26.             . . . . . . . . . . . . . . . .
  27.             . . . . . . . . . . . . . . . .
  28.             . . . . . . . . . . . . . . . .
  29.             . . . . . . . . . . . . . . . .
  30.             . . . . . . . . . . . . . . . .
  31.             1 . . . . . . . . . . . . . . 1
  32.             1 . . . . . . . . . . . . . . 1
  33.             1 . . . . . . . . . . . . . . 1
  34.             1 . . . . . . . . . . . . . . 1
  35.             1 1 1 1 1 . . . . . . 1 1 1 1 1
  36.             """),
  37.         SpriteKind.UI)
  38.     CursorSprite.set_position(60, 90)
  39.     curX = 0
  40.     curY = 0
  41. def PlaySequence():
  42.     global CurrentIndex, PlayerTurn
  43.     index2 = 0
  44.     while index2 <= len(CodeSequence) - 1:
  45.         CurrentIndex = index2
  46.         AddToSpriteList()
  47.         pause(200)
  48.         index2 += 1
  49.     pause(600)
  50.     for value2 in spriteList:
  51.         value2.destroy()
  52.     CurrentIndex = 0
  53.     PlayerTurn = True
  54. def on_up_pressed():
  55.     global curY
  56.     curY = max(0, curY - 1)
  57.     UpdateCurPos()
  58. controller.up.on_event(ControllerButtonEvent.PRESSED, on_up_pressed)
  59. def AddToSequence():
  60.     CodeSequence.append(randint(0, 5))
  61. def on_down_pressed():
  62.     global curY
  63.     curY = min(1, curX + 1)
  64.     UpdateCurPos()
  65. controller.down.on_event(ControllerButtonEvent.PRESSED, on_down_pressed)
  66. def InitSounds2():
  67.     global SoundList
  68.     SoundList = [165, 175, 196, 220, 247, 262]
  69. def on_a_pressed():
  70.     global CursorAt, CurrentIndex
  71.     if PlayerTurn == True:
  72.         CursorAt = curX + curY * 3
  73.         if CursorAt == CodeSequence[CurrentIndex]:
  74.             AddToSpriteList()
  75.             info.change_score_by(1)
  76.             CurrentIndex += 1
  77.             if CurrentIndex == len(CodeSequence):
  78.                 NextLevel()
  79.         else:
  80.             info.change_life_by(-1)
  81.             music.power_down.play()
  82. controller.A.on_event(ControllerButtonEvent.PRESSED, on_a_pressed)
  83. def on_right_pressed():
  84.     global curX
  85.     curX = min(2, curX + 1)
  86.     UpdateCurPos()
  87. controller.right.on_event(ControllerButtonEvent.PRESSED, on_right_pressed)
  88. def InitImages():
  89.     global imageList
  90.     imageList = [img("""
  91.             . . . . . . . . . . b 5 b . . .
  92.             . . . . . . . . . b 5 b . . . .
  93.             . . . . . . . . . b c . . . . .
  94.             . . . . . . b b b b b b . . . .
  95.             . . . . . b b 5 5 5 5 5 b . . .
  96.             . . . . b b 5 d 1 f 5 5 d f . .
  97.             . . . . b 5 5 1 f f 5 d 4 c . .
  98.             . . . . b 5 5 d f b d d 4 4 . .
  99.             b d d d b b d 5 5 5 4 4 4 4 4 b
  100.             b b d 5 5 5 b 5 5 4 4 4 4 4 b .
  101.             b d c 5 5 5 5 d 5 5 5 5 5 b . .
  102.             c d d c d 5 5 b 5 5 5 5 5 5 b .
  103.             c b d d c c b 5 5 5 5 5 5 5 b .
  104.             . c d d d d d d 5 5 5 5 5 d b .
  105.             . . c b d d d d d 5 5 5 b b . .
  106.             . . . c c c c c c c c b b . . .
  107.             """),
  108.         img("""
  109.             . . . . c c c b b b b b . . . .
  110.             . . c c b 4 4 4 4 4 4 b b b . .
  111.             . c c 4 4 4 4 4 5 4 4 4 4 b c .
  112.             . e 4 4 4 4 4 4 4 4 4 5 4 4 e .
  113.             e b 4 5 4 4 5 4 4 4 4 4 4 4 b c
  114.             e b 4 4 4 4 4 4 4 4 4 4 5 4 4 e
  115.             e b b 4 4 4 4 4 4 4 4 4 4 4 b e
  116.             . e b 4 4 4 4 4 5 4 4 4 4 b e .
  117.             8 7 e e b 4 4 4 4 4 4 b e e 6 8
  118.             8 7 2 e e e e e e e e e e 2 7 8
  119.             e 6 6 2 2 2 2 2 2 2 2 2 2 6 c e
  120.             e c 6 7 6 6 7 7 7 6 6 7 6 c c e
  121.             e b e 8 8 c c 8 8 c c c 8 e b e
  122.             e e b e c c e e e e e c e b e e
  123.             . e e b b 4 4 4 4 4 4 4 4 e e .
  124.             . . . c c c c c e e e e e . . .
  125.             """),
  126.         img("""
  127.             . . . . . . . e c 7 . . . . . .
  128.             . . . . e e e c 7 7 e e . . . .
  129.             . . c e e e e c 7 e 2 2 e e . .
  130.             . c e e e e e c 6 e e 2 2 2 e .
  131.             . c e e e 2 e c c 2 4 5 4 2 e .
  132.             c e e e 2 2 2 2 2 2 4 5 5 2 2 e
  133.             c e e 2 2 2 2 2 2 2 2 4 4 2 2 e
  134.             c e e 2 2 2 2 2 2 2 2 2 2 2 2 e
  135.             c e e 2 2 2 2 2 2 2 2 2 2 2 2 e
  136.             c e e 2 2 2 2 2 2 2 2 2 2 2 2 e
  137.             c e e 2 2 2 2 2 2 2 2 2 2 4 2 e
  138.             . e e e 2 2 2 2 2 2 2 2 2 4 e .
  139.             . 2 e e 2 2 2 2 2 2 2 2 4 2 e .
  140.             . . 2 e e 2 2 2 2 2 4 4 2 e . .
  141.             . . . 2 2 e e 4 4 4 2 e e . . .
  142.             . . . . . 2 2 e e e e . . . . .
  143.             """),
  144.         img("""
  145.             . . . . . . . . . . b b b . . .
  146.             . . . . . . . . b e e 3 3 b . .
  147.             . . . . . . b b e 3 2 e 3 a . .
  148.             . . . . b b 3 3 e 2 2 e 3 3 a .
  149.             . . b b 3 3 3 3 3 e e 3 3 3 a .
  150.             b b 3 3 3 3 3 3 3 3 3 3 3 3 3 a
  151.             b 3 3 3 d d d d 3 3 3 3 3 d d a
  152.             b b b b b b b 3 d d d d d d 3 a
  153.             b d 5 5 5 5 d b b b a a a a a a
  154.             b 3 d d 5 5 5 5 5 5 5 d d d d a
  155.             b 3 3 3 3 3 3 d 5 5 5 d d d d a
  156.             b 3 d 5 5 5 3 3 3 3 3 3 b b b a
  157.             b b b 3 d 5 5 5 5 5 5 5 d d b a
  158.             . . . b b b 3 d 5 5 5 5 d d 3 a
  159.             . . . . . . b b b b 3 d d d b a
  160.             . . . . . . . . . . b b b a a .
  161.             """),
  162.         img("""
  163.             . . . . . 3 3 b 3 3 d d 3 3 . .
  164.             . . . . 3 1 1 d 3 d 1 1 1 1 3 .
  165.             . . . 3 d 1 1 1 d 1 1 1 d 3 1 3
  166.             . . 3 d d 1 1 1 d d 1 1 1 3 3 3
  167.             . 3 1 1 d 1 1 1 1 d d 1 1 b . .
  168.             . 3 1 1 1 d 1 1 1 1 1 d 1 1 3 .
  169.             . b d 1 1 1 d 1 1 1 1 1 1 1 3 .
  170.             . 4 b 1 1 1 1 d d 1 1 1 1 d 3 .
  171.             . 4 4 d 1 1 1 1 1 1 d d d b b .
  172.             . 4 d b d 1 1 1 1 1 1 1 1 3 . .
  173.             4 d d 5 b d 1 1 1 1 1 1 1 3 . .
  174.             4 5 d 5 5 b b d 1 1 1 1 d 3 . .
  175.             4 5 5 d 5 5 d b b b d d 3 . . .
  176.             4 5 5 5 d d d d 4 4 b 3 . . . .
  177.             . 4 5 5 5 4 4 4 . . . . . . . .
  178.             . . 4 4 4 . . . . . . . . . . .
  179.             """),
  180.         img("""
  181.             . . . . . . . . . . . . . . . .
  182.             . . . . . . 6 6 6 6 6 6 6 6 . .
  183.             . . . . . 6 c 6 6 6 6 6 6 9 6 .
  184.             . . . . 6 c c 6 6 6 6 6 6 9 c 6
  185.             . . d 6 9 c c 6 9 9 9 9 9 9 c c
  186.             . d 6 6 9 c b 8 8 8 8 8 8 8 6 c
  187.             . 6 6 6 9 b 8 8 b b b 8 b b 8 6
  188.             . 6 6 6 6 6 8 b b b b 8 b b b 8
  189.             . 6 6 6 6 8 6 6 6 6 6 8 6 6 6 8
  190.             . 6 d d 6 8 f 8 8 8 f 8 8 8 8 8
  191.             . d d 6 8 8 8 f 8 8 f 8 8 8 8 8
  192.             . 8 8 8 8 8 8 8 f f f 8 8 8 8 8
  193.             . 8 8 8 8 f f f 8 8 8 8 f f f f
  194.             . . . 8 f f f f f 8 8 f f f f f
  195.             . . . . f f f f . . . . f f f .
  196.             . . . . . . . . . . . . . . . .
  197.             """)]
  198. def UpdateCurPos():
  199.     CursorSprite.x = 60 + 20 * curX
  200.     CursorSprite.y = 90 + 18 * curY
  201. def InitSequence():
  202.     for index3 in range(3):
  203.         AddToSequence()
  204. def NextLevel():
  205.     global PlayerTurn
  206.     PlayerTurn = False
  207.     pause(500)
  208.     for value3 in spriteList:
  209.         value3.destroy()
  210.     AddToSequence()
  211.     PlaySequence()
  212. def AddToSpriteList():
  213.     global x, y, mySprite
  214.     x = CurrentIndex % 9 * 17
  215.     y = Math.floor(CurrentIndex / 9) * 17
  216.     mySprite = sprites.create(imageList[CodeSequence[CurrentIndex]], SpriteKind.glyph)
  217.     spriteList[CurrentIndex] = mySprite
  218.     mySprite.left = x + 5
  219.     mySprite.top = y + 20
  220.     music.play_tone(SoundList[CodeSequence[CurrentIndex]],
  221.         music.beat(BeatFraction.HALF))
  222. def on_left_pressed():
  223.     global curX
  224.     curX = max(0, curX - 1)
  225.     UpdateCurPos()
  226. controller.left.on_event(ControllerButtonEvent.PRESSED, on_left_pressed)
  227. def on_on_created(sprite):
  228.     sprite.set_flag(SpriteFlag.GHOST, True)
  229. sprites.on_created(SpriteKind.UI, on_on_created)
  230. y = 0
  231. x = 0
  232. CursorAt = 0
  233. SoundList: List[number] = []
  234. PlayerTurn = False
  235. CurrentIndex = 0
  236. CodeSequence: List[number] = []
  237. curY = 0
  238. curX = 0
  239. CursorSprite: Sprite = None
  240. imageList: List[Image] = []
  241. mySprite: Sprite = None
  242. spriteList: List[Sprite] = []
  243. index = 0
  244. value = 0
  245. game.show_long_text("Memorize the sequence and replay it", DialogLayout.BOTTOM)
  246. spriteList = sprites.all_of_kind(SpriteKind.glyph)
  247. info.set_score(0)
  248. info.set_life(3)
  249. InitImages()
  250. InitSounds2()
  251. InitUI()
  252. InitSequence()
  253. PlaySequence()
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2 小时前

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师

这是一个基于ARCADE MakeCode的记忆大师游戏(类似西蒙说)代码。

游戏概述
这是一个记忆训练游戏,玩家需要记住系统展示的图案序列,然后按照相同顺序重复这个序列。

代码结构分析

1. 精灵种类定义
python
  1. class SpriteKind:
  2.     glyph = SpriteKind.create()  # 图案精灵
  3.     UI = SpriteKind.create()     # 界面元素
复制代码


2. 核心游戏机制
游戏流程
系统展示:显示一系列图案序列
玩家记忆:观察并记住序列顺序
玩家输入:使用方向键和A键重复序列
验证判断:检查玩家输入是否正确

3. UI界面系统
初始化UI (InitUI)
python
  1. def InitUI():
  2.     # 创建6个图案按钮(2行3列)
  3.     mySprite = sprites.create(imageList[0], SpriteKind.UI)
  4.     mySprite.set_position(60, 90)  # 第一行第一个
  5.     # ... 创建其他5个按钮
  6.    
  7.     # 创建选择光标
  8.     CursorSprite = sprites.create(光标图片, SpriteKind.UI)
  9.     CursorSprite.set_position(60, 90)  # 初始位置
复制代码

界面布局:
text
[0] [1] [2]  ← 第一行 (y=90)
[3] [4] [5]  ← 第二行 (y=108)

光标控制
python
  1. def UpdateCurPos():
  2.     CursorSprite.x = 60 + 20 * curX  # 水平间隔20像素
  3.     CursorSprite.y = 90 + 18 * curY  # 垂直间隔18像素
复制代码

4. 图案和音效系统
图案资源 (InitImages)
游戏包含6种精美的像素艺术图案:
龙/怪物图案:复杂的生物设计
圆形生物:对称的卡通形象
火焰/水滴:动态效果图案
恐龙:绿色恐龙造型
机器人:机械风格设计
船只/车辆:交通工具图案

音效系统 (InitSounds2)
python
  1. SoundList = [165, 175, 196, 220, 247, 262]  # 6个不同频率的音调
复制代码


5. 游戏逻辑核心
序列播放 (PlaySequence)
python
  1. def PlaySequence():
  2.     for index in range(len(CodeSequence)):
  3.         CurrentIndex = index
  4.         AddToSpriteList()  # 显示当前图案
  5.         pause(200)  # 每个图案显示200ms
  6.     # 清空显示,准备玩家输入
复制代码

玩家输入处理
python
  1. def on_a_pressed():
  2.     if PlayerTurn == True:
  3.         CursorAt = curX + curY * 3  # 计算选择的图案索引
  4.         if CursorAt == CodeSequence[CurrentIndex]:  # 判断是否正确
  5.             info.change_score_by(1)  # 得分
  6.             CurrentIndex += 1
  7.             if CurrentIndex == len(CodeSequence):  # 完成当前级别
  8.                 NextLevel()
  9.         else:  # 错误选择
  10.             info.change_life_by(-1)  # 扣生命值
复制代码


6. 序列管理系统
生成序列
python
  1. def AddToSequence():
  2.     CodeSequence.append(randint(0, 5))  # 随机添加0-5的图案索引
  3. def InitSequence():
  4.     for index in range(3):  # 初始序列长度为3
  5.         AddToSequence()
复制代码

下一关卡
python
  1. def NextLevel():
  2.     PlayerTurn = False
  3.     AddToSequence()  # 增加序列长度
  4.     PlaySequence()   # 播放新序列
复制代码


7. 显示系统
图案显示 (AddToSpriteList)
python
  1. def AddToSpriteList():
  2.     x = CurrentIndex % 9 * 17  # 水平位置计算
  3.     y = Math.floor(CurrentIndex / 9) * 17  # 垂直位置计算
  4.     mySprite = sprites.create(imageList[图案索引], SpriteKind.glyph)
  5.     mySprite.left = x + 5  # 设置位置
  6.     mySprite.top = y + 20
  7.     music.play_tone(对应音调, music.beat(BeatFraction.HALF))  # 播放音效
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2 小时前

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师

图形编程参考实验程序

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师图1

通过模拟器,调试与模拟运行

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师图5

实验场景记录

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师图4

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师图3

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师图2

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2 小时前

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师

【花雕动手做】基于 Kitronik 游戏机开发板之记忆大师图1
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail