-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameView.py
69 lines (54 loc) · 2.25 KB
/
GameView.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import pygame
from GameBoard import *
class GameView:
IMAGE_DIRECTORY = "images"
def __init__(self):
self.gamer = 1
self.gameBoard = GameBoard()
self.pyGame = pygame
pygame.init()
pygame.display.set_caption('tic-tac-toe')
self.board_picture = pygame.image.load(os.path.join(GameView.IMAGE_DIRECTORY, "board.png"))
taille_plateau_de_jeu = self.board_picture.get_size()
print('taille plateau de jeu')
print(taille_plateau_de_jeu)
print(taille_plateau_de_jeu[0])
print(taille_plateau_de_jeu[1])
self.size = (taille_plateau_de_jeu[0] * 1, taille_plateau_de_jeu[1])
self.screen = pygame.display.set_mode(self.size)
self.screen.fill((255, 255, 255))
self.screen.blit(self.board_picture, (0, 0))
pygame.display.flip()
self.crossChip = pygame.image.load(os.path.join(GameView.IMAGE_DIRECTORY, "cross.png"))
self.roundChip = pygame.image.load(os.path.join(GameView.IMAGE_DIRECTORY, "round.png"))
self.font = pygame.font.Font("freesansbold.ttf", 15)
def determine_column(self, x):
column = x + 8.75
column /= 97
if column < GameBoard.BOARD_WIDTH:
return int(column)
else:
return GameBoard.BOARD_WIDTH-1
def determine_line(self, y):
line = y + 8.4
line /= 97
if line < GameBoard.BOARD_LENGTH:
return int(line)
else:
return GameBoard.BOARD_LENGTH-1
def render(self):
self.screen.fill((255, 255, 255))
self.screen.blit(self.board_picture, (0, 0))
game_board_game_state = self.gameBoard.board
self.gameBoard.display()
for i in range(len(game_board_game_state)):
for j in range(len(game_board_game_state[i])):
if game_board_game_state[i][j] == GameBoard.ROUND_CHIP:
self.screen.blit(self.roundChip, (8.75 + 97 * j, 8.4 + 97.5 * i))
pygame.display.flip()
if game_board_game_state[i][j] == GameBoard.CROSS_CHIP:
self.screen.blit(self.crossChip, (8.75 + 97 * j, 8.4 + 97.5 * i + 1))
pygame.display.flip()