Esempio n. 1
0
 def __init__(self):
     GObject.GObject.__init__(self)
     self.view = BoardView()
     self.add(self.view)
     self.view.showEnpassant = True
     
     self.connect("button_press_event", self.button_press)
     self.connect("button_release_event", self.button_release)
     self.add_events(Gdk.EventMask.LEAVE_NOTIFY_MASK|Gdk.EventMask.POINTER_MOTION_MASK)
     self.connect("motion_notify_event", self.motion_notify)
     self.connect("leave_notify_event", self.leave_notify)
     
     self.brush = None
Esempio n. 2
0
    def __init__(self, gamemodel, actionMenuItems):
        gtk.EventBox.__init__(self)
        self.promotionDialog = PromotionDialog()
        self.view = BoardView(gamemodel)
        self.add(self.view)

        self.actionMenuItems = actionMenuItems
        self.connections = {}
        for key, menuitem in self.actionMenuItems.iteritems():
            if menuitem == None: print key
            self.connections[menuitem] = menuitem.connect(
                "activate", self.actionActivate, key)

        self.view.connect("shown_changed", self.shown_changed)
        gamemodel.connect("moves_undoing", self.moves_undone)
        self.connect("button_press_event", self.button_press)
        self.connect("button_release_event", self.button_release)
        self.add_events(gtk.gdk.LEAVE_NOTIFY_MASK
                        | gtk.gdk.POINTER_MOTION_MASK)
        self.connect("motion_notify_event", self.motion_notify)
        self.connect("leave_notify_event", self.leave_notify)

        self.selected_last = None
        self.stateLock = threading.Lock()
        self.normalState = NormalState(self)
        self.selectedState = SelectedState(self)
        self.activeState = ActiveState(self)
        self.lockedState = LockedState(self)
        self.lockedSelectedState = LockedSelectedState(self)
        self.lockedActiveState = LockedActiveState(self)
        self.currentState = self.lockedState

        self.lockedPly = self.view.shown
        self.possibleBoards = {
            self.lockedPly: self._genPossibleBoards(self.lockedPly)
        }

        self.allowPremove = False

        def onGameStart(gamemodel):
            for player in gamemodel.players:
                if player.__type__ == LOCAL:
                    self.allowPremove = True

        gamemodel.connect("game_started", onGameStart)
Esempio n. 3
0
 def __init__(self):
     #GameBoard, display and notification objects
     self.board = Board()
     self.boardView = BoardView()
     self.notifications = Notifications()
     #Player objects
     self.human = Human()
     self.computer = Computer()
     #Toss Variables
     self.humanDieToss = 0
     self.computerDieToss = 0
     #Control variables
     self.humanTurn = False
     self.computerTurn = False
     #Variables to store user input of coordinates
     self.startRow = 0
     self.startCol = 0
     self.endRow = 0
     self.endCol = 0
     #1 for vertical first, 2 for lateral first
     self.path = 0
Esempio n. 4
0
    def __init__(self, app):
        self.restart_pressed = False
        self.already_won = False
        self.total_cur_words_n = 0
        self.app = app
        self.game_model = GameModel()

        self.player_views = []
        for i, cards in enumerate(self.game_model.cards):
            name = "player {}".format(i + 1)
            self.player_views.append(PackView(name, cards))

        self.open_view = PackView("open", self.game_model.cards_open)
        self.open_view.switch_to_open_view()
        self.hidden_view = PackView("hidden", self.game_model.cards_hidden)
        self.hidden_view.switch_to_hidden_view()

        self.question_view = QuestionView(
            self.game_model.questions_in_hand_number,
            self.game_model.players_number)
        self.question_view.set_questions(self.game_model.players_questions[0])

        self.board_view = BoardView(self.player_views, self.open_view,
                                    self.hidden_view, self.question_view)

        self.question_view.question_clicked.connect(
            self.question_button_clicked)
        self.board_view.next_turn_button.clicked.connect(
            self.nex_player_button_clicked)
        self.board_view.restart_button.clicked.connect(self.restart_clicked)

        self.update_tables_for_cur_player()
        self.update_tips()
        self.update_views()

        self.board_view.next_turn_button.setDisabled(True)
Esempio n. 5
0
File: Game.py Progetto: Gerome/XXOs
    def start(self):

        innerBoards = [[InnerBoard(), InnerBoard(),
                        InnerBoard()],
                       [InnerBoard(), InnerBoard(),
                        InnerBoard()],
                       [InnerBoard(), InnerBoard(),
                        InnerBoard()]]

        overallBoard = InnerBoard()

        mainBoard = Board(innerBoards)
        boardView = BoardView()

        playerOneNoughtCross = NoughtCross(
            input("Player 1, please input your symbol.\r\n"))
        playerTwoNoughtCross = NoughtCross(
            input("Player 2, please input your symbol.\r\n"))

        playerCharacters = [playerOneNoughtCross, playerTwoNoughtCross]

        currentPlayer = 2
        playerSwitchValue = -1

        xBoard, yBoard = 1, 1

        print("Enter \"tl\" for the top left position.")

        while not self.gameIsFinished:

            print(boardView.GetFormattedBoard())

            currentPlayer += playerSwitchValue
            playerSwitchValue *= -1

            validMove = False

            while not validMove:
                print("Player {}'s go.".format(currentPlayer))

                userInput = input("Where do you want to go?\r\n").lower()

                if userInput.startswith('t'):
                    yInput = 0
                if userInput.startswith('m'):
                    yInput = 1
                if userInput.startswith('b'):
                    yInput = 2

                if userInput.endswith('l'):
                    xInput = 0
                if userInput.endswith('m'):
                    xInput = 1
                if userInput.endswith('r'):
                    xInput = 2

                moveReturnValue = mainBoard.TakeTurn(
                    xBoard, yBoard, int(xInput), int(yInput),
                    playerCharacters[currentPlayer - 1])
                validMove = (moveReturnValue == InnerBoard.ERROR_NO_ERROR)

                if not validMove:
                    print("INVALID MOVE!\r\n")

            boardView.UpdateBoard(xBoard, yBoard, xInput, yInput,
                                  playerCharacters[currentPlayer - 1].type)

            self.CheckForWin(currentPlayer, mainBoard, overallBoard,
                             playerCharacters, xBoard, yBoard)

            if (self.gameIsFinished):
                print(boardView.GetFormattedBoard())
                print("Player {} wins!.".format(currentPlayer))

            xBoard = xInput
            yBoard = yInput
Esempio n. 6
0
 def setUp(self):
     self.boardView = BoardView()
     self.testBoard = self.EMPTY_BOARD