Beispiel #1
0
    def NewGame(self):

        self.ResetInstanceVariable()

        ##################
        # Player related #
        ##################

        # Define the number of players
        text, ok = QtGui.QInputDialog.getText(self, "Text Input Dialog",
                                              "Enter the number of players")

        if ok:
            self.nb_players = int(text)

        # Enter the name of the players
        for i in range(self.nb_players):
            box = QtGui.QInputDialog(self)

            text, ok = box.getText(self, "Text Input Dialog",
                                   "Enter player %d's name:" % (i + 1))

            if ok:
                self.players.append(Player.Player(str(text)))

        # If only one player, need to create an AI player
        if self.nb_players == 1:

            item, ok = QtGui.QInputDialog.getItem(
                self, "Initialization", "Select the difficulty of the AI",
                tuple(difficulties), 0, False)

            self.players.append(
                Player.ArtificalIntelligence('AI ' + str(item),
                                             difficulties.index(str(item)) +
                                             1))

        ################
        # Game related #
        ################

        item, ok = QtGui.QInputDialog.getItem(self, "Initialization",
                                              "Choose the size of the board",
                                              ('4', '6', '8'), 0, False)

        if ok and item:
            if int(item) != self.board_size:
                self.new_size = True
            else:
                self.new_size = False
            self.board_size = int(item)