import pygame as pg
import sys
#RESOLUCIÓN
screen_width = 480
screen_height = 480
#DEFINICIÓN DE COLORES
GREEN = (113, 141, 84)
WHITE = (236, 236, 214)
GRAY = (116, 116, 116)
surf = pg.display.set_mode((screen_width, screen_height))
surf.fill(GRAY)
square_side = screen_width/8
color_squareA = GREEN
color_squareB = WHITE
chessboard = [
['BR','BH','BB','BQ','BK','BB','BH','BR'],
['BP','BP','BP','BP','BP','BP','BP','BP'],
[None,None,None,None,None,None,None,None],
[None,None,None,None,None,None,None,None],
[None,None,None,None,None,None,None,None],
[None,None,None,None,None,None,None,None],
['WP','WP','WP','WP','WP','WP','WP','WP'],
['WR','WH','WB','WQ','WK','WB','WH','WR'],
]
def DrawChessboard():
x = 0
y = 0
aux = True
for f in range(8):
x = 0
for c in range(8):
# print(y)
# print(aux)
if aux == False:
pg.draw.rect(surf, color_squareA, (x,y,square_side, square_side))
x += square_side
aux = True
else:
pg.draw.rect(surf, color_squareB, (x,y,square_side, square_side))
x += square_side
aux = False
if aux == True:
aux = False
else:
aux = True
y += square_side
def LoadChessPieces():
for i in range(8):
for j in range(8):
if chessboard[i][j] == 'WP':
img = pg.image.load("ChessPieces/chesspiece_05.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'BP':
img = pg.image.load("ChessPieces/chesspiece_11.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'WR':
img = pg.image.load("ChessPieces/chesspiece_04.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'BR':
img = pg.image.load("ChessPieces/chesspiece_10.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'WH':
img = pg.image.load("ChessPieces/chesspiece_03.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'BH':
img = pg.image.load("ChessPieces/chesspiece_09.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'WB':
img = pg.image.load("ChessPieces/chesspiece_02.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'BB':
img = pg.image.load("ChessPieces/chesspiece_08.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'WQ':
img = pg.image.load("ChessPieces/chesspiece_01.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'BQ':
img = pg.image.load("ChessPieces/chesspiece_07.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'WK':
img = pg.image.load("ChessPieces/chesspiece_00.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
if chessboard[i][j] == 'BK':
img = pg.image.load("ChessPieces/chesspiece_06.png")
img = pg.transform.scale(img,(int(square_side),int(square_side)))
surf.blit(img,(j*square_side,i*square_side))
def MovControl(x,y):
if chessboard[y][x] == 'WP':
# pg.draw.rect(surf, GRAY, (x*square_side,(y-1)*square_side,square_side, square_side))
# pg.draw.rect(surf, GRAY, (x*square_side,(y-2)*square_side,square_side, square_side))
print("Seleccionaste un peón blanco")
if chessboard[y][x] == 'BP':
print("Seleccionaste un peón negro")
if chessboard[y][x] == 'WR':
print("Seleccionaste una torre blanca")
if chessboard[y][x] == 'BR':
print("Seleccionaste una torre negra")
if chessboard[y][x] == 'WH':
print("Seleccionaste un caballo blanco")
if chessboard[y][x] == 'BH':
print("Seleccionaste un caballo negro")
if chessboard[y][x] == 'WB':
print("Seleccionaste un alfil blanco")
if chessboard[y][x] == 'BB':
print("Seleccionaste una alfil negro")
if chessboard[y][x] == 'WQ':
print("Seleccionaste una reina blanca")
if chessboard[y][x] == 'BQ':
print("Seleccionaste una reina negra")
if chessboard[y][x] == 'WK':
print("Seleccionaste un rey blanco")
if chessboard[y][x] == 'BK':
print("Seleccionaste un rey negro")
def main():
pg.init()
pg.display.set_caption("Test")
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
sys.exit()
if event.type == pg.MOUSEBUTTONDOWN:
x = int(pg.mouse.get_pos()[0]/square_side)
y = int(pg.mouse.get_pos()[1]/square_side)
MovControl(x,y)
DrawChessboard()
LoadChessPieces()
pg.display.update()
main()