Ejemplo n.º 1
0
    def __init__(self,main_game):
        self.main_game = main_game
        self.panel = main_game.main_window.get_right()
        self.center_x = self.panel.get_width()/2 - 5
        self.center_y = self.panel.get_height()/2 - 40

        
        ym = self.center_y
        xm = self.center_x

        
        #预留40像素放其他点组件
        self.height = 40
        self.color =  self.panel.get_bgcolor() #(200, 200, 200)
        self.items = []

        # 
        # self.gif_button = Button(x=xm//2, y=self.height , width= xm, height= self.height ,background_color=self.color, text='GIF')
        # self.add(self.gif_button)

        ym = ym + self.height
        for i in range(3):
            tmp_button1 = Button(x=2, y=ym + self.height * i, width= xm, height= self.height ,background_color=self.color)
            self.add(tmp_button1)
            tmp_button2 = Button(x=xm+3, y=ym + self.height * i, width= xm, height=self.height,background_color=self.color)
            self.add(tmp_button2)
            self.items.append((tmp_button1, tmp_button2))
            # ym = ym +height
        
        self.set_item_label(0,'High S')
        self.set_item_label(2,'score')
Ejemplo n.º 2
0
    def __init__(self):
        self.current_game = None
        self.main_window = MainWindow()

        main_sweeper = MainSweeper(self)
        main_russia = MainRussiaBox(self)
        main_sudoku = MainSudoku(self)
        self.games = [['sweeper', main_sweeper], ['RussiaBox', main_russia],
                      ['sudoku', main_sudoku]]
        self.set_game(2)

        color = (200, 200, 200)
        self.exit_button = Button(text="exit", background_color=color)
        self.sweep_button = ChoiceGameButton(mainwindow=self,
                                             width=80,
                                             text=self.games[0][0],
                                             value=0)
        self.russiabox_button = ChoiceGameButton(mainwindow=self,
                                                 width=100,
                                                 x=82,
                                                 text=self.games[1][0],
                                                 value=1)
        self.sudoku_button = ChoiceGameButton(mainwindow=self,
                                              width=100,
                                              x=182,
                                              text=self.games[2][0],
                                              value=2)
        self.main_window.register_mouse_down(self.russiabox_button)
        self.main_window.register_mouse_down(self.sweep_button)
        self.main_window.register_mouse_down(self.sudoku_button)

        self.main_window.add_top(self.exit_button)
        self.exit_button.set_right()
        self.main_window.add_top(self.sweep_button)
        self.main_window.add_top(self.russiabox_button)
        self.main_window.add_top(self.sudoku_button)

        # genereate gif
        self.gif_button = Button(x=20,
                                 y=20,
                                 width=50,
                                 height=20,
                                 background_color=color,
                                 text='GIF')
        self.gif_button.main_window = self
        self.gif_button.response_mouse_down = MethodType(
            gif_button_mouse_down, self.gif_button)
        self.main_window.register_mouse_down(self.gif_button)
        # self.add(self.gif_button)
        self.main_window.get_right().add(self.gif_button)

        self.main_window.register_sys_exit(self)
        self.main_window.show_window()
Ejemplo n.º 3
0
    def __init__(self,minesweeper):
        self.minesweeper = minesweeper
        panel = minesweeper.main_window.get_right()
        ym = panel.get_height()/2 - 40
        xm = panel.get_width()/2 - 5
        height = 40
        color = (200, 200, 200)


        # display level
        # panel.add(Button(x=2, y=ym, width= xm, height= height, text="level",background_color=color))
        # self.level_label = Button(x=xm+3, y=ym, width= xm, height= height,background_color=color)
        self.level_label = OptionButton([1, 2, 3],x=2, y=ym-30, width= 2*xm-3, height= height+30,background_color=color)
        panel.add(self.level_label)

        ym = ym +height
        # remain mine num
        label = SweeperGrid(x=xm/2 - height/2, y=ym, width= height, height= height ,background_color=color)
        label.change_grid_content('mine')
        panel.add(label)
        self.mine_num_label = Button(x=xm+3, y=ym, width= xm, height=height,background_color=color)
        panel.add(self.mine_num_label)
        

        # display high score
        ym = ym +height
        panel.add(Button(x=2, y=ym, width= xm, height= height, text="High",background_color=color))
        self.high_label = Button(x=xm+3, y=ym, width= xm, height= height,background_color=color)
        panel.add(self.high_label)

        # display current score
        ym = ym +height
        panel.add(Button(x=2, y=ym, width= xm, height= height, text="Score"))
        self.curr_label = Button(x=xm+3, y=ym, width= xm, height= height)
        panel.add(self.curr_label)
