import pygame import time import random import ctypes pygame.init() ekran = pygame.display.set_mode((600, 600)) pygame.display.set_caption("Papież i kremówki") zegar = pygame.time.Clock() papiez = pygame.image.load("papiez.jpg") kremowki = pygame.image.load("kremowki.jpg") dzwiek = pygame.mixer.Sound("Windows XP Shutdown.wav") error = pygame.mixer.Sound("Windows XP Critical Stop.wav") plansza = [ [' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' '] ] kliknieto_x = False teraz_ruch = 'P' while not kliknieto_x: for event in pygame.event.get(): if event.type == pygame.QUIT: kliknieto_x = True pressed = pygame.mouse.get_pressed() pos = pygame.mouse.get_pos() if pressed[0]: x = pos[0]//200 y = pos[1]//200 if plansza[y][x] == ' ': plansza[y][x] = teraz_ruch if teraz_ruch == 'P': teraz_ruch = 'K' else: teraz_ruch = 'P' ekran.fill(0xFFFFFF) # komputer if teraz_ruch == 'K': x = random.randint(0, 2) y = random.randint(0, 2) if plansza[y][x] == ' ': plansza[y][x] = 'K' teraz_ruch = 'P' koniec_gry = True for y in range(3): for x in range(3): znaczek = plansza[y][x] if znaczek == 'P': ekran.blit(papiez, (x*200, y*200)) if znaczek == 'K': ekran.blit(kremowki, (x*200, y*200)) if znaczek == ' ': koniec_gry = False pygame.draw.line(ekran, random.randint(0x000000, 0xFFFFFF), (200, 0), (200, 600), 10) pygame.draw.line(ekran, random.randint(0x000000, 0xFFFFFF), (400, 0), (400, 600), 10) pygame.draw.line(ekran, random.randint(0x000000, 0xFFFFFF), (0, 200), (600, 200), 10) pygame.draw.line(ekran, random.randint(0x000000, 0xFFFFFF), (0, 400), (600, 400), 10) for y in range(3): if plansza[y][0] == plansza[y][1] and plansza[y][1] == plansza[y][2] and plansza[y][0] != ' ': dzwiek.play() pygame.draw.line(ekran, 0x00FF00, (100, 100+200*y), (500, 100+200*y), 25) ctypes.windll.user32.MessageBoxW(0, "Wygrał "+plansza[y][0], "Papież i kremówki", 0) kliknieto_x = True for x in range(3): if plansza[0][x] == plansza[1][x] and plansza[1][x] == plansza[2][x] and plansza[0][x] != ' ': kliknieto_x = True dzwiek.play() pygame.draw.line(ekran, 0x00FF00, (100+200*x, 100), (100+200*x, 500), 25) ctypes.windll.user32.MessageBoxW(0, "Wygrał "+plansza[0][x], "Papież i kremówki", 0) if plansza[0][0] == plansza[1][1] and plansza[1][1] == plansza[2][2] and plansza[0][0] != ' ': dzwiek.play() pygame.draw.line(ekran, 0x00FF00, (100, 100), (500, 500), 25) ctypes.windll.user32.MessageBoxW(0, "Wygrał "+plansza[0][0], "Papież i kremówki", 0) kliknieto_x = True if plansza[0][2] == plansza[1][1] and plansza[1][1] == plansza[2][0] and plansza[0][2] != ' ': dzwiek.play() pygame.draw.line(ekran, 0x00FF00, (100, 500), (500, 100), 25) ctypes.windll.user32.MessageBoxW(0, "Wygrał "+plansza[0][2], "Papież i kremówki", 0) kliknieto_x = True if koniec_gry and not kliknieto_x: error.play() ctypes.windll.user32.MessageBoxW(0, "Koniec gry", "Papież i kremówki", 0) kliknieto_x = True pygame.display.flip() zegar.tick(60) time.sleep(1) pygame.quit()