Beispiel #1
0
    def test_one_winner(self):
        controller1 = fakes.FakeMove()
        controller2 = fakes.FakeMove()

        loop = asyncio.get_event_loop()
        game = ffa.FreeForAll([controller1, controller2], piaudio.DummyMusic())
        game.set_rainbow_duration_for_testing(0.1)
        game_task = asyncio.ensure_future(game.run())

        loop.run_until_complete(asyncio.sleep(1))

        self.assertFalse(game_task.done())
        self.assertFalse(game_task.cancelled())

        controller1.accel = (100, 100, 100)

        # Shouldn't throw timeout.
        loop.run_until_complete(asyncio.wait_for(game_task, timeout=3))
        self.assertTrue(game.has_winner_())
Beispiel #2
0
    def test_two_outs(self):
        """Tests that we don't lose all the players if they all simultaenously register high accel."""
        controller1 = fakes.FakeMove()
        controller2 = fakes.FakeMove()

        loop = asyncio.get_event_loop()
        game = ffa.FreeForAll([controller1, controller2], piaudio.DummyMusic())
        game.set_rainbow_duration_for_testing(0.1)
        game_task = asyncio.ensure_future(game.run())

        loop.run_until_complete(asyncio.sleep(0.01))

        self.assertFalse(game_task.done())
        self.assertFalse(game_task.cancelled())

        controller1.accel = (100, 100, 100)
        controller2.accel = (100, 100, 100)

        # Shouldn't throw timeout.
        loop.run_until_complete(asyncio.wait_for(game_task, timeout=3))
        self.assertTrue(game.has_winner_())
Beispiel #3
0
    def start_game(self, random_mode=False):
        self.enable_bt_scanning(False)
        self.exclude_out_moves()
        self.stop_tracking_moves()
        time.sleep(1)
        self.teams = {
            serial: self.move_opts[serial][Opts.team.value]
            for serial in self.tracked_moves.keys()
            if self.out_moves[serial] == Alive.on.value
        }
        game_moves = [
            move.get_serial() for move in self.moves
            if self.out_moves[move.get_serial()] == Alive.on.value
        ]
        try:
            self.menu_music.stop_audio()
        except:
            pass

        if len(game_moves
               ) < self.game_mode.minimum_players and self.ns.settings[
                   'enforce_minimum']:
            Audio('audio/Menu/notenoughplayers.wav').start_effect()
            self.tracked_moves = {}
            return
        self.update_status('starting')

        if random_mode:
            good_random_modes = [
                game for game in common.Games
                if game.name in self.ns.settings['random_modes']
            ]
            good_random_modes = [
                common.Games[game] for game in self.ns.settings['random_modes']
            ]
            if self.ns.settings['enforce_minimum']:
                good_random_modes = [
                    game for game in good_random_modes
                    if game.minimum_players <= len(game_moves)
                ]
            if len(good_random_modes) == 0:
                selected_game = common.Games.JoustFFA  #force Joust FFA
            elif len(good_random_modes) == 1:
                selected_game = good_random_modes[0]
            else:
                if len(self.rand_game_list) >= len(good_random_modes):
                    #empty rand game list, append old game, to not play it twice
                    self.rand_game_list = [self.old_game_mode]

                selected_game = random.choice(good_random_modes)
                while selected_game in self.rand_game_list:
                    selected_game = random.choice(good_random_modes)

                self.old_game_mode = selected_game
                self.rand_game_list.append(selected_game)

            self.game_mode = selected_game

        if self.ns.settings['play_instructions'] and self.ns.settings[
                'play_audio']:
            self.play_random_instructions()

        if self.game_mode == common.Games.Zombies:
            zombie.Zombie(game_moves, self.command_queue, self.ns,
                          self.zombie_music)
            self.tracked_moves = {}
        elif self.game_mode == common.Games.Commander:
            commander.Commander(game_moves, self.command_queue, self.ns,
                                self.commander_music)
            self.tracked_moves = {}
        elif self.game_mode == common.Games.Ninja:
            speed_bomb.Bomb(game_moves, self.command_queue, self.ns,
                            self.commander_music)
            self.tracked_moves = {}
        elif self.game_mode == common.Games.Swapper:
            swapper.Swapper(game_moves, self.command_queue, self.ns,
                            self.joust_music)
            self.tracked_moves = {}
        elif self.game_mode == common.Games.FightClub:
            if random.randint(0, 1) == 1:
                fight_music = self.commander_music
            else:
                fight_music = self.joust_music
            fight_club.Fight_club(game_moves, self.command_queue, self.ns,
                                  fight_music)
            self.tracked_moves = {}
        elif self.game_mode == common.Games.Tournament:
            tournament.Tournament(game_moves, self.command_queue, self.ns,
                                  self.joust_music)
            self.tracked_moves = {}
        else:
            if self.game_mode == common.Games.JoustFFA and self.experimental:
                print("Playing EXPERIMENTAL FFA Mode.")
                moves = [
                    common.get_move(serial, num)
                    for num, serial in enumerate(game_moves)
                ]
                game = ffa.FreeForAll(moves, self.joust_music)
                game.run_loop()
            else:
                #may need to put in moves that have selected to not be in the game
                joust.Joust(game_moves, self.command_queue, self.ns,
                            self.joust_music, self.teams, self.game_mode)
            self.tracked_moves = {}
        if random_mode:
            self.game_mode = common.Games.Random
            if self.ns.settings['play_instructions']:
                if self.ns.settings['play_audio']:
                    Audio('audio/Menu/tradeoff2.wav').start_effect_and_wait()
        self.play_menu_music = True
        #reset music
        self.choose_new_music()
        #turn off admin mode so someone can't accidentally press a button
        self.admin_move = None
        self.random_added = []
