コード例 #1
0
ファイル: Dealer.py プロジェクト: YusukZebs/Blackjack
    def reveal_card(self):
        """
        Swaps the hidden card with the actual card, revealing it.
        """
        print("Revealing HIDDEN CARD...")
        delay(1.4)

        self.hand.append(self.hidden_card)
        self.hand.remove("HIDDEN CARD")

        print(f"The HIDDEN CARD was a {self.hidden_card}!")
        delay(1.4)
コード例 #2
0
    def check_game_over(self):
        """
        Checks if any characters are broke.
        """
        for char in self.char_list:
            if char.money_in_CharBase <= 0:
                global GAME
                GAME = False

                print(f"{char.name} is broke. {char.name} loses!")
                delay()

                break
コード例 #3
0
    def check_loss(self):
        """
        Checks if any character score is higher than 21, and if so, assigns them to self.loser.
        """
        for char in self.char_list:
            if type(char.score1_in_CharBase) is str:
                pass

            elif char.score1_in_CharBase > 21:

                print(f"{char.name}'s score is over 21!")

                self.loser = char

                delay()
コード例 #4
0
 def display(self):
     """
     Outputs game interface.
     """
     print(
         "------------------------------------- \n"
         f"Dealer's hand: {dealer.hand} \n"
         f"Dealer's score: {dealer.score1_in_CharBase} or {dealer.score2_in_CharBase} \n"
         f"Dealer's bank: ${dealer.money_in_CharBase}"
         "\n \n \n \n \n"
         f"Player's hand: {player.hand} \n"
         f"Player score: {player.score1_in_CharBase} or {player.score2_in_CharBase} \n"
         f"Player's bet: ${player.total_bet_in_Player} \n"
         f"Player's bank: ${player.money_in_CharBase}"
         "\n-------------------------------------")
     delay(3)
コード例 #5
0
    def draw_card(self, amount=1):
        """
        Draws a random card from Board.deck. Repeat for amount.
        """
        for _ in range(amount):
            drawn_card = choice(Board.deck)
            Board.deck.remove(drawn_card)
            self.hand.append(drawn_card)

            if self.name == "Dealer" and len(self.hand) <= 2:
                print("Dealer draws a card.")

            else:
                print(f"{self.name} draws {drawn_card}.")

            delay(1.4)
コード例 #6
0
    def game_result(self):
        """
        Checks self.loser and compares score values to see who lost and who won.
        Also adds and subtracts cash from characters according to that result.
        """
        if self.loser == None:
            if player.score1_in_CharBase > dealer.score1_in_CharBase:
                self.loser = dealer

            elif player.score1_in_CharBase < dealer.score1_in_CharBase:
                self.loser = player

            else:  #is a draw
                print("It's a draw!")
                player.money_in_CharBase += player.total_bet_in_Player
                print(
                    f"{player.name} gets their bet, ${player.total_bet_in_Player} back!"
                )

        if self.loser != None:
            index = self.char_list.index(self.loser)
            other_char = self.char_list[abs(index - 1)]

            if player.decision == 4:
                player.total_bet_in_Player = player.total_bet_in_Player // 2
                player.money_in_CharBase += player.total_bet_in_Player
                print("Player surrenders, only losing half the bet.")
                delay()

            if self.loser == player:
                dealer.money_in_CharBase += player.total_bet_in_Player

            else:  #self.loser == dealer
                print(
                    f"{player.name} gets their bet, ${player.total_bet_in_Player} back!"
                )
                delay()
                player.money_in_CharBase += player.total_bet_in_Player * 2
                dealer.money_in_CharBase -= player.total_bet_in_Player

            print(f"{self.loser.name} loses!")
            delay()
            print(f"{self.loser.name} loses ${player.total_bet_in_Player}.")
            delay()
            print(f"{other_char.name} wins ${player.total_bet_in_Player}.")
            delay()
コード例 #7
0
ファイル: Player.py プロジェクト: YusukZebs/Blackjack
    def make_decision(self):
        """
        decide a value for self.decision. Use in main script.
        """
        while not self.decided:
            try:
                self.decision = int(
                    input("1. Draw \n"
                          "2. Draw final card and double bet \n"
                          "3. End turn \n"
                          "4. Surrender \n"))
            except ValueError:
                print("Wrong input")
                delay(1.4)
                continue

            if self.decision < 1 and self.decision > 4:
                print("Wrong input")
                delay(1.4)
                continue

            self.decided = True
コード例 #8
0
    GAME = True

    while GAME == True:

        main.check_game_over()
        main.value_reset()

        if GAME == False:
            break
        else:
            pass

        for char in main.char_list:
            print(f"{char.name} has ${char.money_in_CharBase}.")

            delay()

        player.bet()

        for char in main.char_list:
            char.draw_card(2)
            char.calc_score()

        dealer.hide_card()

        #show BOARD
        main.display()

        main.playing_char = player

        while main.loser == None:
コード例 #9
0
ファイル: Player.py プロジェクト: YusukZebs/Blackjack
    def bet(self, bet_amount_in_Player=0):
        """
        betting a set amount of money.
        
        """
        while not self.has_betted:

            if self.decided == False:
                bet_amount_in_Player = input(
                    f"How much will you bet? (Min: $1, Max: ${self.money_in_CharBase}) \n"
                    "$")

            try:
                bet_amount_in_Player = int(bet_amount_in_Player)
            except ValueError:
                print("Bet again.")
                delay(1.4)
                continue

            if bet_amount_in_Player > self.money_in_CharBase:
                print("You can't bet more than your balance.")
                delay(1.4)
                if self.decision == 2:  #This is when bet() is called from CharBase.ask_decision()
                    print("Betting all instead.")
                    delay(1.4)
                    bet_amount_in_Player = self.money_in_CharBase
                else:
                    print("Bet again.")
                    delay(1.4)
                    continue

            elif bet_amount_in_Player < 1:
                print("Can't bet less than $1.")
                delay(1.4)
                continue

            if bet_amount_in_Player <= self.money_in_CharBase:
                print(f"Betting ${bet_amount_in_Player}.")
                delay(1.4)
                self.money_in_CharBase -= bet_amount_in_Player
                self.total_bet_in_Player += bet_amount_in_Player
                break