Exemplo n.º 1
0
    def test_WinnerBeyond(self):
        #Arrage
        myBoard = ChutesAndLaddersBoard(10, '-', 2)
        expWinner = 1

        #Act
        myBoard.makeMove(0, 6)
        myBoard.makeMove(0, 6)
        myBoard.makeMove(0, 6)
        myBoard.makeMove(0, 6)
        myBoard.makeMove(0, 4)
        myBoard.makeMove(0, 6)
        myBoard.makeMove(0, 6)
        myBoard.makeMove(0, 6)
        actWinner = myBoard.checkWinner(0)

        #Assert
        self.assertEqual(expWinner, actWinner,
                         "Player landing beyond winning spot [0,0] is wrong")
Exemplo n.º 2
0
class ChutesAndLadders(Game):

    turn = 0
    delimeter = "_"
    boardSize = 10

    # CONSTRUCTOR

    @MyLogger.log(["File"])
    def __init__(self):
        """
        Create ChutesAndLadders game class.
        """
        print("\nWelcome to Chutes and Ladders!")
        self.maxSpin = 6

        super().__init__(ChutesAndLadders.turn, ChutesAndLadders.boardSize,
                         ChutesAndLadders.delimeter)
        self.getPlayers()
        self.board = ChutesAndLaddersBoard(self.boardSize, self.delimeter,
                                           len(self.players))

        self._playGame()

    # PROTECTED METHODS

    def _initGame(self):
        pass

    #have players spin and move
    @MyLogger.log(["File"])
    def _playGame(self):
        playerCnt = len(self.players)

        gameWon = False
        while (not (gameWon)):
            input(
                f"{self.players[self.turn]} ({str(self.turn)}) press Enter to spin"
            )
            print("\n")

            spin = random.randint(1, self.maxSpin)
            print(f"You spun a {str(spin)}")

            self.board.makeMove(self.turn, spin)
            print("\n")
            self.board.printBoard()

            gameWon = self.board.checkWinner(self.turn)
            if gameWon:
                print("\n")
                print(f"{self.players[self.turn]} wins!\n")
            else:
                self.turn = 0 if self.turn + 1 > playerCnt - 1 else self.turn + 1

    # Method to get a human player's move
    def _getMoveHuman(self):
        pass

    # Method to determine cpu move
    def _getMoveCPU(self):
        pass