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
|
class Fen_jeu(tk.Tk):
def __init__(self, taille):
super().__init__()
# infos sur la partie
self.couleur_tour = -1
self.groupes = []
self.goban = np.zeros((taille, taille))
self.tab_boutons = [[0 for k in range(taille)] for k in range(taille)]
self.boutons = []
self.pions_captures_N = 0
self.pions_captures_B = 0
# images
self.pion_blanc = tk.PhotoImage(file="images\pion blanc.png")
self.pion_noir = tk.PhotoImage(file="images\pion noir.png")
self.goban19 = tk.PhotoImage(file="images\goban19.png")
self.goban9 = tk.PhotoImage(file="images\goban9.png")
# infos de la fenêtre
self.title("Jeu de Go")
self.creer_barre_menu()
# creation widgets
self.zone_grille = ttk.Frame(self)
self.zone_point = ttk.Frame(self)
self.zone_point.pack()
self.zone_grille.pack()
self.creer_zone_grille(taille)
self.creer_zone_point()
def creer_zone_grille(self, n):
for i in range(n):
for j in range(n):
b = ttk.Button(self.zone_grille, text=str(i) + "," + str(j), command=lambda k=i, l=j: self.tour_de_jeu((k, l)))
self.tab_boutons[i][j]= b
b.grid(row=i, column=j)
def rafraichir(self):
nouveau = np.zeros_like(self.goban)
# met la valeur de la couleur du groupe pour les positions du groupe
for g in self.groupes:
for pos in g.positions:
nouveau[pos[0], pos[1]] = g.couleur
self.goban = nouveau
# met les pions sur le plateau
self.pion_blanc = tk.PhotoImage(file="images\pion blanc.png")
self.pion_noir = tk.PhotoImage(file="images\pion noir.png")
(n,k)= np.shape(self.goban)
for i in range(n):
for j in range (n):
if self.goban[i,j] == -1:
self.tab_boutons[i][j]['image'] = self.pion_noir
elif self.goban[i,j] == 1:
self.tab_boutons[i][j]['image'] = self.pion_blanc |
Partager