basic.show_number(3)
basic.show_number(2)
basic.show_number(1)
basic.pause(500) # 計時 3,2,1 開始游戲,停頓5s
basic.show_leds("""
. . # . .
. . # . .
# . # . #
. # # # .
. . # . .
""") # 數秒結束 顯示一個向下的箭頭
game.set_score(0) # 設定一個分數
x=randint(0, 2) # 亂數模塊產生 0 到 2的亂數
sudu = 600
spirt = game.create_sprite(2, 4) # 保證精靈初始狀態在螢屏底部中間
niuye1 = game.create_sprite(x, 0)
niuye2 = game.create_sprite(x+1, 0)
niuye3 = game.create_sprite(x+2, 0) # 創建三個精靈模塊
basic.pause(400)
i = 0
while True:
if input.acceleration(Dimension.X)>200: # 判斷 x 方向加速度,大于 200
spirt.move(1) # spirt x 坐標加 1
basic.pause(200)
else:
spirt.move(-1)
basic.pause(200)
niuye1.change(LedSpriteProperty.Y, 1)
niuye2.change(LedSpriteProperty.Y, 1)
niuye3.change(LedSpriteProperty.Y, 1)
basic.pause(200)
if spirt.is_touching(niuye1) or spirt.is_touching(niuye2)or spirt.is_touching(niuye3): # 如果碰到精靈中的任何一個
game.game_over() # 游戲結束
game.score()
break
if niuye2.get(LedSpriteProperty.Y)==4:
x=randint(0, 2)
niuye1.set(LedSpriteProperty.X, x)
niuye2.set(LedSpriteProperty.X, x+1)
niuye3.set(LedSpriteProperty.X, x+2)
niuye1.set(LedSpriteProperty.Y, 0)
niuye2.set(LedSpriteProperty.Y, 0)
niuye3.set(LedSpriteProperty.Y, 0)
basic.pause(200)
i += 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/293074.html
標籤:其他