Beispiel #4
0
    def start_game(self, random_mode=False):
        self.enable_bt_scanning(False)
        self.exclude_out_moves()
        time.sleep(1)
        self.teams = {
            serial: self.move_opts[serial][Opts.team.value]
            for serial in self.tracked_moves.keys()
            if self.out_moves[serial] == Alive.on.value
        }
        game_moves = [
            move.get_serial() for move in self.moves
            if self.out_moves[move.get_serial()] == Alive.on.value
        ]
        try:
            self.menu_music.stop_audio()
        except:
            pass

        if len(game_moves
               ) < self.game_mode.minimum_players and self.ns.settings[
                   'enforce_minimum']:
            Audio('audio/Menu/vox/' + self.ns.settings['menu_voice'] +
                  '/notenoughplayers.wav').start_effect()
            self.reset_controller_game_state()
            return
        self.menu.value = 0
        self.restart.value = 1
        self.update_status('starting')

        self.sensitivity = self.ns.settings['sensitivity']
        self.controller_sensitivity[0] = common.SLOW_MAX[self.sensitivity]
        self.controller_sensitivity[1] = common.SLOW_WARNING[self.sensitivity]
        self.controller_sensitivity[2] = common.FAST_MAX[self.sensitivity]
        self.controller_sensitivity[3] = common.FAST_WARNING[self.sensitivity]

        self.controller_sensitivity[4] = common.WERE_SLOW_MAX[self.sensitivity]
        self.controller_sensitivity[5] = common.WERE_SLOW_WARNING[
            self.sensitivity]
        self.controller_sensitivity[6] = common.WERE_FAST_MAX[self.sensitivity]
        self.controller_sensitivity[7] = common.WERE_FAST_WARNING[
            self.sensitivity]

        self.controller_sensitivity[8] = common.ZOMBIE_MAX[self.sensitivity]
        self.controller_sensitivity[9] = common.ZOMBIE_WARNING[
            self.sensitivity]

        if random_mode:
            good_random_modes = [
                game for game in common.Games
                if game.name in self.ns.settings['random_modes']
            ]
            good_random_modes = [
                common.Games[game] for game in self.ns.settings['random_modes']
            ]
            if self.ns.settings['enforce_minimum']:
                good_random_modes = [
                    game for game in good_random_modes
                    if game.minimum_players <= len(game_moves)
                ]
            if len(good_random_modes) == 0:
                selected_game = common.Games.JoustFFA  #force Joust FFA
            elif len(good_random_modes) == 1:
                selected_game = good_random_modes[0]
            else:
                if len(self.rand_game_list) >= len(good_random_modes):
                    #empty rand game list, append old game, to not play it twice
                    self.rand_game_list = [self.old_game_mode]

                selected_game = random.choice(good_random_modes)
                while selected_game in self.rand_game_list:
                    selected_game = random.choice(good_random_modes)

                self.old_game_mode = selected_game
                self.rand_game_list.append(selected_game)

            self.game_mode = selected_game
        self.controller_game_mode.value = self.game_mode.value

        if self.ns.settings['play_instructions'] and self.ns.settings[
                'play_audio']:
            self.play_random_instructions()

        if self.game_mode == common.Games.Zombies:
            zombie.Zombie(game_moves, self.command_queue, self.ns,
                          self.zombie_music, self.restart, self.zombie_opts)
        elif self.game_mode == common.Games.Commander:
            commander.Commander(game_moves, self.command_queue, self.ns, self.commander_music, self.dead_moves,  self.commander_intro, self.commander_move_opts, \
                                self.commander_powers, self.commander_overdrive, self.music_speed, self.force_color, self.restart, self.controller_teams)
        elif self.game_mode == common.Games.Ninja:
            speed_bomb.Bomb(game_moves, self.command_queue, self.ns,
                            self.commander_music, self.bomb_color,
                            self.game_start, self.five_controller_opts,
                            self.dead_moves, self.force_color,
                            self.false_colors, self.was_faked, self.rumble,
                            self.music_speed, self.restart)
        elif self.game_mode == common.Games.Swapper:
            swapper.Swapper(game_moves, self.command_queue, self.ns, self.joust_music, \
                            self.swapper_team_colors, self.dead_moves, self.music_speed, self.force_color, self.five_controller_opts, self.controller_teams, self.restart)
        elif self.game_mode == common.Games.FightClub:
            if random.randint(0, 1) == 1:
                fight_music = self.commander_music
            else:
                fight_music = self.joust_music
            fight_club.Fight_club(game_moves, self.command_queue, self.ns,
                                  fight_music, self.show_team_colors,
                                  self.music_speed, self.dead_moves,
                                  self.force_color, self.invincible_moves,
                                  self.fight_club_colors, self.restart)
        elif self.game_mode == common.Games.Tournament:
            tournament.Tournament(game_moves, self.command_queue, self.ns,
                                  self.joust_music, self.show_team_colors,
                                  self.music_speed, self.controller_teams,
                                  self.dead_moves, self.force_color,
                                  self.invincible_moves, self.num_teams,
                                  self.restart)
        else:
            if self.game_mode == common.Games.JoustFFA and self.experimental:
                print("Playing EXPERIMENTAL FFA Mode.")
                moves = [
                    common.get_move(serial, num)
                    for num, serial in enumerate(game_moves)
                ]
                game = ffa.FreeForAll(moves, self.joust_music)
                game.run_loop()
            else:
                #may need to put in moves that have selected to not be in the game
                joust.Joust(game_moves, self.command_queue, self.ns,
                            self.joust_music, self.teams, self.game_mode,
                            self.controller_teams, self.controller_colors,
                            self.dead_moves, self.force_color,
                            self.music_speed, self.werewolf_reveal,
                            self.show_team_colors, self.red_on_kill,
                            self.restart)
        if random_mode:
            self.game_mode = common.Games.Random
            if self.ns.settings['play_instructions']:
                if self.ns.settings['play_audio']:
                    Audio('audio/Menu/vox/' + self.ns.settings['menu_voice'] +
                          '/tradeoff2.wav').start_effect_and_wait()
        self.play_menu_music = True
        #reset music
        self.choose_new_music()
        #turn off admin mode so someone can't accidentally press a button
        self.admin_move = None
        self.random_added = []
        self.reset_controller_game_state()
        self.menu.value = 1
        self.restart.value = 0
        self.reset_controller_game_state()