def keydown(key): x, y = g2d.mouse_position() g2d.set_color((randrange(256), randrange(256), randrange(256))) if x <= 25 and y <= 25 and g2d.confirm("Exit?"): g2d.close_canvas() else: g2d.fill_circle((x, y), 25)
def update_buttons(self): global solved g2d.clear_canvas() g2d.set_color((0, 0, 0)) cols, rows = self._game.cols(), self._game.rows() for y in range(1, rows): g2d.draw_line((0, y * H), (cols * W, y * H)) for x in range(1, cols): g2d.draw_line((x * W, 0), (x * W, rows * H)) for y in range(rows): for x in range(cols): value = self._game.value_at(x, y) if '#' not in value: center = x * W + W // 2, y * H + H // 2 if '!' in value: g2d.set_color((0, 0, 200)) g2d.fill_circle(center, 14) g2d.set_color((255, 255, 255)) g2d.fill_circle(center, 12) g2d.set_color((0, 0, 0)) g2d.draw_text_centered(value[:-1], center, H // 2) else: g2d.fill_rect((x * W, y * H, W, H)) g2d.update_canvas() if self._game.finished() and not solved: g2d.alert(self._game.message()) g2d.close_canvas()
def update_buttons(self): g2d.clear_canvas() g2d.set_color((0, 0, 0)) cols, rows = self._game.cols(), self._game.rows() for y in range(1, rows): g2d.draw_line((0, y * H), (cols * W, y * H)) for x in range(1, cols): g2d.draw_line((x * W, 0), (x * W, rows * H)) for y in range(rows): for x in range(cols): g2d.set_color((0,0,0)) value = self._game.value_at(x, y) if self._game.checkblack(x,y): g2d.fill_rect((x * W, y * H, W, H)) center = x * W + W//2, y * H + H // 2 if self._game.checkcircle(x,y): g2d.fill_circle((center), W // 2) g2d.set_color((255,255,255)) g2d.fill_circle((center), W // 2 - 1) g2d.set_color((0,0,0)) g2d.draw_text_centered(value, center, H//2) g2d.update_canvas() if self._game.finished(): g2d.alert(self._game.message()) g2d.close_canvas()
def tick(): if g2d.key_pressed("LeftButton"): x, y = g2d.mouse_position() g2d.set_color((randrange(256), randrange(256), randrange(256))) if x <= 25 and y <= 25 and g2d.confirm("Exit?"): g2d.close_canvas() else: g2d.fill_circle((x, y), 25)
def update_buttons(self): g2d.clear_canvas() g2d.set_color((0, 0, 0)) rows, cols = self._game.rows(), self._game.cols() for y in range(1, rows): g2d.draw_line((0, y * H), (cols * W, y * H)) for x in range(1, cols): g2d.draw_line((x * W, 0), (x * W, rows * H)) for y in range(rows): for x in range(cols): value = self._game.value_at(x, y) center = x * W + W // 2, y * H + H // 2 g2d.draw_text_centered(value, center, H // 2) g2d.update_canvas() if self._game.finished(): g2d.alert(self._game.message()) g2d.close_canvas()
def update_buttons(self): g2d.clear_canvas() g2d.set_color((0, 0, 0)) rows, cols = self._game.rows(), self._game.cols() for y in range(1, rows): g2d.draw_line((0, y * H), (cols * W, y * H)) for x in range(1, cols): g2d.draw_line((x * W, 0), (x * W, rows * H)) for y in range(rows): for x in range(cols): value = self._game.value_at(x, y) center = x * W + W//2, y * H + H//2 g2d.draw_text_centered(value, center, H//2) g2d.update_canvas() if self._game.finished(): g2d.alert(self._game.message()) g2d.close_canvas()
def checkbuttons(): """ Controlla se i pulsanti sono premuti e agisce di conseguenza """ # --------Controllo interfaccia------- # for i, elem in enumerate(GUI._elements): if g2d.key_released( 'LeftButton' ) and elem._selectable and elem._selected: # Prosegue solo se il pulsante è selezionabile e selezionato if GUI._state == 0: # Menu principale if i == 1: # Pulsante Play GUI._state = 1 elif i == 2: # Pulsante Quit g2d.close_canvas() break # Non serve controllare tutto elif GUI._state == 1: # Menu selezione difficoltà if 1 <= i < len(GUI._elements) - 1: ActualGame._difficulty = int( elem._text ) # Imposta la difficoltà in base al numero selezionato e inizia la partita GUI._state = 2 else: # Pulsante Back GUI._state = 0 break # Non serve controllare tutto elif GUI._state == 2: # Partita vera e propria if i == len(GUI._elements) - 2: # Pulsante Check GUI._substate = ActualGame.check(True) elif i == len(GUI._elements) - 1: hint() # --------Controllo caselle------- # if GUI._gamerunning: # Effettua il controllo solo se in partita for box in ActualGame._boxes: if g2d.key_released('LeftButton') and box._selected: GUI._clicks += 1 # Aumenta il numero di click if ActualGame._statematrix[box._row][ box. _column] == 2: # Se cerchiato, ritorna allo stato normale ActualGame._statematrix[box._row][box._column] = 0 else: ActualGame._statematrix[box._row][ box. _column] += 1 # Altrimenti passa a quello successivo
def tick(self): self.handle_keyboard() arena = self._game.arena() arena.move_all() # Game logic g2d.clear_canvas() for a in arena.actors(): if a.symbol() != (0, 0, 0, 0): g2d.draw_image_clip(self._sprites, a.symbol(), a.position()) else: g2d.fill_rect(a.position()) lives = "Lives: " + str(self._game.hero().lives()) toplay = "Time: " + str(self._game.remaining_time()) g2d.draw_text(lives + " " + toplay, (0, 0), 24) if self._game.game_over(): g2d.alert("Game over") g2d.close_canvas() elif self._game.game_won(): g2d.alert("Game won") g2d.close_canvas()
def level_2_tick(self): global hero_lives if self._game.game_won(): g2d.alert("Game won") g2d.close_canvas() elif self._game.in_game(): self._game.update_obstacles() if self._hero[0].get_x( ) < ROVER_X_TARGET and self._is_game_starting: for hero in self._hero: hero.go_right() hero.move() else: self._game.add_second_to_score() self._is_game_starting = False self._game.generate_bomber() self._game.bomber_shoot() self._game.generate_cannon() self._game.cannon_shoot() self._game.generate_alien() self._game.generate_random_bullet_from_aliens() self.handle_keyboard() self._arena.move_all() self.draw() else: hero_lives -= 1 if self._game.game_over(): self.write_score() g2d.alert("Game over") #g2d.draw_image_clip(self.game_over, 0, 0, 3069, 1470, 0, 0, 1280, 720) g2d.close_canvas() else: self._arena.add_to_score(-20) self._game.reset(hero_lives, self._settings, self._arena.get_score()) self.reset()
def level_1_tick(self): global hero_lives if self._game.game_won(): self._game.reset(2, self._settings) g2d.alert("Level won") self._settings['level'] = 'level_2' self.reset() elif self._game.in_game(): self._game.update_obstacles() self._game.generate_random_obstacles() if self._hero[0].get_x( ) < ROVER_X_TARGET and self._is_game_starting: for hero in self._hero: hero.go_right() hero.move() else: self._game.add_second_to_score() self._is_game_starting = False self._game.generate_alien() self._game.generate_random_bullet_from_aliens() self.handle_keyboard() self._arena.move_all() # Game logic self.draw() else: hero_lives -= 1 if self._game.game_over(): g2d.alert("Game over") self.write_score() g2d.close_canvas() else: self._arena.add_to_score(-20) self._game.reset(hero_lives, self._settings, self._arena.get_score()) self.reset()