Example #1
0
    def get(self, name):
        img = self.images[name + self._postfix]
        if self.need_scale and GameStatus().use_Droid4X:
            x, y, z = img.shape
            t = GameStatus().y / self.delta_y
            img = cv2.resize(img, (int(y * t), int(x * t)), fx=t, fy=t)

        return img
Example #2
0
class SelectTeam:

    def __init__(self):
        self.player1 = None
        self.player2 = None
        self.game_status = GameStatus()

    # The argument passed to HumanPlayer() and SimpleComputerPlayer says who will start (1=start, 2=chooses second)
    # The player who starts is set to be: to_move. The player who is not starting is et to be: other
    def select_starter(self):
        while self.game_status.to_move is None:
            answer = input("Do you want to start? (Y/N)")
            if answer == "Y" or answer == "y":
                self.player1 = HumanPlayer(1)
                self.player2 = SimpleComputerPlayer(2)
                self.game_status.to_move = self.player1
                self.game_status.other = self.player2

            if answer == "N" or answer == "n":
                self.player1 = HumanPlayer(2)
                self.player2 = SimpleComputerPlayer(1)
                self.game_status.to_move = self.player2
                self.game_status.other = self.player1

    def select_move(self):
        self.game_status.to_move.make_move(self.game_status)

    def finished(self):
        return self.game_status.finished()

    def print_result(self):
        if self.player1.score() > self.player2.score():
            print(self.player1.name + " WON! ")
        elif self.player1.score() < self.player2.score():
            print(self.player2.name + " WON! ")
        else:
            print("DRAW")

        print(self.player1.name, " chose: ", self.player1.chosen_to_string())
        print("Score: ", self.player1.score())

        print(self.player2.name, " chose: ")
        print(self.player2.chosen_to_string())
        print("Score: ", self.player2.score())

    def print_status(self):
        if self.game_status.to_move == self.player1:
            print("To move: " + self.game_status.to_move.name)
            print("Selected: " + self.game_status.to_move.chosen_to_string())
            print("Score: ", self.game_status.to_move.score())
            print("")

            print("Other: " + self.game_status.other.name)
            print("Selected: " + self.game_status.other.chosen_to_string())
            print("Score: ", self.game_status.other.score())
            print("")
            print(self.game_status.remaining_to_string())
Example #3
0
class SelectTeam:

    def __init__(self):
        self.player1 = None
        self.player2 = None
        self.game_status = GameStatus()

    def select_starter(self):
        while self.game_status.to_move is None:
            answer = input("Do you want to start? (Y/N)")
            if answer == "Y" or answer == "y":
                self.player1 = HumanPlayer(1)
                self.player2 = SimpleComputerPlayer(2)
                self.game_status.to_move = self.player1
                self.game_status.other = self.player2

            if answer == "N" or answer == "n":
                self.player1 = HumanPlayer(2)
                self.player2 = SimpleComputerPlayer(1)
                self.game_status.to_move = self.player2
                self.game_status.other = self.other

    def select_move(self):
        self.game_status.to_move.make_move(self.game_status)

    def finished(self):
        return self.game_status.finished()

    def print_result(self):
        if self.player1.score() > self.player2.score():
            print(self.player1.name + " WON! ")
        elif self.player1.score() < self.player2.score():
            print(self.player2.name + " WON! ")
        else:
            print("DRAW")

        print(self.player1.name, " chose: ", self.player1.chosen_to_string())
        print("Score: ", self.player1.score())

        print(self.player2.name, " chose: ")
        print(self.player2.chosen_to_string())
        print("Score: ", self.player2.score())

    def print_status(self):
        if self.game_status.to_move == self.player1:
            print("To move: " + self.game_status.to_move.name)
            print("Selected: " + self.game_status.to_move.chosen_to_string())
            print("Score: ", self.game_status.to_move.score())
            print("")

            print("To move: " + self.game_status.other.name)
            print("Selected: " + self.game_status.other.chosen_to_string())
            print("Score: ", self.game_status.other.score())
            print("")
            print(self.game_status.remaining_to_string())
Example #4
0
    def continue_loop(self):
        if self.worker is not None and not self.worker.stopped():
            return

        self.worker = Worker()
        GameStatus().game_stage = GameStage.Fighting
        self.worker.start()
Example #5
0
    def start_loop(self):
        if self.worker is not None and not self.worker.stopped():
            return

        self.worker = Worker()
        GameStatus().game_stage = GameStage.BeforeFight
        self.worker.start()
Example #6
0
    def yaoguaifaxian(self):
        if self.worker is not None and not self.worker.stopped():
            return

        self.worker = Worker(self.imagesPath)
        GameStatus().game_stage = GameStage.Yaoguaifaxian
        self.worker.start()
