def onPlayButtonClicked(self):
        if self.player1NameLineEdit.text() == "" or self.player2NameLineEdit.text() == "" or str(
                self.player1Cb.currentText()) == "" or str(self.player2Cb.currentText()) == "":
            msg = QMessageBox()
            msg.setIcon(QMessageBox.NoIcon)
            msg.setText("Enter your username and choose ship")
            msg.setWindowTitle("Error")
            msg.exec_()

        elif self.player1NameLineEdit.text() == self.player2NameLineEdit.text():
            msg = QMessageBox()
            msg.setIcon(QMessageBox.NoIcon)
            msg.setText("Username must be unique")
            msg.setWindowTitle("Error")
            msg.exec_()

        else:

            player1_input = PlayerInput(player_id=self.player1NameLineEdit.text(), color=self.player1Cb.currentText())
            player2_input = PlayerInput(player_id=self.player2NameLineEdit.text(), color=self.player2Cb.currentText())

            _start_game_process(player1_input, player2_input, title="Asteroids - Multi Player")
            self.hide()
            self.player1NameLineEdit.setText("")
            self.player2NameLineEdit.setText("")
def _start_game(player1_id, player1_color, player2_id, player2_color, title="Multi Player"):
    app = QApplication(sys.argv)
    game = AsteroidsGame(
        player_inputs=[
            PlayerInput(player_id=player1_id, color=player1_color),
            PlayerInput(player_id=player2_id, color=player2_color)
        ], title=title)
    game.start()
    sys.exit(app.exec_())
Example #3
0
def _start_game(queue: Queue, player1_id, player1_color, player2_id, player2_color, title="Tournament"):
    app = QApplication(sys.argv)
    game = AsteroidsTournament(
        queue=queue,
        player_inputs=[
            PlayerInput(player_id=player1_id, color=player1_color),
            PlayerInput(player_id=player2_id, color=player2_color)
        ], title=title)
    game.start()
    sys.exit(app.exec_())
Example #4
0
    def onPlayButtonClicked(self):
        if self.player1NameLineEdit.text() == "" or self.player2NameLineEdit.text() == "" \
                or self.player3NameLineEdit.text() == "" or self.player4NameLineEdit.text() == "" \
                or str(self.player1Cb.currentText()) == "" or str(self.player2Cb.currentText()) == "" \
                or str(self.player3Cb.currentText()) == "" or str(self.player4Cb.currentText()) == "":
            msg = QMessageBox()
            msg.setIcon(QMessageBox.NoIcon)
            msg.setText("Enter your username and choose ship")
            msg.setWindowTitle("Error")
            msg.exec_()

        elif self.player1NameLineEdit.text() == self.player2NameLineEdit.text() \
                or self.player1NameLineEdit.text() == self.player3NameLineEdit.text() \
                or self.player1NameLineEdit.text() == self.player4NameLineEdit.text() \
                or self.player2NameLineEdit.text() == self.player3NameLineEdit.text() \
                or self.player2NameLineEdit.text() == self.player4NameLineEdit.text() \
                or self.player3NameLineEdit.text() == self.player4NameLineEdit.text():
            msg = QMessageBox()
            msg.setIcon(QMessageBox.NoIcon)
            msg.setText("Username must be unique")
            msg.setWindowTitle("Error")
            msg.exec_()

        else:
            player1_input = PlayerInput(
                player_id=self.player1NameLineEdit.text(),
                color=self.player1Cb.currentText())
            player2_input = PlayerInput(
                player_id=self.player2NameLineEdit.text(),
                color=self.player2Cb.currentText())
            player3_input = PlayerInput(
                player_id=self.player3NameLineEdit.text(),
                color=self.player3Cb.currentText())
            player4_input = PlayerInput(
                player_id=self.player4NameLineEdit.text(),
                color=self.player4Cb.currentText())

            thread = Thread(target=start_tournament,
                            args=(player1_input, player2_input, player3_input,
                                  player4_input))
            thread.daemon = True
            thread.start()
            self.hide()
            self.player1NameLineEdit.setText("")
            self.player2NameLineEdit.setText("")
            self.player3NameLineEdit.setText("")
            self.player4NameLineEdit.setText("")
    def onCreateButtonClicked(self):
        if self.player1NameLineEdit.text() == "" or str(self.player1Cb.currentText()) == "":
            msg = QMessageBox()
            msg.setIcon(QMessageBox.NoIcon)
            msg.setText("Enter your username and choose ship")
            msg.setWindowTitle("Error")
            msg.exec_()

        else:
            player1_input = PlayerInput(player_id=self.player1NameLineEdit.text(), color=self.player1Cb.currentText())

            self.server = Server(5)

            self.game = ClientAsteroidsGame('seed', player_inputs=[player1_input], title="Asteroids - Client")
            self.game.start()
