Masa - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Masa.php
- import pygame
- # Ekran boyutları
- SCREEN_WIDTH = 800
- SCREEN_HEIGHT = 600
- # Renkler
- WHITE = (255, 255, 255)
- BLACK = (0, 0, 0)
- RED = (255, 0, 0)
- GREEN = (0, 255, 0)
- # Oyun nesneleri
- class MasaTenisiOyunu():
- def __init__(self):
- # Pygame'i başlat
- pygame.init()
- # Ekranı oluştur
- self.ekran = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
- # Saat nesnesi
- self.saat = pygame.time.Clock()
- # Raketler
- self.raket1 = pygame.Rect(100, SCREEN_HEIGHT / 2 - 50, 10, 100)
- self.raket2 = pygame.Rect(SCREEN_WIDTH - 110, SCREEN_HEIGHT / 2 - 50, 10, 100)
- # Top
- self.top = pygame.Rect(SCREEN_WIDTH / 2 - 10, SCREEN_HEIGHT / 2 - 10, 20, 20)
- # Oyun döngüsü
- while True:
- # Olayları işle
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- sys.exit()
- # Tuşlara basma kontrolü
- keys = pygame.key.get_pressed()
- if keys[pygame.K_UP]:
- self.raket1.y -= 5
- if keys[pygame.K_DOWN]:
- self.raket1.y += 5
- # Topun hareketini kontrol et
- self.top.x += 5
- if self.top.x > SCREEN_WIDTH - 20:
- # Top sağ taraftan çıktı
- self.top.x = SCREEN_WIDTH / 2 - 10
- self.top.y = SCREEN_HEIGHT / 2 - 10
- # Topun raketlerle çarpışmasını kontrol et
- if self.top.colliderect(self.raket1):
- self.top.x -= 5
- elif self.top.colliderect(self.raket2):
- self.top.x += 5
- # Ekranı temizle
- self.ekran.fill(WHITE)
- # Oyun nesnelerini çiz
- pygame.draw.rect(self.ekran, BLACK, self.raket1)
- pygame.draw.rect(self.ekran, BLACK, self.raket2)
- pygame.draw.rect(self.ekran, RED, self.top)
- # Ekranı güncelle
- pygame.display.update()
- # Saat ayarlama
- self.saat.tick(60)
- # Oyunu başlat
- oyun = MasaTenisiOyunu()