Пример #1
0
def main():
    print("\t\tWelcome to Blackjack!\n")

    names = []
    number = None
    while not number:
        number = Games.ask_number("How many players? (1-7): ", low = 1, high = 8)

    for i in range(number):
        name = None
        while not name:
            name = input("Enter player name: ")
        names.append(name)

    print()

    game = BJ_Game(names)

    again = None
    while again != "n" and game.players:
        game.play()
        if not game.players:
            print("\nNo more players left!")
        else:
            again = Games.ask_yes_no("\nDo you want to play again? (Y/N): ")
Пример #2
0
    def play(self):
        # check if the card has enough cards if not repopulate and reshuffle
        if len(self.deck) <= 12:
            self.repopulate_deck()
        # deal initial 2 cards to everyone
        self.deck.deal(self.players + [self.dealer], per_hand=2)
        self.dealer.flip_first_card()  # hide the dealer's first card
        for player in self.players:
            while (1):
                player.bet_amount = Games.ask_number(
                    '{} How much would you like to bet: ({} - {}): '.format(
                        player.name, 10, player.Bank.total),
                    low=10,
                    high=player.Bank.total + 1)
                if player.bet(player.bet_amount):
                    break

            player.Bank.total = player.Bank.total - player.bet_amount

        for player in self.players:
            print(player)
        print(self.dealer)

        # deal additional cards
        for player in self.players:
            self.__additional_cards(player)

        self.dealer.flip_first_card()  # reveal dealer's first card

        if not self.still_playing:
            # since all players have busted show dealers hand
            print(self.dealer)
        else:
            # deal additional cards
            print(self.dealer)
            self.__additional_cards(self.dealer)

            if self.dealer.is_busted():
                # everyone still playing wins
                for player in self.still_playing:
                    player.win()

            else:
                # compare each player still playing to he dealer
                for player in self.still_playing:
                    if player.total > self.dealer.total:
                        player.win()
                    elif player.total < self.dealer.total:
                        player.lose()
                    else:
                        player.push()

        # remove everyones cards
        for player in self.players:
            player.clear()
        self.dealer.clear()
Пример #3
0
def main():
    print("\t\tWelcome to Blackjack!\n")

    names = []
    number = Games.ask_number("How many players? (1 - 7): ", low=1, high=8)
    for i in range(number):
        name = input("Enter player name: ")
        names.append(name)
        print()

    game = BJ_Game(names)

    again = None
    while again != 'n':
        game.play()
        again = Games.ask_yes_no("\nDo you want to play again?: ")
Пример #4
0
#Simple Game
#Demonstrates importing modules
#Evan Piercy
#6.5.15

import Games, random

print("Welcome to the world's simplest game!\n")

again = None
while again !="n":
    players = []
    num = Games.ask_number(question = "How many players? (2 - 5): ", low = 2, high = 5)

    for i in range(num):
        name = input("Player name: ")

        score = random.randrange(100) + 1
        player = Games.Player(name, score)
        players.append(player)

    print("\nHere are the game results: ")
    for player in players:
        print(player)
    again = Games.ask_yes_no("\nDo you want to play again? (y/n)")

input("\n\nPress the enter key to exit.")
Пример #5
0
# Simple Game
# Demos importing modules

import Games, random

print("Welcome to the world's simplest game!\n")

again = None
while again != "n":
    players = []
    num = Games.ask_number(question = "How many players? (2-5): ", low = 2,
                       high = 5)

    for i in range(num):
        name = input("Player name: ")
        score = random.randrange(100) + 1
        player = Games.Player(name, score)
        players.append(player)

    print("\nHere are the game results:")
    for player in players:
        print(player)

    again = Games.ask_yes_no("\nDo you want to play again? (y/n): ")

input("\n\nPress the enter key to exit.")