示例#1
0
    def __init__(self, skin, puzzle, text, parent=None):
        board = grid2graphics(skin, puzzle.board)
        drawpile = [grid2graphics(skin, move.grid) for move in puzzle.moves]
        hover = grid2graphics(skin, puzzle.hover)

        win = SoloGameView(board, drawpile, hover, 0, text, parent)
        super().__init__(skin, puzzle, win.gameview)

        win.gameview.pressUp.connect(self.revertMove)
        win.gameview.pressDown.connect(self.makeMove)

        win.show()

        self.win = win
示例#2
0
    def __init__(self, skin, module, nmoves, nreview, parent=None):
        self.skin = skin
        self.module = module
        self.nmoves = nmoves
        self.nreview = nreview

        self.history = []

        # Initialize the window.
        self.pickPuzzle()
        self.win = TestWindow(
            board1=grid2graphics(skin, self.puzzle_response.board),
            drawpile1=[
                grid2graphics(skin, move.grid) for move in self.puzzle_response.moves
            ],
            hover1=grid2graphics(skin, self.puzzle_response.hover),
            nremain1=0,
            board2=grid2graphics(skin, self.puzzle_solution.board),
            drawpile2=[
                grid2graphics(skin, move.grid) for move in self.puzzle_solution.moves
            ],
            hover2=grid2graphics(skin, self.puzzle_solution.hover),
            nremain2=0,
            parent=parent,
        )

        # Wire up the sub-controllers.
        self.play_control = PlayVC(
            skin, self.puzzle_response, self.win.test.gameview, revertable=False
        )
        self.review_response_control = PlayVC(
            skin, self.puzzle_response, self.win.review.gameview1, shiftable=False
        )
        self.review_solution_control = PlayVC(
            skin, self.puzzle_response, self.win.review.gameview2, shiftable=False
        )

        self.review_solution_control.animation_start.connect(
            self.review_response_control.setLock
        )
        self.review_solution_control.animation_end.connect(
            self.review_response_control.releaseLock
        )

        # cross strap hack
        self.win.review.gameview2.setFocusPolicy(Qt.NoFocus)
        self.review_response_control.pressDown_xstrap.connect(
            self.win.review.gameview2.pressDown
        )
        self.review_response_control.pressUp_xstrap.connect(
            self.win.review.gameview2.pressUp
        )
        self.win.test.gameview.pressSpace.connect(self.proceed2review)
        self.win.review.gameview1.pressSpace.connect(self.proceed2test)

        self.review_response_control.process_complete.connect(self.reviewEval)

        self.win.show()
示例#3
0
    def __init__(self, puzzle, skin, parent=None):
        self.skin = skin
        self.puzzle = puzzle

        board, drawpile = self._generatePuzzleDefineGraphics()
        hover = grid2graphics(skin, puzzle.hover)

        self.view = EditorView(board, drawpile, hover, parent)
        self.view.setWindowTitle("New Puzzle (" + puzzle.path + ")")

        self.game_controller = PlayVC(skin, puzzle,
                                      self.view.solverview.gameview)

        self.bindDefineView()
        self.bindSolverView()

        self.view.show()
示例#4
0
    def animate(self, popstate=PopState.PREPOP):
        # Create a timer for the pop animation.
        timer = QTimer(self.view)
        timer.setSingleShot(True)
        timer.setInterval(POP_SPEED * 1000)
        self.timer = timer

        # Check for a pop and animate (recursively).
        popset = self.puzzle.board.pop_set(self.puzzle.module.pop_limit)
        if popset:
            if not self.haslock:
                self.animation_start.emit()
                self.haslock = True

            # Empty the hover grid.
            self.puzzle.hover.assign_move(None)
            hover_gfx = grid2graphics(self.skin, self.puzzle.hover)

            # Get the visible drawpile.
            draw_gfx = [grid2graphics(self.skin, mv.grid) for mv in self.puzzle.moves]
            draw_gfx = draw_gfx[self.draw_index : self.draw_index + 2]

            # Calculate remaining.
            nremaining = len(self.puzzle.moves) - self.draw_index

            # Get the board graphics.
            board_gfx = grid2graphics(
                skin=self.skin,
                grid=self.puzzle.board,
                ghosts=set(),
                pops=popset,
                popstate=popstate,
            )

            self.view.setGraphics(board_gfx, draw_gfx, hover_gfx, nremaining)

            # Start the timer to update the animation at the next pop state.
            self.timer.timeout.connect(lambda: self.animate(popstate._next()))
            self.timer.start()

            # If at the final pop state in the animation, execute the pop.
            if popstate is PopState.POPLATER:
                self.puzzle.board.execute_pop(self.puzzle.module.pop_limit)

        else:
            # Assign a move, if available, to the hover grid.
            try:
                move = self.puzzle.moves[self.draw_index]
            except IndexError:
                move = None

            self.puzzle.hover.assign_move(move)
            hover_gfx = grid2graphics(self.skin, self.puzzle.hover)

            # Get the visible drawpile.
            draw_gfx = [grid2graphics(self.skin, mv.grid) for mv in self.puzzle.moves]
            draw_gfx = draw_gfx[self.draw_index + 1 : self.draw_index + 3]

            # Calculate remaining.
            nremaining = len(self.puzzle.moves) - self.draw_index

            # Find the ghosts.
            if move is not None:
                future_board = deepcopy(self.puzzle.board)
                future_board.apply_move(move)
                ghosts = future_board - self.puzzle.board
            else:
                ghosts = set()

            # Get the board graphics.
            board_gfx = grid2graphics(self.skin, self.puzzle.board, ghosts)

            self.view.setGraphics(board_gfx, draw_gfx, hover_gfx, nremaining)
            self.animation_end.emit()
            self.haslock = False
示例#5
0
 def _generatePuzzleDefineGraphics(self):
     board = grid2graphics(self.skin, self.puzzle.board)
     drawpile = [
         grid2graphics(self.skin, move.grid) for move in self.puzzle.moves
     ]
     return board, drawpile