طبعا هذا هو المشروع واشعر انني لم اتمكن منه بالكامل بعد ممكن اجلس اعيده اليوم وغدا ومن ثم انتقل الى المستوى الجديد
.
import random
import os
import time
def main_screen():
clear_screen()
print ('''
████████╗░██╗░░░░░░░██╗███████╗███╗░░██╗████████╗██╗░░░██╗░░░░░░░█████╗░███╗░░██╗███████╗
╚══██╔══╝░██║░░██╗░░██║██╔════╝████╗░██║╚══██╔══╝╚██╗░██╔╝░░░░░░██╔══██╗████╗░██║██╔════╝
░░░██║░░░░╚██╗████╗██╔╝█████╗░░██╔██╗██║░░░██║░░░░╚████╔╝░█████╗██║░░██║██╔██╗██║█████╗░░
░░░██║░░░░░████╔═████║░██╔══╝░░██║╚████║░░░██║░░░░░╚██╔╝░░╚════╝██║░░██║██║╚████║██╔══╝░░
░░░██║░░░░░╚██╔╝░╚██╔╝░███████╗██║░╚███║░░░██║░░░░░░██║░░░░░░░░░╚█████╔╝██║░╚███║███████╗
░░░╚═╝░░░░░░╚═╝░░░╚═╝░░╚══════╝╚═╝░░╚══╝░░░╚═╝░░░░░░╚═╝░░░░░░░░░╚════╝░╚═╝░░╚══╝╚══════╝
♠ ♣ ♥ ♦
----------------------------------------------------------------------------------------------------------
''')
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
def deal_cards():
return random.choice([11,2,3,4,5,6,7,8,9,10,10,10,10])
def calculate_card(cards):
if sum(cards) == 21 and len(cards) == 2:
return 0
if sum(cards) > 21 and 11 in cards:
cards.remove(11)
cards.append(1)
return sum(cards)
def who_win(user_score,computer_score):
results = {
'draw': 'draw😑',
'user_21': 'You win with a blackjack🤯🔥✔',
'computer_21': 'Sorry, computer has a blackjack, you lose😬🤦',
'user_over': 'Sorry, you went over 21, you lose🤨😹',
'computer_over': 'computer went over 21, you win😎😉',
'user_win': 'You Win!😬👌😎',
'computer_win': 'You Lose😅',
}
if user_score == computer_score:
return results['draw']
elif user_score == 0:
return results['user_21']
elif computer_score == 0:
return results['computer_21']
elif user_score > 21:
return results['user_over']
elif computer_score > 21:
return results['computer_over']
elif user_score > computer_score:
return results['user_win']
else:
return results['computer_win']
def game_21():
clear_screen()
print ('Game is starting....')
time.sleep(3)
user_cards = [deal_cards() for _ in range(2)]
computer_cards = [deal_cards() for _ in range (2)]
game_countinue = True
while game_countinue == True:
main_screen()
user_score = calculate_card(user_cards)
computer_score = calculate_card(computer_cards)
print (f'\nYour cards is: {user_cards}, with score: {sum(user_cards)}')
print (f"Computer's first cards: {computer_cards[0]}")
if user_score > 21 or user_score == 0 or computer_score > 21 or computer_score == 0:
game_countinue = False
else:
if input('\nGet another card? y/n: ') == 'y':
user_cards.append(deal_cards())
else:
game_countinue = False
print ('Wait... computer picks his cards.')
time.sleep(3)
while computer_score != 0 and computer_score < 17 and user_score < 21:
computer_cards.append(deal_cards())
computer_score = calculate_card(computer_cards)
input ("Press ENTER to show the results.")
main_screen()
print ('Calculating the results.....')
time.sleep(2)
print (f'\nYour final hand: {user_cards}, with score: {sum(user_cards)}')
print (f"Computer's final hand: {computer_cards}, with score: {sum(computer_cards)}\n")
print (who_win(user_score,computer_score))
input('\nPress ENTER to exit..')
clear_screen()
while input ("Choose a game to start\n_________________\n1- Foggy\n2- Twenty one\n3- Snake\n_________________\n> ") == "2":
game_21()
print ("Exiting....")