def init(self, wi=None, panel=True): global board global oldboard global panel self.board = [[0 for _ in range(self.BOARDSIZE)] for _ in range(self.BOARDSIZE)] self.oldboard = copy.deepcopy(self.board) self.panel = [[0 for _ in range(15)] for _ in range(9)] self.addtile() if panel: self.paneldisplay = True else: self.paneldisplay = False if self.paneldisplay: sp.panel_clear() self.draw() self.playing=True if self.BOARDSIZE > 4 and self.paneldisplay: sp.rectangle(0, 15-(self.BOARDSIZE+2), self.BOARDSIZE+1, 14, "ffffff") else: sp.rectangle(0,15-((self.BOARDSIZE+2)*2-2), ((self.BOARDSIZE+1)*2)-1, 14, "656565") if self.paneldisplay: for i in range(len(self.COLORS)-2): sp.set_pixel_color(sp.matrix(i,0), self.COLORS[i+1]) #sp.set_pixel_color(sp.matrix(i,1), self.COLORS2[i+1]) time.sleep(0.1) print i self.play(wi)
def play(self): while True: sp.panel_clear() x, y = infrapen.get_cords() infrapen.waituntilrelease() sp.set_pixel_color(sp.matrix(x, y), "906090") print x, y
def play(self, wi): import time while self.playing: direction = self.getdirection(wi) if direction == "R": self.right() time.sleep(0.23) elif direction == "L": self.left() time.sleep(0.3) elif direction == "U": self.up() time.sleep(0.3) elif direction == "D": self.down() time.sleep(0.3) if self.checkboard(): self.playing = False print "You win" text, textwidth = self.textHandler.make_text("YOU WIN!", 16,1, color="00ff00") engine =matrixHandler.MatrixEngine(text) for i in range(textwidth+16): engine.shift_left() matrix = engine.get_matrix(cycle=True, cycle_size_col = textwidth+16) sp.set_panel_memory_from_matrix(matrix) return for _ in range(5): sp.set_panel_color("003000") time.sleep(1) sp.panel_clear() time.sleep(1)
def end_current_game(self): if self.current_game is not None: self.current_game.stop_game() print("Terminating currrent game") print("Waiting 1 second for game-thread to finish") time.sleep(1) Led_panel.panel_clear() self.state = self.states["idle"]
def game_over(self): for i in range(5): svetelny_panel.set_panel_color(colors.RED1) time.sleep(0.1) svetelny_panel.panel_clear() time.sleep(0.1) self.player = [0, PANEL_HEIGHT // 2] self.initialize_boards()
def game_over(self): #RED BLINK for i in range(5): svetelny_panel.set_panel_color(colors.RED1) time.sleep(0.1) svetelny_panel.panel_clear() time.sleep(0.1) self.__init__()
def checkforlost(self): self.oldboard = copy.deepcopy(self.board) self.shiftleft() self.leftcount() if self.board == self.oldboard: #cannot move left self.shiftright() self.rightcount() if self.board == self.oldboard: #cannot move right self.shiftup() self.upcount() if self.board == self.oldboard: #cannot move up self.shiftdown() self.downcount() if self.board == self.oldboard: #cannot move down #you lose! self.playing = False print "Game over" text, textwidth = self.textHandler.make_text( "GAME OVER!", 16, 1, color="ff0000") engine = matrixHandler.MatrixEngine(text) for i in range(textwidth + 16): engine.shift_left() matrix = engine.get_matrix( cycle=True, cycle_size_col=textwidth + 16) sp.set_panel_memory_from_matrix(matrix) return if self.paneldisplay: for _ in range(5): sp.set_panel_color("300000") time.sleep(1) sp.panel_clear() time.sleep(1) else: self.board = self.oldboard else: self.board = self.oldboard else: self.board = self.oldboard else: self.board = self.oldboard
def checkforlost(self): self.oldboard = copy.deepcopy(self.board) self.shiftleft() self.leftcount() if self.board == self.oldboard: #cannot move left self.shiftright() self.rightcount() if self.board == self.oldboard: #cannot move right self.shiftup() self.upcount() if self.board == self.oldboard: #cannot move up self.shiftdown() self.downcount() if self.board == self.oldboard: #cannot move down #you lose! self.playing = False print "Game over" text, textwidth = self.textHandler.make_text("GAME OVER!", 16,1, color="ff0000") engine =matrixHandler.MatrixEngine(text) for i in range(textwidth+16): engine.shift_left() matrix = engine.get_matrix(cycle=True, cycle_size_col = textwidth+16) sp.set_panel_memory_from_matrix(matrix) return if self.paneldisplay: for _ in range(5): sp.set_panel_color("300000") time.sleep(1) sp.panel_clear() time.sleep(1) else: self.board = self.oldboard else: self.board = self.oldboard else: self.board = self.oldboard else: self.board = self.oldboard
def conf(self, wimote): global wi wi = wimote sp.panel_clear() sp.set_pixel_color(sp.matrix(0, 0), "ffffff") print "klikni vlevo dole" ld = self.getcord(wi) sp.panel_clear() print ld self.waitfornopen() time.sleep(1) sp.set_pixel_color(sp.matrix(0, 14), "ffffff") print "klikni vpravo dole" pd = self.getcord(wi) sp.panel_clear() print pd self.waitfornopen() time.sleep(1) sp.set_pixel_color(sp.matrix(8, 0), "ffffff") print "klikni vlevo nahore" lh = self.getcord(wi) sp.panel_clear() print lh self.waitfornopen() time.sleep(1) sp.panel_clear() sp.set_pixel_color(sp.matrix(8, 14), "ffffff") print "klikni pravo nahore" ph = self.getcord(wi) sp.panel_clear() print ph self.waitfornopen() self.pohl.setsrc(lh, ph, ld, pd) print "konfigurace dokoncena"
def conf(self, wimote): global wi wi = wimote sp.panel_clear() sp.set_pixel_color(sp.matrix(0,0),"ffffff") print "klikni vlevo dole" ld = self.getcord(wi) sp.panel_clear() print ld self.waitfornopen() time.sleep(1) sp.set_pixel_color(sp.matrix(0,14),"ffffff") print "klikni vpravo dole" pd = self.getcord(wi) sp.panel_clear() print pd self.waitfornopen() time.sleep(1) sp.set_pixel_color(sp.matrix(8,0),"ffffff") print "klikni vlevo nahore" lh = self.getcord(wi) sp.panel_clear() print lh self.waitfornopen() time.sleep(1) sp.panel_clear() sp.set_pixel_color(sp.matrix(8,14),"ffffff") print "klikni pravo nahore" ph = self.getcord(wi) sp.panel_clear() print ph self.waitfornopen() self.pohl.setsrc(lh, ph, ld, pd) print "konfigurace dokoncena"