步驟1:製作
這是什麼?
用兩個micro:bit玩這個經典的遊戲,並同時學習selection,variables 和random numbers。
這兩支影片為您示範了製作內容和編碼方法:
介紹
編程指引
運作方式
- 剪刀、石頭、布是一個適合兩人玩的經典遊戲。 You and a partner shake your fists 3 times and then make gestures at random to show a rock, paper or scissors. Rock beats scissors, scissors beat paper and paper beats rock (it wraps the rock!).
- When the micro:bit accelerometer detects a shake movement, it sets the variable tool to a random number: 0, 1 or 2.
- We use 0 because computers start counting at 0, and it’s good to remember that 0 is a number!
- The program uses selection to decide what image to show on the LED display. If the random number was 0, it shows a rock icon, if it was 1 it shows the icon representing paper. If it wasn’t 0 or 1, it must be 2 because we instructed the micro:bit to only pick random numbers between 0 and 2, so in that case it shows scissors.
你需要的東西
- 2 個micro:bit(或MakeCode模擬器)
- MakeCode 或, Python 編輯器
- 電池組(選配)
- a partner to play with
步驟2:編碼
步驟3:進階
- Draw your own icons for rock, paper, scissors.
- Think of other tools that could replace rock, paper and scissors or invent new rules.
- Use the micro:bit radio function to make a game that knows if you won or lost by communicating with your friend’s micro:bit.
This content is published under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) licence.