|
| 1 | +import pygame |
| 2 | +from os import path |
| 3 | +from TicTacToe import Grid |
| 4 | + |
| 5 | + |
| 6 | +class Game: |
| 7 | + def __init__(self, *assetPath): |
| 8 | + self.clock = pygame.time.Clock() |
| 9 | + self.running = True |
| 10 | + |
| 11 | + self.assets = {} |
| 12 | + self.loadAssets(*assetPath) |
| 13 | + |
| 14 | + self.WINDOW_WIDTH = 400 |
| 15 | + self.WINDOW_HEIGHT = 400 |
| 16 | + self.window = pygame.display.set_mode((self.WINDOW_WIDTH, self.WINDOW_HEIGHT)) |
| 17 | + |
| 18 | + pygame.init() |
| 19 | + |
| 20 | + while self.running: |
| 21 | + self.clock.tick(100) |
| 22 | + self.handleEvents() |
| 23 | + self.redraw() |
| 24 | + |
| 25 | + def redraw(self): |
| 26 | + pygame.draw.rect(self.window, (255, 255, 255), (50, 75, 300, 300)) |
| 27 | + self.window.blit(self.assets['VLine'], (50 - 5 + 100, 75)) |
| 28 | + self.window.blit(self.assets['VLine'], (50 - 5 + 200, 75)) |
| 29 | + self.window.blit(self.assets['HLine'], (50, 75 + 100)) |
| 30 | + self.window.blit(self.assets['HLine'], (50, 75 + 200)) |
| 31 | + self.window.blit(self.assets['O'], (50, 80)) |
| 32 | + self.window.blit(self.assets['O'], (50 + 1 * 100, 80 + 1 * 100)) |
| 33 | + self.window.blit(self.assets['X'], (50 + 1 * 100, 80 + 2 * 100)) |
| 34 | + pygame.display.update() |
| 35 | + |
| 36 | + def handleEvents(self): |
| 37 | + for event in pygame.event.get(): |
| 38 | + if event.type == pygame.QUIT: self.running = False |
| 39 | + |
| 40 | + def loadAssets(self, *assetsPath): |
| 41 | + |
| 42 | + self.assets['VLine'] = pygame.image.load(path.join(*assetsPath, 'line.png')) |
| 43 | + self.assets['HLine'] = pygame.transform.rotate(self.assets['VLine'], 90) |
| 44 | + self.assets['X'] = pygame.image.load(path.join(*assetsPath, 'X.png')) |
| 45 | + self.assets['O'] = pygame.image.load(path.join(*assetsPath, 'O.png')) |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == '__main__': |
| 49 | + Game('resources') |
0 commit comments