from microbit import *
from random import randint
shapes = "TIJLOSZTIJLOSZTIJLOSZTIJLOSZTIJLOSZT "
display.show("-")
while True:
if button_a.was_pressed():
display.show(" ")
sleep(100)
ln = len(shapes)
if ln == 1:
break
r = randint(0,ln-2)
display.show(shapes[r])
if r == 0:
shapes = shapes[1:]
else:
shapes = shapes[0:r] + shapes[r+1:]
display.show("=")
由於 MicroPython 不是一般 Python,它只提供精簡版的函數庫,所以不足的功能要自己寫。上面的程式每按一次 A 鍵,隨機抽一個拼塊,因此程式將 36 個拼塊依序排列一字串,亂數隨機抽一個,被抽到的字塊拿掉,未被抽走的字塊再合併成一字串,再隨機抽籤,直到抽完為止。
六月份中國象棋對局
-
[Game "Chinese Chess"] [Format "Chinese"] {寡人勝網友。一度劣勢,幾近告負,最終僥幸得以翻盤} 1.
炮二平五 馬8進7 2. 馬二進三 卒3進1 3. 車一平二 車9平8 4. 馬八進九 馬2進3 5. 兵三進一 象3進5 6. 馬三進四 (6.
車九進一 {w 6...
4 天前
沒有留言:
張貼留言