Ejemplo n.º 4
0
    def __init__(self,game,text='Play Game!',width=150):
        height = 60
        super(GameResult, self).__init__(width=width,height=height*2)
        self.status_alpha = 0
        self.status_step = 1
        self.status_msg = ['congratulations!','You are failed!']
        self.button_text = ['Play again!', 'Play!']
        self.add(Button(x=0, y=0, width=width, height=height, background_color=(255,255,0)))
        self.elements[0].set_text_size(20)
        self.add(Button(x=0, y=height, text=self.button_text[1], width=width, height=height, background_color=(100,100,100)))
        self.elements[1].set_text_size(25)

        # self.elements[0].set_visible(False)
        self.game = game
        self.reset_result()
Ejemplo n.º 5
0
class MainGame:
    def __init__(self):
        settings = Settings()

        self.main_window = MainWindow()
        self.exit_button = Button(text="exit",
                                  background_color=(200, 200, 200))
        self.sweep_button = Button(width=70,
                                   text="sweep",
                                   background_color=(200, 200, 200))
        self.main_window.add_top(self.exit_button)
        self.exit_button.set_right()
        self.main_window.add_top(self.sweep_button)

        self.main_sweeper = MainSweeper(self)
        self.current_game = self.main_sweeper

        self.play_button = PlayGameButton(self)
        self.main_window.add_main(self.play_button)
        self.main_window.register_mouse_down(self.play_button)
        self.main_window.register_sys_exit(self)

    def start(self):
        self.current_game.start_game()

    def get_game_panel(self):
        # print("test:", self.main_window.get_main())
        return self.main_window.get_main()

    def stop_game(self):
        self.play_button.set_visible(True)
        self.play_button.active = True
        self.play_button.set_text("play again!")

    def sys_exit(self):
        print("sys exit")
        self.stop_game()
        self.main_sweeper.stop_game()

    def start_game(self):

        while True:
            self.main_window.show_window()
            self.main_window.start_listen_event()
Ejemplo n.º 6
0
    def __init__(self):
        settings = Settings()

        self.main_window = MainWindow()
        self.exit_button = Button(text="exit",
                                  background_color=(200, 200, 200))
        self.sweep_button = Button(width=70,
                                   text="sweep",
                                   background_color=(200, 200, 200))
        self.main_window.add_top(self.exit_button)
        self.exit_button.set_right()
        self.main_window.add_top(self.sweep_button)

        self.main_sweeper = MainSweeper(self)
        self.current_game = self.main_sweeper

        self.play_button = PlayGameButton(self)
        self.main_window.add_main(self.play_button)
        self.main_window.register_mouse_down(self.play_button)
        self.main_window.register_sys_exit(self)
