-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchess.py
More file actions
145 lines (131 loc) · 5.2 KB
/
Copy pathchess.py
File metadata and controls
145 lines (131 loc) · 5.2 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
########################START LIB#########################
import os
from os import system, name
from time import sleep
from verif import *
from var import *
import pygame
from pygame.locals import *
####################Script start######################################
# main()
######################################################################
pygame.init()
# Ouverture de la fenétre Pygame
fenetre = pygame.display.set_mode((240, 240))
#Chargement et collage du fond
fond = pygame.image.load("img/background.png").convert()
fenetre.blit(fond, (0,0))
#Chargement et collage du personnage
pawnW = pygame.image.load("img/white_pawn.png").convert_alpha()
rookW = pygame.image.load("img/white_rook.png").convert_alpha()
knightW = pygame.image.load("img/white_knight.png").convert_alpha()
bishopW = pygame.image.load("img/white_bishop.png").convert_alpha()
queenW = pygame.image.load("img/white_queen.png").convert_alpha()
kingW = pygame.image.load("img/white_king.png").convert_alpha()
pawnB = pygame.image.load("img/black_pawn.png").convert_alpha()
rookB = pygame.image.load("img/black_rook.png").convert_alpha()
knightB = pygame.image.load("img/black_knight.png").convert_alpha()
bishopB = pygame.image.load("img/black_bishop.png").convert_alpha()
queenB = pygame.image.load("img/black_queen.png").convert_alpha()
kingB = pygame.image.load("img/black_king.png").convert_alpha()
taille_sprite = 30
def afficher(plate, fenetre):
num_ligne = 0
for ligne in plate:
num_case = 0
for sprite in ligne:
x = num_case * taille_sprite
y = num_ligne * taille_sprite
if sprite == 'P':
fenetre.blit(pawnB, (x, y))
elif sprite == 'T':
fenetre.blit(rookB, (x, y))
elif sprite == 'C':
fenetre.blit(knightB, (x, y))
elif sprite == 'F':
fenetre.blit(bishopB, (x, y))
elif sprite == 'D':
fenetre.blit(queenB, (x, y))
elif sprite == 'R':
fenetre.blit(kingB, (x, y))
elif sprite == 'p':
fenetre.blit(pawnW, (x, y))
elif sprite == 't':
fenetre.blit(rookW, (x, y))
elif sprite == 'c':
fenetre.blit(knightW, (x, y))
elif sprite == 'f':
fenetre.blit(bishopW, (x, y))
elif sprite == 'd':
fenetre.blit(queenW, (x, y))
elif sprite == 'r':
fenetre.blit(kingW, (x, y))
num_case += 1
num_ligne +=1
afficher(plate, fenetre)
# Rafraichissement de l'écran
pygame.display.flip()
chessIsRun = 1
# BOUCLE INFINIE
while chessIsRun:
continuer = 1
reloop = False
chessIsRun = True
turns = "Black"
while turns == "Black":
chesspi = []
platePrint(plate)
loopget = 0
continuer = 1
getMove(turns)
while continuer:
for event in pygame.event.get(): # Attente des événements
if event.type == QUIT:
continuer = 0
if event.type == MOUSEBUTTONDOWN and event.button == 1 and loopget == 0:
print((event.pos[0] // 30) + 1, 8 - (event.pos[1] // 30))
loopget += 1
chesspi.append(((event.pos[0] // 30), 8 - (event.pos[1] // 30)))
if event.type == MOUSEBUTTONDOWN and event.button == 3 and loopget == 1:
print((event.pos[0] // 30) + 1, 8 - (event.pos[1] // 30))
chesspi.append(((event.pos[0] // 30), 8 - (event.pos[1] // 30)))
print(chesspi)
print("move",plate[-int(chesspi[0][1])][chesspi[0][0]],"in",chesspi[0],"to",chesspi[1])
continuer = 0
#intp = getMove(turns)
error("clear")
verif(chesspi, pieceN, pieceB, turns)
if error("get") == 0:
turns = 'White'
fenetre.blit(fond, (0, 0))
afficher(plate, fenetre)
# Rafraichissement de l'écran
pygame.display.flip()
while turns == "White":
chesspi = []
platePrint(plate)
loopget = 0
continuer = 1
getMove(turns)
while continuer:
for event in pygame.event.get(): # Attente des événements
if event.type == QUIT:
continuer = 0
if event.type == MOUSEBUTTONDOWN and event.button == 1 and loopget == 0:
print((event.pos[0] // 30), 8 - (event.pos[1] // 30))
loopget += 1
chesspi.append(((event.pos[0] // 30), 8 - (event.pos[1] // 30)))
if event.type == MOUSEBUTTONDOWN and event.button == 3 and loopget == 1:
print((event.pos[0] // 30), 8 - (event.pos[1] // 30))
chesspi.append(((event.pos[0] // 30), 8 - (event.pos[1] // 30)))
print(chesspi)
continuer = 0
#intp = getMove(turns)
error("clear")
verif(chesspi, pieceB, pieceN, turns)
if error("get") == 0:
turns = 'Black'
fenetre.blit(fond, (0, 0))
afficher(plate, fenetre)
# Rafraichissement de l'écran
pygame.display.flip()