class ControlView:
    def __init__(self):
        self.controller = BlackjackController()
        self.new_table = Table(self.controller)

    @staticmethod
    def quit_game():
        pygame.quit()
        quit()

    # passes two objects that tell menu buttons where to go
    def meta_loop(self):
        config.game_exit = Menu().game_menu()
        while not config.game_exit:
            self.new_table.player_hand_loop()
            if config.new_game:
                self.controller = BlackjackController()
                self.new_table = Table(self.controller)
                config.new_game = False
            elif config.game_exit:
                break
            else:
                self.new_table.end_of_hand()
                if config.new_game or config.end_shoe:
                    self.controller = BlackjackController()
                    self.new_table = Table(self.controller)
                    config.new_game = False
                else:
                    self.controller.get_new_player_hand()
                    self.controller.get_new_dealer_hand()
            config.end_shoe = self.controller.get_if_shoe_end()
 def setUp(self):
     self.bjc = BlackjackController()
     self.currentDeck = self.bjc.currentDeck
     self.currentDeck.shuffle()
     self.bet_amount = 100
     self.win = False
     self.default_balance = 10000
     self.starting_blackjack = False
     self.test_player = self.bjc.currentPlayer
     self.test_dealer = self.bjc.currentDealer
Exemple #3
0
 def meta_loop(self):
     """Outer game-control loop, controls exit and new_game."""
     logger.info(
         "Main: ControlView.meta_loop(): Start running through ControlView meta_loop"
     )
     config.game_exit = Menu().game_menu()
     while not config.game_exit:
         logger.debug(
             "While config game_exit bool is FALSE: Simulate blackjack game\n\n"
         )
         #  A player_hand_loop() is really a game loop? The debug message occurs
         #  Each time a new hand is initiated.
         logger.debug(
             "Main: meta_loop() calling Table player_hand_loop() method...")
         self.new_table.player_hand_loop()
         logger.debug(
             "Main: meta_loop() checking if \"NEW GAME\" or \"EXIT GAME\" pressed..."
         )
         if config.new_game:
             logger.debug(
                 "Main: meta_loop() ...\"NEW GAME\" HAS been pressed...")
             self.controller = BlackjackController()
             self.new_table = Table(self.controller)
             config.new_game = False
         elif config.game_exit:
             logger.debug(
                 "Main: meta_loop() ...\"EXIT GAME\" HAS been pressed...")
             break
         else:
             logger.debug(
                 "Main: meta_loop() ...\"NEW GAME\" and \"EXIT GAME\" NOT pressed\n"
             )
             logger.debug(
                 "Main: meta_loop() ... calling Table end_of_hand() method")
             self.new_table.end_of_hand()
             if config.new_game or config.end_shoe:
                 self.controller = BlackjackController()
                 self.new_table = Table(self.controller)
                 config.new_game = False
             else:
                 self.controller.get_new_player_hand()
                 self.controller.get_new_dealer_hand()
         config.end_shoe = self.controller.get_if_shoe_end()
 def meta_loop(self):
     config.game_exit = Menu().game_menu()
     while not config.game_exit:
         self.new_table.player_hand_loop()
         if config.new_game:
             self.controller = BlackjackController()
             self.new_table = Table(self.controller)
             config.new_game = False
         elif config.game_exit:
             break
         else:
             self.new_table.end_of_hand()
             if config.new_game or config.end_shoe:
                 self.controller = BlackjackController()
                 self.new_table = Table(self.controller)
                 config.new_game = False
             else:
                 self.controller.get_new_player_hand()
                 self.controller.get_new_dealer_hand()
         config.end_shoe = self.controller.get_if_shoe_end()
Exemple #5
0
    def __init__(self, controller=None, new_table=None):
        """
        Outer Control Loop, TBD

        Args:
            controller (BlackjackController): Keeps track of game, points, deck
            new_table (Table): Displays UI with controller

        Returns:
            A Blackjack Game

        Raises:
            KeyError: EXAMPLE!!! REPLACE
        """
        logger.debug(
            "Main: ControlView.__init__(): Create BlackjackController: controller in ControlView"
        )
        self.controller = BlackjackController()

        logger.debug(
            "Main: ControlView.__init__(): Create Table: new_table in ControlView"
        )
        self.new_table = Table(self.controller)
