-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
132 lines (108 loc) · 4.73 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import pygame
import numpy as np
import sys
# Definição das constantes
WIDTH, HEIGHT = 700, 700 # Dimensões da janela
FPS = 60
boardSize = 13 # Tamanho do tabuleiro
lineWidth = 2 # Largura das linhas
lineColor = (65, 37, 0) # Cor das linhas
backgroundColor = (217, 164, 89) # Cor de fundo
hoshiRadius = 5 # Raio dos pontos "hoshi"
HoshiColor = (65, 37, 0) # Cor dos pontos "hoshi"
boardMatrix = np.zeros((boardSize, boardSize), dtype=int)
# Carregamento das imagens
icon = pygame.image.load("./icon.png")
menuBackground = pygame.image.load("./openingScreen.png")
# Inicialização do Pygame
pygame.init()
# Configurações da janela
pygame.display.set_caption('Go!')
pygame.display.set_icon(icon)
window = pygame.display.set_mode((WIDTH, HEIGHT))
# Função para o menu
def menu():
run = True
clock = pygame.time.Clock()
while run:
clock.tick(FPS)
x, y = pygame.mouse.get_pos()
window.blit(menuBackground, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if x in range(178, 522) and y in range(246, 348):
return # Sai do menu se o botão for pressionado
if x in range(178, 522) and y in range(246, 348):
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_HAND)
else:
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)
pygame.display.flip()
# Função que desenha o tabuleiro
def drawBoard(window):
# Definir o fundo da tela
window.fill(backgroundColor)
# Desenhar linhas horizontais e verticais do tabuleiro
for i in range(boardSize):
# Desenhar linhas horizontais
pygame.draw.line(window, lineColor, (30, 30 + i * (WIDTH - 60) // (boardSize - 1)), (WIDTH - 30, 30 + i * (WIDTH - 60) // (boardSize - 1)), lineWidth)
# Desenhar linhas verticais
pygame.draw.line(window, lineColor, (30 + i * (HEIGHT - 60) // (boardSize - 1), 30), (30 + i * (HEIGHT - 60) // (boardSize - 1), HEIGHT - 30), lineWidth)
# Desenhar os pontos "hoshi" para os diferentes tamanhos de tabuleiros
if (boardSize == 9):
hoshi_points = [(2, 2), (6, 2), (2, 6), (6, 6), (4, 4)]
if (boardSize == 13):
hoshi_points = [(3, 3), (9, 3), (3, 9), (9, 9), (6, 6)]
if (boardSize == 19):
hoshi_points = [(3, 3), (9, 3), (15, 3), (3, 9), (9, 9), (15, 9), (3, 15), (9, 15), (15, 15)]
for x, y in hoshi_points:
pygame.draw.circle(window, HoshiColor, (30 + x * (WIDTH - 60) // (boardSize - 1), 30 + y * (HEIGHT - 60) // (boardSize - 1)), hoshiRadius)
# Função que desenha as pedras
def drawStone(x, y, stoneColor):
if stoneColor == "B":
pygame.draw.circle(window, (0, 0, 0), (x, y), 26) # Círculo para a pedra escura
elif stoneColor == "W":
pygame.draw.circle(window, (255, 255, 255), (x, y), 26) # Círculo para a pedra clara
# Função principal do jogo
def main():
run = True
clock = pygame.time.Clock()
stoneColor = "B"
drawBoard(window)
pygame.display.flip()
def main():
run = True
clock = pygame.time.Clock()
stoneColor = "B"
board = np.zeros((boardSize, boardSize), dtype=int) # Matriz para representar o tabuleiro
drawBoard(window)
pygame.display.flip()
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONDOWN:
mouseX, mouseY = pygame.mouse.get_pos()
# Calcular a posição do clique em termos das intersecções do tabuleiro
gridX = round((mouseX - 30) / ((WIDTH - 60) / (boardSize - 1)))
gridY = round((mouseY - 30) / ((HEIGHT - 60) / (boardSize - 1)))
if board[gridY][gridX] == 0: # Verificar se a posição está vazia na matriz
board[gridY][gridX] = 1 if stoneColor == "B" else 2 # Marcar a posição na matriz
# Calcular a posição central da intersecção para desenhar a pedra
stonePosX = 30 + gridX * ((WIDTH - 60) // (boardSize - 1))
stonePosY = 30 + gridY * ((HEIGHT - 60) // (boardSize - 1))
if stoneColor == "B":
drawStone(stonePosX, stonePosY, "B")
stoneColor = "W"
else:
drawStone(stonePosX, stonePosY, "W")
stoneColor = "B"
pygame.display.flip()
pygame.quit()
sys.exit()
if __name__ == "__main__":
menu() # Chama o menu antes do início do jogo
main() # Inicia o jogo após a seleção no menu