Ejemplo n.º 7
0
class MainGame:
    def __init__(self):
        self.current_game = None
        self.main_window = MainWindow()

        main_sweeper = MainSweeper(self)
        main_russia = MainRussiaBox(self)
        main_sudoku = MainSudoku(self)
        self.games = [['sweeper', main_sweeper], ['RussiaBox', main_russia],
                      ['sudoku', main_sudoku]]
        self.set_game(2)

        color = (200, 200, 200)
        self.exit_button = Button(text="exit", background_color=color)
        self.sweep_button = ChoiceGameButton(mainwindow=self,
                                             width=80,
                                             text=self.games[0][0],
                                             value=0)
        self.russiabox_button = ChoiceGameButton(mainwindow=self,
                                                 width=100,
                                                 x=82,
                                                 text=self.games[1][0],
                                                 value=1)
        self.sudoku_button = ChoiceGameButton(mainwindow=self,
                                              width=100,
                                              x=182,
                                              text=self.games[2][0],
                                              value=2)
        self.main_window.register_mouse_down(self.russiabox_button)
        self.main_window.register_mouse_down(self.sweep_button)
        self.main_window.register_mouse_down(self.sudoku_button)

        self.main_window.add_top(self.exit_button)
        self.exit_button.set_right()
        self.main_window.add_top(self.sweep_button)
        self.main_window.add_top(self.russiabox_button)
        self.main_window.add_top(self.sudoku_button)

        # genereate gif
        self.gif_button = Button(x=20,
                                 y=20,
                                 width=50,
                                 height=20,
                                 background_color=color,
                                 text='GIF')
        self.gif_button.main_window = self
        self.gif_button.response_mouse_down = MethodType(
            gif_button_mouse_down, self.gif_button)
        self.main_window.register_mouse_down(self.gif_button)
        # self.add(self.gif_button)
        self.main_window.get_right().add(self.gif_button)

        self.main_window.register_sys_exit(self)
        self.main_window.show_window()

        # 0 represent sweeper
    def set_gif_active(self, active):
        self.main_window.set_gif_active(active)

    def get_gif_active(self):
        return self.main_window.get_gif_active()

    def save_gif(self):
        print('save gif mygame')
        self.main_window.save_gif(self.current_game.game_name)

    def refresh_rate(self):
        self.main_window.refresh_rate = self.current_game.get_refresh_rate()

    def start(self):
        self.current_game.start_game()

    def set_game(self, game):
        if self.current_game is not None:
            # self.stop_game()
            self.main_window.refresh()
            self.current_game.reset_game()
            self.current_game.set_active(False)

        self.current_game = self.games[game][1]
        print("set_game:" + str(game))
        self.current_game.set_active(True)
        # self.game_result.reset()

    def get_game_panel(self):
        # print("test:", self.main_window.get_main())
        return self.main_window.get_main()


# success
#failed

    def sys_exit(self):
        print("sys exit")
        # self.stop_game()
        self.current_game.stop_game(0)
        if self.main_window.get_gif_active():
            self.main_window.save_gif(self.current_game.game_name)
Ejemplo n.º 8
0
class ScoreBoard:
    def __init__(self,minesweeper):
        self.minesweeper = minesweeper
        panel = minesweeper.main_window.get_right()
        ym = panel.get_height()/2 - 40
        xm = panel.get_width()/2 - 5
        height = 40
        color = (200, 200, 200)


        # display level
        # panel.add(Button(x=2, y=ym, width= xm, height= height, text="level",background_color=color))
        # self.level_label = Button(x=xm+3, y=ym, width= xm, height= height,background_color=color)
        self.level_label = OptionButton([1, 2, 3],x=2, y=ym-30, width= 2*xm-3, height= height+30,background_color=color)
        panel.add(self.level_label)

        ym = ym +height
        # remain mine num
        label = SweeperGrid(x=xm/2 - height/2, y=ym, width= height, height= height ,background_color=color)
        label.change_grid_content('mine')
        panel.add(label)
        self.mine_num_label = Button(x=xm+3, y=ym, width= xm, height=height,background_color=color)
        panel.add(self.mine_num_label)
        

        # display high score
        ym = ym +height
        panel.add(Button(x=2, y=ym, width= xm, height= height, text="High",background_color=color))
        self.high_label = Button(x=xm+3, y=ym, width= xm, height= height,background_color=color)
        panel.add(self.high_label)

        # display current score
        ym = ym +height
        panel.add(Button(x=2, y=ym, width= xm, height= height, text="Score"))
        self.curr_label = Button(x=xm+3, y=ym, width= xm, height= height)
        panel.add(self.curr_label)
    
    def set_curr_label(self, curr):
        
        self.curr_label.set_text(curr)

    def set_high_label(self, high):
        self.high_label.set_text(high)

    # def set_level(self, level):
    #     self.level_label.set_text(level)
    def get_level(self):
        return self.level_label.current_value

    def set_mine_num_label(self, num):
        self.mine_num_label.set_text(num)

    def  response_mouse_down(self,pos , mouse_index = 0):
        print("level label response_mouse_down")
        result = self.level_label.response_mouse_down(pos, mouse_index)
        if result :
            self.minesweeper.reset_game()
        return result
    
    def can_response(self, pos):
        print("level label can response")
        return self.level_label.can_response(pos)