im making the capturing pieces part of the game and it works with the white pawn but for the black pawn it doesnt move it on the square it captured on and if selected after capturing something it captures itself
code to move white pawn:
if selected_piece.type == "pawn_w":
if mousedownY == int(selected_piece.y - 79) and mousedownX == selected_piece.x and not capture:
truMove = True
selected_piece.starter = False
elif selected_piece.starter:
for i in range(len(pieces_list)):
if pieces_list[i].square == f'{collumns[mousedownX]}{rows[mousedownY + 79]}':
clear_path = False
break
if clear_path and mousedownY == int(selected_piece.y - 158) and mousedownX == selected_piece.x and not capture:
truMove = True
selected_piece.starter = False
if capture and capture_piece.color != selected_piece.color and mousedownY == int(selected_piece.y - 79) and(mousedownX == selected_piece.x - 79 or mousedownX == selected_piece.x + 79):
capture_piece.taken = True
truMove = True
selected_piece.starter = False
code to move black pawn:
if selected_piece.type == "pawn_b":
if mousedownY == int(selected_piece.y + 79) and mousedownX == selected_piece.x and not capture:
truMove = True
selected_piece.starter = False
elif selected_piece.starter:
for i in range(len(pieces_list)):
if pieces_list[i].square == f'{collumns[mousedownX]}{rows[mousedownY - 79]}':
clear_path = False
break
if mousedownY == int(selected_piece.y + 158) and mousedownX == selected_piece.x and clear_path and not capture:
truMove = True
selected_piece.starter = False
if capture and mousedownY == int(selected_piece.y + 79) and(mousedownX == selected_piece.x - 79 or mousedownX == selected_piece.x + 79):
capture_piece.taken = True
truMove = True
selected_piece.starter = False
code that moves the pieces:
for i in range(len(pieces_list)):
if pieces_list[i].select and truMove:
moveX(pieces_list[i],pieces_list[i].x, mousedownX)
moveY(pieces_list[i],pieces_list[i].y, mousedownY)
pieces_list[i].select = False
truMove = False
break
elif mousedownX == pieces_list[i].x and mousedownY == pieces_list[i].y:
pieces_list[i].select = True
break
elif pieces_list[i].select and not truMove:
pieces_list[i].select = False
break
i honestly dont know what to try, i cant find what the problem is
New contributor
Dark Angel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.