Блэкджек, питон - PullRequest
       19

Блэкджек, питон

0 голосов
/ 08 марта 2019
import random
import time

class card():
    def __init__(self):
         cardNum = ["1","2", "3", "4", "5", "6", "7", "8", "9", "10", "10", "10"]
        randNum = random.randint(0, len(cardNum) - 1)
        cardSuit = ["Hearts", "Clubs", "Diamonds", "Spades"]
        randSuit = random.randint(0, len(cardSuit) - 1)

        self.rank = cardNum[randNum]
        self.suit = cardSuit[randSuit]

    total1 = []
    total2 = []
    total1.append(self.rank)

    def printIntro():
        print("Blackjack (twenty-one) is a casino game played with cards.")
        print("the goal of game is to draw cards that total as close to 21 
points, as possibale")
        print("without going over( whose hand > 21 will bust). All face 
cards count as 10 points,")
        print("aces count as 1 or 11, and all other cards count their 
numeric value.")
        print("\nFirstly, your turn:")


    def displayCard(self):


        return (self.rank+ " of "+ self.suit)

    def totalScore(self, ans="Y"):
        total1 = []
        total2 = []

        if ans == "Y":
            totalscore1 = total1.append(self.rank)
            return totalscore1
            ans = "N"
        if ans == "N":
            totalscore2 = total2.append(self.rank)
            return totalscore2


    def aceOption(self, cards1, cards2):
        if "Ace" in cards1:
            print("You have an ACE!")
            opt = int(input("Would you like ACE to be 1 or 11?: "))

            if opt == "1":
                aceVal(1)
            elif opt == "11":
                aceVal(11)

        elif "Ace" in cards2:
            print("You have an ACE!")
            opt = int(input("Would you like ACE to be 1 or 11?: "))

            if opt == "1":
                aceVal(1)
            elif opt == "11":
                aceVal(11)

    def nextOption(self):
        opt = input("Would you like to (T)WIST, or (S)TICK?")
        if opt == "T":
            #make twist function
        elif opt == "S":
            #make stick function

#myCard = card()

class player():
    def __init__(self, name="bob"):
        self.cards = []
        self.name = name
        self.cards2 = []

    def dealer1go(self):
        for i in range(0, 1):
            newcard = card()
            self.cards2.append(newcard.displayCard())

    def player1go(self):
        for i in range(0, 1):
            newcard = card()
            self.cards.append(newcard.displayCard())

class totalAmount():
    def __init__(self):
        pass




player1 = player("Matt")
dealer = player("Kieron")
deck = card()
intro =card.printIntro()
print(" ")
print(intro)


print("\nPlayer1 is dealt two cards..")
print("-------------------------------\n")
time.sleep(1)
print("\nDealer has two cards..")
print("-------------------------------\n")
time.sleep(1)

for i in range(1, 3):
    player1.player1go()
    dealer.dealer1go()

print("Player1 cards: ", player1.cards)
#card.totalScore("Y")
deck.aceOption(player1.cards, dealer.cards2)

print("Dealers cards: ", dealer.cards2)
#card.totalScore("N")
deck.aceOption(player1.cards, dealer.cards2)

deck.nextOption()



card()

Функция totalScore (self) и aceOption (self) не работают, и я все время путаюсь с тем, как их связать.В настоящее время изучаю, как использовать классы, и (самостоятельно).

В настоящий момент получается всего 2 случайных карты, которые сдаются игроку 1 и дилеру, а затем помещаются в массив.Мне нужно дать пользователю возможность выбрать туза, если он у него есть, равным 11 или 1.

И мне нужен общий балл значений карт, если totalScore> 21, тогда ониБЮСТ и игра окончена.

1 Ответ

0 голосов
/ 12 марта 2019

Поскольку вы являетесь студентом уровня A, мы должны учитывать это при ответе на ваши вопросы.Когда вы пишете «randNum = random.randint (0, len (cardNum) - 1)») в строке 7, вы ограничиваете выбор карт до 12 карт, а не 13 для масти.Это даст вам 48 карт, как упомянул Ли Дэниел Крокер, но на самом деле не объяснил.Вы также можете дать пользователю возможность сменить туза, если это то, что вы хотите сделать, так как это ваш код, но вы можете оставить его до конца, чтобы упростить вещи.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...