Example #6
0
    def __init__(self,
                 screen_width,
                 screen_height,
                 asteroid_factory: AsteroidFactory,
                 spaceship_factory: SpaceshipFactory,
                 heart_factory: HeartFactory,
                 player_factory: PlayerFactory,
                 player_inputs=None,
                 seed=None):
        if player_inputs is None:
            player_inputs = [PlayerInput(player_id="1", color="red")]

        self.rand_gen = Random(seed)
        self.screen_width = screen_width
        self.screen_height = screen_height
        self.asteroid_factory = asteroid_factory
        self.spaceship_factory = spaceship_factory
        self.heart_factory = heart_factory
        self.player_factory = player_factory
        self.player_inputs = player_inputs
Example #7
0
        self.game = Game(self.screen,
                         level_factory=level_factory,
                         key_handler=key_handler,
                         collision_handler=collision_handler,
                         movement_handler=movement_handler,
                         on_game_end=self.on_game_end)

    def on_game_end(self, storage):
        winner = storage.get_player_with_most_points()
        self.screen.display_winner(
            winner=winner, on_end=lambda: self._handle_end_click(storage))

    def _handle_end_click(self, storage):
        save_score_to_file(storage)
        exit()

    def start(self):
        self.screen.show()
        self.game.start()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    asteroidsGame = AsteroidsGame(player_inputs=[
        PlayerInput(player_id="Steve", color="green"),
        PlayerInput(player_id="Urkel", color="blue")
    ])
    asteroidsGame.start()
    sys.exit(app.exec_())
        self.game = OnlineGame(self.screen,
                               level_factory=level_factory,
                               key_handler=key_handler,
                               collision_handler=collision_handler,
                               movement_handler=movement_handler,
                               on_game_end=self.on_game_end)

    # TODO: Ovo javlja server
    def on_game_end(self, storage):
        winner = storage.get_player_with_most_points()
        self.screen.display_winner(
            winner=winner, on_end=lambda: self._handle_end_click(storage))

    def _handle_end_click(self, storage):
        save_score_to_file(storage)
        exit()

    def start(self):
        self.screen.show()
        self.game.start()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    asteroidsGame = ClientAsteroidsGame(player_inputs=[
        PlayerInput(player_id="Steve", color="red"),
        PlayerInput(player_id="Urkel", color="yellow")
    ])
    asteroidsGame.start()
    sys.exit(app.exec_())
Example #9
0
    exit()


def _start_game_process(q, player1_input, player2_input, title="Tournament") -> str:
    process = Process(target=_start_game, args=(q, player1_input.player_id, player1_input.color,
                                                player2_input.player_id, player2_input.color,
                                                title))
    process.start()
    winner_id = q.get()
    process.terminate()
    return winner_id


def _start_game(queue: Queue, player1_id, player1_color, player2_id, player2_color, title="Tournament"):
    app = QApplication(sys.argv)
    game = AsteroidsTournament(
        queue=queue,
        player_inputs=[
            PlayerInput(player_id=player1_id, color=player1_color),
            PlayerInput(player_id=player2_id, color=player2_color)
        ], title=title)
    game.start()
    sys.exit(app.exec_())


if __name__ == "__main__":
    start_tournament(player1_input=PlayerInput("A", "red"),
                     player2_input=PlayerInput("B", "yellow"),
                     player3_input=PlayerInput("C", "green"),
                     player4_input=PlayerInput("D", "blue"))