コード例 #1
0
    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()
コード例 #2
0
ファイル: boardgamegui.py プロジェクト: Kekko01/My-Hitori
 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()
コード例 #3
0
 def update_buttons(self):
     g2d.fill_canvas((255, 255, 255))
     rows, cols = self._game.rows(), self._game.cols()
     for y in range(1, rows):
         g2d.draw_line((0, 0, 0), (0, y * H), (cols * W, y * H))
     for x in range(1, cols):
         g2d.draw_line((0, 0, 0), (x * W, 0), (x * W, rows * H))
     for y in range(rows):
         for x in range(cols):
             g2d.draw_text_centered(self._game.get_val(x, y), (0, 0, 0),
                                    (x * W + W//2, y * H + H//2), H//2)
     g2d.update_canvas()
     if self._game.finished():
         g2d.alert(self._game.message())
         g2d.exit()
         g2d.draw_text_centered(self._game.message(), (0, 0, 255),
                                (cols * W//2, rows * H//2), H//2)
コード例 #4
0
 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()
コード例 #5
0
ファイル: boardgame_g2d.py プロジェクト: tomamic/fondinfo
 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()
コード例 #6
0
    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()
コード例 #7
0
 def update_buttons(self):
     g2d.fill_canvas((255, 255, 255))
     rows, cols, flag = self._game.rows(), self._game.cols(), 0
     cellevuote = 0
     for y in range(1, rows):
         g2d.draw_line((0, 0, 0), (0, y * H), (cols * W, y * H))
     for x in range(1, cols + 1):
         g2d.draw_line((0, 0, 0), (x * W, 0), (x * W, rows * H))
     for y in range(rows):
         for x in range(cols):
             if (self._game.get_valpos(y, x) == 0):
                 g2d.draw_text_centered(" ", (0, 0, 0),
                                        (x * W + W // 2, y * H + H // 2),
                                        H // 2)
                 cellevuote = cellevuote + 1
             elif (self._game.get_valpos(y, x) == 2):
                 g2d.draw_image(flag1, (x * W + W // 8, y * H + H // 8))
                 #g2d.draw_text_centered("<|", (0, 0, 0),(x * W + W//2, y * H + H//2), H//2)
                 flag = flag + 1
             elif (self._game.get_val(y, x) == -1):
                 g2d.draw_image(bomb, (x * W + W // 8, y * H + H // 8))
             else:
                 g2d.draw_text_centered(str(self._game.get_val(y, x)),
                                        (0, 0, 0),
                                        (x * W + W // 2, y * H + H // 2),
                                        H // 2)
     g2d.draw_text_centered("MINE RIMANENTI DA SEGNALARE", (0, 0, 0),
                            ((x * W) + 160, H // 2), H // 2)
     g2d.draw_text_centered(str(self._game.mines() - flag), (0, 0, 0),
                            ((x * W) + 160, H), H // 2)
     g2d.draw_text_centered("CELLE VUOTE RIMANENTI", (0, 0, 0),
                            ((x * W) + 160, H * 2), H // 2)
     g2d.draw_text_centered(str((cellevuote + flag) - self._game.mines()),
                            (0, 0, 0), ((x * W) + 160, H * 3), H // 2)
     g2d.update_canvas()
     if (self._game.finished() == True):
         g2d.alert(self._game.message())
         g2d.exit()
         g2d.draw_text_centered(self._game.message(), (0, 0, 255),
                                (cols * W // 2, rows * H // 2), H // 2)
コード例 #8
0
    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()
コード例 #9
0
    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()
コード例 #10
0
ファイル: boardgamegui.py プロジェクト: Kekko01/My-Hitori
def gui_play(game: BoardGame):
    g2d.init_canvas((game.cols() * W, game.rows() * H))
    g2d.alert("Welcome to Hitori Game!")
    ui = BoardGameGui(game)
    g2d.main_loop(ui.tick)
コード例 #11
0
#!/usr/bin/env python3
'''
@author  Michele Tomaiuolo - http://www.ce.unipr.it/people/tomamic
@license This software is free - http://www.gnu.org/licenses/gpl.html
'''

import g2d

g2d.init_canvas((400, 400))  # width, height

radius = int(g2d.prompt("Radius? [50-99]"))

if 50 <= radius and radius <= 99:
    g2d.set_color((0, 0, 255))
    g2d.fill_circle((200, 200), radius)
else:
    g2d.alert("Out of range!")

g2d.set_color((255, 255, 0))
g2d.fill_circle((200, 200), 25)

g2d.main_loop()  # manage the window/canvas