import pygame
import random
import time
pygame.init()
# Oyun ekranının boyutu
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
# Renkler
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
# Yazı tipleri
FONT = pygame.font.SysFont("Arial", 32)
FONT_SMALL = pygame.font.SysFont("Arial", 24)
# Resimlerin konumları
BIRD_X = 600
BIRD_Y = 50
PLANE_X = 400
PLANE_Y = 50
FEATURE_X = 200
FEATURE_Y = 50
BIRD_GAP = 120
PLANE_GAP = 120
FEATURE_GAP = 120
# Eşleştirme durumları
MATCH_NONE = 0 # Hiçbir eşleştirme yok
MATCH_PLANE = 1 # Uçakla eşleştirildi
MATCH_FEATURE = 2 # Özellikle eşleştirildi
MATCH_BOTH = 3 # Hem uçakla hem de özellikle eşleştirildi
# Kuş sınıfı
class Bird:
def _init_(self, image, x, y):
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
def draw(self, screen):
# Ekranda resmi çiz
screen.blit(self.image, (self.x, self.y))
def drag_start(self, mouse_x, mouse_y):
# Sürükleme başlangıcında, fare konumu ile resim konumu arasındaki farkı hesapla
self.offset_x = self.x - mouse_x
self.offset_y = self.y - mouse_y
# Sürükleme durumunu True yap
self.drag = True
def drag_move(self, mouse_x, mouse_y):
# Sürükleme sırasında, resmin konumunu fare konumu ve farka göre güncelle
self.x = mouse_x + self.offset_x
self.y = mouse_y + self.offset_y
def drag_end(self):
# Sürükleme bitiminde, sürükleme durumunu False yap
self.drag = False
def match_plane(self, plane):
# Uçakla eşleştirme kontrolü
# Eğer resimlerin merkezleri arasındaki mesafe 50'den küçükse, eşleştirme başarılı say
dx = self.x + 25 - plane.x - 25
dy = self.y + 25 - plane.y - 25
distance = (dx**2 + dy**2)**0.5
if distance < 50:
# Eşleştirme durumunu güncelle
self.match = MATCH_PLANE
plane.match = MATCH_PLANE
# Resimleri birbirine yakınlaştır
self.x = plane.x + (self.x - plane.x) / distance * 50
self.y = plane.y + (self.y - plane.y) / distance * 50
# Ekranda "Doğru" yaz
screen.blit(FONT.render("Doğru", True, GREEN), (350, 300))
pygame.display.update()
# Bir saniye bekle
time.sleep(1)
else:
# Eşleştirme başarısızsa, ekranda "Tekrar Dene" yaz
screen.blit(FONT.render("Tekrar Dene", True, RED), (350, 300))
pygame.display.update()
# Bir saniye bekle
time.sleep(1)
def match_feature(self, feature):
# Özellikle eşleştirme kontrolü
# Eğer resimlerin merkezleri arasındaki mesafe 50'den küçükse, eşleştirme başarılı say
dx = self.x + 25 - feature.x - 25
dy = self.y + 25 - feature.y - 25
distance = (dx**2 + dy**2)**0.5
if distance < 50:
# Eşleştirme durumunu güncelle
self.match = MATCH_BOTH
feature.match = MATCH_BOTH
# Resimleri birbirine yakınlaştır
self.x = feature.x + (self.x - feature.x) / distance * 50
self.y = feature.y + (self.y - feature.y) / distance * 50
# Ekranda "Doğru" yaz
screen.blit(FONT.render("Doğru", True, GREEN), (350, 300))
pygame.display.update()
# Bir saniye bekle
time.sleep(1)
else:
# Eşleştirme başarısızsa, ekranda "Tekrar Dene" yaz
screen.blit(FONT.render("Tekrar Dene", True, RED), (350, 300))
pygame.display.update()
# Bir saniye bekle
time.sleep(1)
# Uçak sınıfı
class Plane:
def _init_(self, image, x, y):
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
def draw(self, screen):
# Ekranda resmi çiz
screen.blit(self.image, (self.x, self.y))
def drag_start(self, mouse_x, mouse_y):
# Sürükleme başlangıcında, fare konumu ile resim konumu arasındaki farkı hesapla
self.offset_x = self.x - mouse_x
self.offset_y = self.y - mouse_y
# Sürükleme durumunu True yap
self.drag = True
def drag_move(self, mouse_x, mouse_y):
# Sürükleme sırasındaresmin konumunu fare konumu ve farka göre güncelle
self.x = mouse_x + self.offset_x , self.y == mouse_y + self.offset_y
def drag_end(self):
# Sürükleme bitiminde, sürükleme durumunu False yap
self.drag = False
class Feature:
def init(self, image, x, y):
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
def draw(self, screen):
# Ekranda resmi çiz
screen.blit(self.image, (self.x, self.y))
def drag_start(self, mouse_x, mouse_y):
# Sürükleme başlangıcında, fare konumu ile resim konumu arasındaki farkı hesapla
self.offset_x = self.x - mouse_x
self.offset_y = self.y - mouse_y
# Sürükleme durumunu True yap
self.drag = True
def drag_move(self, mouse_x, mouse_y):
# Sürükleme sırasında, resmin konumunu fare konumu ve farka göre güncelle
self.x = mouse_x + self.offset_x
self.y = mouse_y + self.offset_y
def drag_end(self):
# Sürükleme bitiminde, sürükleme durumunu False yap
self.drag = False
# Oyun ekranını ve saatini oluştur
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Eşleştirme Oyunu")
clock = pygame.time.Clock()
class Bird:
def __init__(self, image, x, y): # Burada ikişer alt çizgi kullandık
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
# Resimleri yükle ve nesneleri oluştur
akbaba = Bird(pygame.image.load("akbaba.jpeg"), BIRD_X, BIRD_Y)
ebabil = Bird(pygame.image.load("ebabil.jpeg"), BIRD_X, BIRD_Y + BIRD_GAP)
yusufcuk = Bird(pygame.image.load("yusufçuk.jpeg"), BIRD_X, BIRD_Y + 2 * BIRD_GAP)
yunus = Bird(pygame.image.load("yunus.jpeg"), BIRD_X, BIRD_Y + 3 * BIRD_GAP)
class Plane:
def __init__(self, image, x, y): # Burada ikişer alt çizgi kullandık
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
a320 = Plane(pygame.image.load("a320.jpeg"), PLANE_X, PLANE_Y)
savas_ucagi = Plane(pygame.image.load("savas ucagi.jpeg"), PLANE_X, PLANE_Y + PLANE_GAP)
helikopter = Plane(pygame.image.load("helikopter.jpeg"), PLANE_X, PLANE_Y + 2 * PLANE_GAP)
concorde = Plane(pygame.image.load("concorde.jpeg"), PLANE_X, PLANE_Y + 3 * PLANE_GAP)
class Feature:
def __init__(self, image, x, y): # Burada ikişer alt çizgi kullandık
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
tuyyapisi = Feature(pygame.image.load("tuyyapisi.jpeg"), FEATURE_X, FEATURE_Y)
kuyrukyapisi = Feature(pygame.image.load("kuyrukyapisi.jpeg"), FEATURE_X, FEATURE_Y + FEATURE_GAP)
ucusstili = Feature(pygame.image.load("ucusstili.jpeg"), FEATURE_X, FEATURE_Y + 2 * FEATURE_GAP)
burunyapisi = Feature(pygame.image.load("burunyapisi.jpeg"), FEATURE_X, FEATURE_Y + 3 * FEATURE_GAP)
# Oyun döngüsünü başlat
running = True
while running:
# Olayları yakala ve işle
for event in pygame.event.get():
# Çıkış olayı
if event.type == pygame.QUIT:
running = False
# Fare basma olayı
if event.type == pygame.MOUSEBUTTONDOWN:
# Fare konumunu al
mouse_x, mouse_y = pygame.mouse.get_pos()
# Kuşlara tıklandıysa, sürükleme başlat
for bird in [akbaba, ebabil, yusufcuk, yunus]:
if bird.x <= mouse_x <= bird.x + 50 and bird.y <= mouse_y <= bird.y + 50:
bird.drag_start(mouse_x, mouse_y)
# Eşleştirilen kuş ve uçak çiftlerine tıklandıysa, sürükleme başlat
for bird in [akbaba, ebabil, yusufcuk, yunus]:
for plane in [a320, savas_ucagi, helikopter, concorde]:
if bird.match == MATCH_PLANE and plane.match == MATCH_PLANE:
if bird.x <= mouse_x <= bird.x + 100 and bird.y <= mouse_y <= bird.y + 50:
bird.drag_start(mouse_x, mouse_y)
plane.drag_start(mouse_x, mouse_y)
# Fare bırakma olayı
if event.type == pygame.MOUSEBUTTONUP:
# Fare konumunu al
mouse_x, mouse_y = pygame.mouse.get_pos()
# Sürüklenen kuş varsa, sürükleme bitir
for bird in [akbaba, ebabil, yusufcuk, yunus]:
if bird.drag:
bird.drag_end()
# Uçaklarla eşleştirme kontrolü yap
for plane in [a320, savas_ucagi, helikopter, concorde]:
bird.match_plane(plane)
# Sürüklenen kuş ve uçak çifti varsa, sürükleme bitir
for bird in [akbaba, ebabil, yusufcuk, yunus]:
for plane in [a320, savas_ucagi, helikopter, concorde]:
if bird.drag and plane.drag:
bird.drag_end()
plane.drag_end()
# Özelliklerle eşleştirme kontrolü yap
for feature in [tuyyapisi, kuyrukyapisi, ucusstili, burunyapisi]:
bird.match_feature(feature)
# Fare hareket olayı
if event.type == pygame.MOUSEMOTION:
# Fare konumunu al
mouse_x, mouse_y = pygame.mouse.get_pos()
# Sürüklenen kuş varsa, sürükleme hareketi yap
for bird in [akbaba, ebabil, yusufcuk, yunus]:
if bird.drag:
bird.drag_move(mouse_x, mouse_y)
# Sürüklenen kuş ve uçak çifti varsa, sürükleme hareketi yap
for bird in [akbaba, ebabil, yusufcuk, yunus]:
for plane in [a320, savas_ucagi, helikopter, concorde]:
if bird.drag and plane.drag:
bird.drag_move(mouse_x, mouse_y)
plane.drag_move(mouse_x, mouse_y)
# Ekrana beyaz renk ile doldur
screen.fill(WHITE)
class Bird:
def __init__(self, image, x, y): # Burada ikişer alt çizgi kullandık
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
def draw(self,screen):
for bird in [akbaba, ebabil, yusufcuk, yunus]:
bird.draw(screen)
class Plane:
def __init__(self, image, x, y): # Burada ikişer alt çizgi kullandık
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
def draw(self, screen):
for plane in [a320, savas_ucagi, helikopter, concorde]:
plane.draw(screen)
class Feature:
def __init__(self, image, x, y): # Burada ikişer alt çizgi kullandık
self.image = image # Resim
self.x = x # X konumu
self.y = y # Y konumu
self.match = MATCH_NONE # Eşleştirme durumu
self.drag = False # Sürükleme durumu
def draw(self, screen):
for feature in [tuyyapisi, kuyrukyapisi, ucusstili, burunyapisi]:
feature.draw(screen)
# Ekrandaki değişiklikleri güncelle
pygame.display.flip()
# Saati ayarla
clock.tick(60)
# Oyun döngüsünü bitir
pygame.quit()
Oyunun amacı öncelikle ilham alınan uçak ve kuşları eşleştirmek daha sonra ise ilham nedeniyle eşleştirip oyunu tamamlamaktır. görünürde bir hata yok gibi gözükğyor ama kod çalışmıyor. ne yapmalıyım.