示例#1
0
class MainApp(App):
    def build(self):

        #sound = SoundLoader.load('muzlome_Metallica_-_Sad_But_True_47954412.mp3')
        #sound.play()

        self.create_start_screen()
        self.create_game_screen()

        self.main_layout = FloatLayout()
        self.main_layout.add_widget(self.start_screen)
        return self.main_layout

    def create_start_screen(self):
        self.start_screen = FloatLayout(size_hint=(1, 1),
                                        pos_hint={
                                            'center_x': 0.5,
                                            'center_y': 0.5
                                        })

        background_image = Image(source=BACKGROUND_IMAGE,
                                 size_hint=[1, 1],
                                 pos_hint={
                                     'center_x': 0.5,
                                     'center_y': 0.5
                                 },
                                 allow_stretch=True,
                                 keep_ratio=False)
        background_belki = Image(source=BELKI,
                                 size_hint=[1, 1],
                                 pos_hint={
                                     'center_x': 0.5,
                                     'center_y': 0.5
                                 },
                                 allow_stretch=True,
                                 keep_ratio=False)

        buttons = BoxLayout(orientation='vertical',
                            spacing=10,
                            size_hint=(0.3, 0.4),
                            pos_hint={
                                'center_x': 0.7,
                                'center_y': 0.4
                            })

        start_game_button = Button(text='Start game',
                                   on_press=self.reset_game_mode,
                                   background_normal='',
                                   background_color=BUTTON_COLOR,
                                   color=[0, 0, 0, 1])

        settings_button = Button(
            text='Settings',
            #on_press=None,
            background_normal='',
            background_color=BUTTON_COLOR,
            color=[0, 0, 0, 1])

        buttons.add_widget(start_game_button)
        buttons.add_widget(settings_button)

        self.start_screen.add_widget(background_image)
        self.start_screen.add_widget(buttons)

    def create_game_screen(self):
        self.board = BoardWidget(FIELD_WIDTH, FIELD_HEIGHT)

        exit_button = Button(text='Quit',
                             on_press=self.leave,
                             size_hint=[0.25, 0.1],
                             pos_hint={
                                 'center_x': 1.30,
                                 'center_y': 0.66
                             },
                             background_color=BUTTON_COLOR,
                             background_normal='')
        restart_button = Button(text='Restart',
                                on_press=self.reset_game_mode,
                                size_hint=[0.25, 0.1],
                                pos_hint={
                                    'center_x': 1.30,
                                    'center_y': 0.90
                                },
                                background_color=BUTTON_COLOR,
                                background_normal='')
        back_to_menu_button = Button(
            text='Main menu',  #on_press=self.back_to_main_menu,
            size_hint=[0.25, 0.1],
            pos_hint={
                'center_x': 1.30,
                'center_y': 0.78
            },
            background_color=BUTTON_COLOR,
            background_normal='')

        make_move_button = Button(text='Start game',
                                  on_press=self.start_game,
                                  size_hint=[0.25, 0.1],
                                  pos_hint={
                                      'center_x': 1.30,
                                      'center_y': 0.4
                                  },
                                  background_color=BUTTON_COLOR,
                                  background_normal='')

        self.game_screen = FloatLayout(size_hint=[0.5, 1],
                                       pos_hint={
                                           'center_x': 0.5,
                                           'center_y': 0.5
                                       })
        self.game_screen.add_widget(self.board)
        self.game_screen.add_widget(exit_button)
        self.game_screen.add_widget(restart_button)
        self.game_screen.add_widget(back_to_menu_button)
        self.game_screen.add_widget(make_move_button)

    def reset_game_mode(self, _):
        self.game = Game([(FirstStupidAlgorithm(), [2, 2])])

        self.main_layout.remove_widget(self.main_layout.children[0])
        self.main_layout.add_widget(self.game_screen)

    def start_game(self, _):  # FIXME not class method
        Clock.schedule_interval(self.make_move, 0.1)

    def make_move(self, _):
        self.game.move()
        self.board.refresh(self.game.board)
        return not self.game.is_game_over()

    def set_start_mode(self, _):
        pass

    def leave(self, button):
        exit()
示例#2
0
def main():
    game = Game([(FirstStupidAlgorithm(), [6, 8])])
    print(game.board)
    while game.is_game_over() == False:
        game.move()
        print(game.board)