Example #7
0
    def __init__(self):
        super().__init__()
        self.worker = None
        self.statusBar().showMessage('ready')
        self.resize(250, 150)
        self.move(300, 300)
        self.setWindowTitle('刷起来')
        self.setWindowIcon(QIcon('icon.ico'))
        self.imagesPath = "./images/tp14/"
        self.toolBar = self.addToolBar('')

        GameStatus().window = self

        yaoguaifaxian_action = QAction(QIcon('./images/ui/yaoguaifaxian.jpg'),
                                       '妖怪发现', self)
        yaoguaifaxian_action.triggered.connect(self.yaoguaifaxian)

        exit_action = QAction(QIcon('./images/ui/exit.png'), '停止', self)
        exit_action.setShortcut('Ctrl+Q')
        exit_action.triggered.connect(self.stop_loop)

        self.toolBar.addAction(yaoguaifaxian_action)
        self.toolBar.addAction(exit_action)

        txt = QTextBrowser()
        txt.setContentsMargins(5, 5, 5, 5)
        self.setCentralWidget(txt)
        self.show()
Example #8
0
    def reload(self):
        global winner, p1_hp_pos, p1_total_life, p1_hp_size, p1_hp_score, p2_hp_pos, \
            p2_hp_size, p2_total_life, p2_hp_score, explosion_time, p1_gaurd_size, p2_gaurd_pos, p1_dhp_pos, p1_dhp_size, p2_dhp_pos, p2_dhp_size

        # GAME DETAILS
        winner = None

        # PLAYER 1 DETAILS
        p1_total_life = resx(550)
        p1_hp_pos = [0, resy(1000)]
        p1_hp_size = [p1_total_life, resy(20)]
        p1_hp_score = 0
        p1_gaurd_size = [p1_total_gaurd, resy(20)]
        p1_dhp_pos = p1_hp_pos.copy()
        p1_dhp_size = p1_hp_size.copy()

        # PLAYER 2 DETAILS
        p2_total_life = resx(550)
        p2_hp_pos = [resolution[0] - p2_total_life, resy(1000)]
        p2_hp_size = [p2_total_life, resy(20)]
        p2_hp_score = 0
        p2_gaurd_pos = [resolution[0] - p2_total_gaurd, resy(970)]
        p2_dhp_pos = p2_hp_pos.copy()
        p2_dhp_size = p2_hp_size.copy()

        # OTHER DETAILS
        explosion_time = 15  # in ms

        self.status = GameStatus()
        self.menu = GameMenu(resolution, self.status.game_menu_text)
        self.smenu = SelectionMenu(resolution, self.status.game_selection_text)

        # PLAYER INITIALIZATIONS
        self.player1 = DisplayPlayers(p1_pos_x, p1_pos_y, p1_fire_type)

        self.player2 = DisplayPlayers(p2_pos_x, p2_pos_y, p2_fire_type)

        # self.player1.laser_sound.play()
        self.player1.hp = Quad(p1_hp_pos, p1_hp_size, p1_hp_color, 'p1')
        self.player2.hp = Quad(p2_hp_pos, p2_hp_size, p2_hp_color, 'p2')

        self.player1.dhp = Quad(p1_dhp_pos, p1_dhp_size, p1_dhp_color, 'p1')
        self.player2.dhp = Quad(p2_dhp_pos, p2_dhp_size, p2_dhp_color, 'p2')

        self.player1.gaurd = Quad(p1_gaurd_pos, p1_gaurd_size, p1_gaurd_color,
                                  'p1')
        self.player2.gaurd = Quad(p2_gaurd_pos, p2_gaurd_size, p2_gaurd_color,
                                  'p2')

        self.menu = GameMenu(resolution, self.status.game_menu_text)
Example #9
0
    def __init__(self, *args, **kwargs):

        # WINDOW INITIALIZATIONS
        super().__init__(*args, **kwargs)
        self.frame_rate = 1 / 60.0
        self.fps_display = FPSDisplay(self)
        self.fps_display.label.font_size = 50

        # MAKING THE PRIMITIVE DRAWINGS TRANSPARENT
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        # GAME MENU INITIALIZATIONS
        self.status = GameStatus()
        self.menu = GameMenu(resolution, self.status.game_menu_text)
        self.smenu = SelectionMenu(resolution, self.status.game_selection_text)
        self.cmenu = ControlsMenu()
        self.amenu = AboutMenu()
        self.start_time = time.time()

        # INITIALLY PLAYING THE MENU BG SONG
        bg_player.play()

        # SPACE BG INITIALIZATIONS
        self.space_list = []
        self.space_img = preload_image(space_bg_img)
        for i in range(2):
            self.space_list.append(
                DisplayObjects(0, i * 1080, Sprite(self.space_img)))
        for space in self.space_list:
            space.vel_y = -space_scroll_speed

        # PLAYER INITIALIZATIONS
        # CREATING PLAYER OBJECTS
        self.player1 = DisplayPlayers(p1_pos_x, p1_pos_y, p1_fire_type)
        self.player2 = DisplayPlayers(p2_pos_x, p2_pos_y, p2_fire_type)

        # PLAYER HP QUAD CREATION
        self.player1.hp = Quad(p1_hp_pos, p1_hp_size, p1_hp_color, 'p1')
        self.player2.hp = Quad(p2_hp_pos, p2_hp_size, p2_hp_color, 'p2')

        # PLAYER GAURD QUAD CREATION
        self.player1.gaurd = Quad(p1_gaurd_pos, p1_gaurd_size, p1_gaurd_color,
                                  'p1')
        self.player2.gaurd = Quad(p2_gaurd_pos, p2_gaurd_size, p2_gaurd_color,
                                  'p2')

        # PLAYER DAMAGE HP QUAD CREATION
        self.player1.dhp = Quad(p1_dhp_pos, p1_dhp_size, p1_dhp_color, 'p1')
        self.player2.dhp = Quad(p2_dhp_pos, p2_dhp_size, p2_dhp_color, 'p2')
