파이썬으로 코딩된 블랙잭 게임을 시도했습니다.

그래서 나는 가능한 카드 값의 목록을 만들기 시작합니다. 52장의 카드 목록에서 임의의 카드를 선택하고 값 날씨에 따라 다른 플레이어보다 더 많지만 여전히 21 미만인 카드가 결정되는 방식입니다.

link to my github for this project

from random import randint
A = 1
J = 10
K = 10
Q = 10
all_cards = [A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, K, Q]
new_list = []
for x in range(len(all_cards)):
    z = 0
    while z < 4:
        new_list.append(all_cards[x])
        z += 1
player_1_counter = 0
player_1_final_val = 21313
player_2_final_val = 12312
player_2_counter = 0
print("Player 1's turn.")
#starting cards for deck
player_1_counter += new_list[randint(0, len(new_list)-1)]
player_1_counter += new_list[randint(0, len(new_list)-1)]
print(player_1_counter)
while player_1_counter != player_1_final_val:
    if player_1_counter > 21:
        player_1_final_val = player_1_counter
        print("Value over 21, player 1 you lose")
    elif player_1_counter == 21:
        player_1_final_val = player_1_counter
        print("you got 21!")
    elif player_1_counter <= 21:
        next_instruction1 = input("Would you like to 'hit' or 'stand?")
        if next_instruction1 == 'hit':
            player_1_counter += new_list[randint(0, len(new_list)-1)]
            print(player_1_counter)
        elif next_instruction1 == 'stand':
            player_1_final_val = player_1_counter
print("player 2's turn.")
player_2_counter += new_list[randint(0, len(new_list)-1)]
player_2_counter += new_list[randint(0, len(new_list)-1)]
print(player_2_counter)
while player_2_counter != player_2_final_val:
    if player_2_counter > 21:
        player_2_final_val = player_2_counter
        print("Value over 21, player 2 you lose")
    elif player_2_counter == 21:
        player_2_final_val = player_2_counter
        print("you got 21!")
    elif player_2_counter < 21:
        next_instruction2 = input("Would you like to 'hit' or 'stand?")
        if next_instruction2 == 'hit':
            player_2_counter += new_list[randint(0, len(new_list)-1)]
            print(player_2_counter)
        elif next_instruction2 == 'stand':
            player_2_final_val = player_2_counter
if player_2_final_val == player_1_final_val:
    print("its a tie! restart the game to try again.")
elif player_1_final_val > player_2_final_val:
    if player_1_final_val <= 21:
        print("player 1 won! congrats.")
    elif player_1_final_val > 21:
        print("player 2 won! congrats")
elif player_2_final_val > player_1_final_val:
    print("player 2 won! congrats")
    if player_2_final_val <= 21:
        print("player 2 won! congrats.")
    elif player_2_final_val > 21:
        print("player 1 won! congrats")


개선을 위해 노력하는 모든 팁이나 비판에 감사할 것입니다. 지적할 수 있는 실수를 저질렀다면 나중에 프로젝트에서 개선할 수 있도록 참고할 수 있도록 의견을 말해주세요.

좋은 웹페이지 즐겨찾기