예제 #1
0
    def testWin(self):
        testObject = Board()
        model = ModelBattleship()
        model.placeShip(testObject, 2, [0, 0], 'v')
        model.placeShot(testObject, [0, 0])

        expectedValue = False
        actualValue = model.checkWin(testObject)
        assert (actualValue == expectedValue)

        model.placeShot(testObject, [1, 0])
        expectedValue = True
        actualValue = model.checkWin(testObject)
        assert (actualValue == expectedValue)
 controller = ControllerBattleship()
 controller.playerBoard = Board()
 controller.enemyBoard = Board()
 view = ViewBattleship()
 model = ModelBattleship()
 userInput = view.displayMenu()
 if userInput[0] == '1':
     controller.makeAIBoard()
     view.displayBoard(controller.playerBoard)
     controller.inputShips()
     if userInput[1] == '1':
         while 1:
             view.display("Enemy Board: ")
             view.displayBoard(model.maskBoard(controller.enemyBoard))
             controller.getShot()
             if model.checkWin(controller.enemyBoard):
                 view.display("Congrats you won!!")
                 break
             else:
                 model.randAI(controller.playerBoard)
                 view.display("Your Board: ")
                 view.displayBoard(controller.playerBoard)
                 if model.checkWin(controller.playerBoard):
                     view.display("Oh no you lost!!")
                     break
         view.displayBoard(controller.enemyBoard)
     elif userInput[1] == '2':
         while 1:
             view.display("Enemy Board: ")
             view.displayBoard(model.maskBoard(controller.enemyBoard))
             controller.getShot()