import pygame
import sys
# Ekran boyutları
EKRAN_GENISLIK = 800
EKRAN_YUKSEKLIK = 600
# Renkler
BEYAZ = (255, 255, 255)
YESIL = (0, 128, 0)
SARI = (255, 255, 0)
def menu_ciz(ekran):
"""Başlangıç menüsünü çizer."""
ekran.fill(YESIL) # Arkaplanı yeşil yap
# "Oyna" tuşunu çiz
oyna_buton = pygame.Rect(300, 250, 200, 100)
pygame.draw.rect(ekran, SARI, oyna_buton)
# "Oyna" yazısını çiz
font = pygame.font.SysFont(None, 48)
oyna_yazi = font.render("Oyna", True, BEYAZ)
yazi_rect = oyna_yazi.get_rect(center=oyna_buton.center)
ekran.blit(oyna_yazi, yazi_rect)
def oyun_ekrani_ciz(ekran):
"""Oyun ekranını çizer."""
ekran.fill(YESIL)
import random
def create_deck():
"""Desteyi oluşturur."""
suits = ['Hearts', 'Diamonds', 'Clubs', 'Spades']
ranks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace']
deck = [{'rank': rank, 'suit': suit} for suit in suits for rank in ranks]
random.shuffle(deck)
return deck
def calculate_total(hand):
"""Eldeki kartların toplam değerini hesaplar."""
total = 0
num_aces = 0
for card in hand:
if card['rank'] in ['Jack', 'Queen', 'King']:
total += 10
elif card['rank'] == 'Ace':
num_aces += 1
total += 11
else:
total += int(card['rank'])
while total > 21 and num_aces:
total -= 10
num_aces -= 1
return total
def display_cards(hand, player_name):
"""Kartları ekrana yazar."""
print(f"{player_name}'s Hand:")
for card in hand:
print(f"{card['rank']} of {card['suit']}")
def blackjack():
"""Blackjack oyununu yürütür."""
deck = create_deck()
player_hand = [deck.pop(), deck.pop()]
dealer_hand = [deck.pop(), deck.pop()]
display_cards(player_hand, "Player")
player_total = calculate_total(player_hand)
print(f"Total: {player_total}")
display_cards(dealer_hand, "Dealer")
dealer_total = calculate_total(dealer_hand)
print(f"Dealer's Total: {dealer_total}")
while player_total < 21:
action = input("Do you want to (h)it or (s)tand? ")
if action.lower() == 'h':
player_hand.append(deck.pop())
display_cards(player_hand, "Player")
player_total = calculate_total(player_hand)
print(f"Total: {player_total}")
if player_total > 21:
print("Bust! You lose.")
return
elif action.lower() == 's':
break
while dealer_total < 17:
dealer_hand.append(deck.pop())
dealer_total = calculate_total(dealer_hand)
display_cards(dealer_hand, "Dealer")
print(f"Dealer's Total: {dealer_total}")
if dealer_total > 21 or (player_total <= 21 and player_total > dealer_total):
print("You win!")
elif player_total == dealer_total:
print("Push! It's a tie.")
else:
print("Dealer wins.")
blackjack()
pygame.display.flip()
clock.tick(60)
pygame.quit()
sys.exit()
if __name__ == "__main__":
main()