Example #10
0
    def generate_children(self):
        children = []
        for i in range(len(self.game_status.remaining_candidates)):
            new_game_status = GameStatus(copy.deepcopy(self.game_status))
            new_game_status.to_move.move(new_game_status, i)

            new_node = GameTreeNode(new_game_status)
            new_node.computer_player = copy.deepcopy(self.computer_player)
            new_node.depth = self.depth + 1
            if self.MAX:
                new_node.MAX = False
            else:
                new_node.MAX = True

            children.append(new_node)
        return children
Example #11
0
    def __init__(self):
        super().__init__()
        self.worker = None
        self.statusBar().showMessage('ready')
        self.resize(250, 150)
        self.move(300, 300)
        self.setWindowTitle('刷起来')
        self.setWindowIcon(QIcon('icon.ico'))

        self.toolBar = self.addToolBar('')

        GameStatus().window = self

        loop_action = QAction(QIcon('./image/ui/loop.png'), 'Loop', self)
        loop_action.triggered.connect(self.start_loop)

        continue_action = QAction(QIcon('./image/ui/continue.png'), 'Continue',
                                  self)
        continue_action.triggered.connect(self.continue_loop)

        once_action = QAction(QIcon('./image/ui/one.jpg'), 'Once', self)
        once_action.triggered.connect(self.quit_on_complete)

        exit_action = QAction(QIcon('./image/ui/exit.png'), 'Exit', self)
        exit_action.setShortcut('Ctrl+Q')
        exit_action.triggered.connect(self.stop_loop)

        inspect_action = QAction(QIcon('./image/ui/inspect.jpg'), 'Inspect',
                                 self)
        inspect_action.triggered.connect(self.inspect)

        self.toolBar.addAction(loop_action)
        self.toolBar.addAction(continue_action)
        self.toolBar.addAction(once_action)
        self.toolBar.addAction(exit_action)
        self.toolBar.addAction(inspect_action)

        txt = QTextBrowser()
        txt.setContentsMargins(5, 5, 5, 5)
        self.setCentralWidget(txt)
        self.show()
Example #12
0
 def __init__(self):
     self.player1 = None
     self.player2 = None
     self.game_status = GameStatus()
Example #13
0
def run_game():
    # 初始化Pygame、设置和屏幕对象

    game_settings = Settings()
    pygame.init()
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))

    pygame.display.set_caption("Alien Invasion")

    # 创建Play按钮
    play_button = Button(game_settings, screen, "Play")

    # 创建一个用于存储游戏统计信息的实例
    status = GameStatus(game_settings)

    scoreboard = ScoreBoard(game_settings, screen, status)

    # 设置背景色
    # bg_color = (230,230,230)

    # 创建一艘飞船
    ship = Ship(game_settings, screen)

    # 创建一个外星人
    # aliens = Alien(game_settings, screen)

    # 创建一个用于存储子弹的编组
    bullets = Group()

    # 创建一个外星人编组
    aliens = Group()

    # 创建外星人群
    GameFunctions.create_fleet(game_settings, screen, ship, aliens)

    # 开始游戏主循环
    while True:

        # 监控键盘和鼠标事件
        # for event in pygame.event.get():
        #     if event.type == pygame.QUIT:
        #         sys.exit()
        GameFunctions.chech_events(game_settings, screen, status, scoreboard,
                                   play_button, ship, aliens, bullets)

        if status.game_active:
            ship.update()

            # 每次循环时都重回屏幕
            # screen.fill(game_settings.bg_color)
            # ship.blitme()
            #
            # # 让最近绘制的屏幕可见
            # pygame.display.flip()

            # bullets.update()

            # 删除已消失的子弹
            # for bullet in bullets.copy():
            #     if bullet.rect.bottom <= 0:
            #         bullets.remove(bullet)
            # print(len(bullets))

            GameFunctions.update_bullets(game_settings, screen, status,
                                         scoreboard, ship, aliens, bullets)
            GameFunctions.update_aliens(game_settings, screen, status,
                                        scoreboard, ship, aliens, bullets)
        GameFunctions.update_screen(game_settings, screen, status, scoreboard,
                                    ship, aliens, bullets, play_button)