class BlackJackControllerTest(unittest.TestCase):
    def setUp(self):
        self.bjc = BlackjackController()
        self.currentDeck = self.bjc.currentDeck
        self.currentDeck.shuffle()
        self.bet_amount = 100
        self.win = False
        self.default_balance = 10000
        self.starting_blackjack = False
        self.test_player = self.bjc.currentPlayer
        self.test_dealer = self.bjc.currentDealer


    def test_hit_dealer(self):
        """testing that the return of hit_dealer is among these return string
        statements

        1 player_bust test 2 dealer_bust 3 player BLACKJACK WIN 4 player
        BLACKJACK WIN when both equal 21 but dealer is not blackjack 5 player
        win 6 player loses, dealer wins. 7 Dealer wins with blackjack 8 tie game
        """
        print("Hit_dealer Return value:", self.bjc.hit_dealer())
        print("Player Score : ", self.test_player.get_score())
        print("Dealer Score:", self.test_dealer.get_score())

        if self.test_player.get_score() > 21:
            self.assertEqual(self.bjc.hit_dealer(), "You bust and lose!", "player Bust  check")
        elif self.test_dealer.get_score() > 21:
            self.assertEqual(self.bjc.hit_dealer(), "Dealer busts! You win!", "Dealer Bust check")
        elif (self.test_player.get_score() != self.test_dealer.get_score()) and self.test_player.has_blackjack():
            self.assertEqual(self.bjc.hit_dealer(), "Blackjack! You Win!", "win condition check player BJ")
        elif (self.test_player.get_score() == self.test_dealer.get_score()) and self.test_player.has_blackjack() and not self.test_dealer.has_blackjack():
            self.assertEqual(self.bjc.hit_dealer(), "BlackJack! You Win!", "player has bj and beats dealers 21 not bj")
        elif self.test_player.get_score() > self.test_dealer.get_score() and not self.test_player.get_score() > 21:
            self.assertEqual(self.bjc.hit_dealer(), "You win!", "Player wins higher score than dealer")
        elif self.test_dealer.get_score() > self.test_player.get_score() and not self.test_dealer.get_score() > 21:
            self.assertEqual(self.bjc.hit_dealer(), "You lose!", "Player loses Dealer had higher score")
        elif self.test_player.get_score()== self.test_dealer.get_score() and self.test_dealer.has_blackjack() and not self.test_player.has_blackjack():
            self.assertEqual(self.bjc.hit_dealer(),"Dealer has BlackJack! You Lose!", "Dealer had BJ player didnt LOSS")
        else:

            self.assertEqual(self.bjc.hit_dealer(), "It's a Tie!", "tie game check")
Exemple #7
0
class ControlView:
    def __init__(self, controller=None, new_table=None):
        """
        Outer Control Loop, TBD

        Args:
            controller (BlackjackController): Keeps track of game, points, deck
            new_table (Table): Displays UI with controller

        Returns:
            A Blackjack Game

        Raises:
            KeyError: EXAMPLE!!! REPLACE
        """
        logger.debug(
            "Main: ControlView.__init__(): Create BlackjackController: controller in ControlView"
        )
        self.controller = BlackjackController()

        logger.debug(
            "Main: ControlView.__init__(): Create Table: new_table in ControlView"
        )
        self.new_table = Table(self.controller)

    def quit_game():
        """call the pygame quit() method"""
        pygame.quit()
        quit()

    # passes two objects that tell menu Buttons where to go
    def meta_loop(self):
        """Outer game-control loop, controls exit and new_game."""
        logger.info(
            "Main: ControlView.meta_loop(): Start running through ControlView meta_loop"
        )
        config.game_exit = Menu().game_menu()
        while not config.game_exit:
            logger.debug(
                "While config game_exit bool is FALSE: Simulate blackjack game\n\n"
            )
            #  A player_hand_loop() is really a game loop? The debug message occurs
            #  Each time a new hand is initiated.
            logger.debug(
                "Main: meta_loop() calling Table player_hand_loop() method...")
            self.new_table.player_hand_loop()
            logger.debug(
                "Main: meta_loop() checking if \"NEW GAME\" or \"EXIT GAME\" pressed..."
            )
            if config.new_game:
                logger.debug(
                    "Main: meta_loop() ...\"NEW GAME\" HAS been pressed...")
                self.controller = BlackjackController()
                self.new_table = Table(self.controller)
                config.new_game = False
            elif config.game_exit:
                logger.debug(
                    "Main: meta_loop() ...\"EXIT GAME\" HAS been pressed...")
                break
            else:
                logger.debug(
                    "Main: meta_loop() ...\"NEW GAME\" and \"EXIT GAME\" NOT pressed\n"
                )
                logger.debug(
                    "Main: meta_loop() ... calling Table end_of_hand() method")
                self.new_table.end_of_hand()
                if config.new_game or config.end_shoe:
                    self.controller = BlackjackController()
                    self.new_table = Table(self.controller)
                    config.new_game = False
                else:
                    self.controller.get_new_player_hand()
                    self.controller.get_new_dealer_hand()
            config.end_shoe = self.controller.get_if_shoe_end()
 def __init__(self):
     self.controller = BlackjackController()
     self.new_table = Table(self.controller)