from
microbit import * def controls(): sleep(100) (a,b) = (button_a.was_pressed(),button_b.was_pressed()) if a and b: return 10 elif a: return -1 elif b: return 1 else: return 0 def shooting(): if controls() == 10: return 0 def printBoard (move,previousPost): x=0 y=0 if move == 10: move = 0 currentPost = previousPost + move if currentPost > 4: currentPost = 4 if currentPost < 0: currentPost = 0 boardStatus1[previousPost][4] = 0 boardStatus1[currentPost][4] = 1 killFactor = shooting() if killFactor == 0: boardStatus1[currentPost][0]=0 for row in boardStatus1: for status in boardStatus1[x]: if status == 1: display.set_pixel(x,y,9) elif status == 0: display.set_pixel(x,y,0) y += 1 if y > 4: y = 0 x += 1 if x > 5: x=0 return currentPost print("Current Post: "+ str(currentPost)) def initFunction(startPoint): boardStatus1[startPoint][4]=1 display.scroll("Start!!!") boardStatus1 = [[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]] boardStatus2 = [[0,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] boardStatus3 = [[0,0,0,0,0],[0,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]] boardStatus4 = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,0,0],[0,0,0,0,0]] boardStatus5 = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1],[0,0,0,0,0]] boardStatus6 = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,1]] initCompleted=0 while True: if initCompleted == 1: prevPosition=postNow postNow=printBoard(controls(),prevPosition) if initCompleted == 0: prevPosition=2 postNow=printBoard(controls(),prevPosition) initCompleted=1 if boardStatus1 == boardStatus2: display.scroll("Won!!!") if boardStatus1 == boardStatus3: display.scroll("Won!!!") if boardStatus1 == boardStatus4: display.scroll("Won!!!") if boardStatus1 == boardStatus5: display.scroll("Won!!!") if boardStatus1 == boardStatus6: display.scroll("Won!!!"