Code:
Code: Alles auswählen
import pygame
import numpy as np
from enum import Enum
class Color(Enum):
BG = (0, 186, 150)
GREY = (54, 54, 54)
COLOR_LINES = (0, 130, 111)
WHITE = (255, 255, 245)
class Game:
WINDOW_WIDTH = 1000
WINDOW_HEIGHT = 1000
SQUARE_SIZE = WINDOW_HEIGHT/3
def __init__(self):
self.grid = np.zeros(((3, 3)))
self.grid[1,1] = 1
self.screen = pygame.display.set_mode((self.WINDOW_WIDTH, self.WINDOW_HEIGHT))
self.screen.fill(Color.BG.value)
pygame.display.set_caption("Tic Tac Toe")
self.clock = pygame.time.Clock()
def draw_lines(self):
for i in range(1, 3):
pygame.draw.lines(self.screen, Color.COLOR_LINES.value, False, ((0 + 50, i * self.WINDOW_WIDTH/3), (self.WINDOW_WIDTH - 50, i * self.WINDOW_HEIGHT/3)), 10) # horizontal lines
pygame.draw.lines(self.screen, Color.COLOR_LINES.value, False, ((i * self.WINDOW_WIDTH/3, 0 + 50), (i * self.WINDOW_WIDTH/3, self.WINDOW_HEIGHT - 50)), 10) # vertical lines
def draw_figures(self):
for row in range(3):
for col in range(3):
if self.grid[row, col] == 1:
pygame.draw.circle(self.screen, Color.WHITE.value, (int(col*self.SQUARE_SIZE+self.SQUARE_SIZE//2), int(row * self.SQUARE_SIZE + self.SQUARE_SIZE//2 )), 100, 15)
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
self.draw_lines()
self.draw_figures
pygame.display.update()
self.clock.tick(60)
if __name__ == "__main__":
game = Game()
game.run()