-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMove.cpp
More file actions
44 lines (40 loc) · 1.49 KB
/
Move.cpp
File metadata and controls
44 lines (40 loc) · 1.49 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
#include "Move.h"
#include "Board.h"
#include "Piece.h"
#include <iostream>
// Constructor to initialize the move and set the captured piece (if any)
Move::Move(int startX, int startY, int endX, int endY, Piece* captured) : captured_piece(captured), startX(startX), startY(startY), endX(endX), endY(endY) {}
void Move::execute(Board& board) {
// Retrieve the piece from the starting position
Piece* movingPiece = board.getPieceAt(startX, startY);
if (movingPiece) {
// Move the piece on the board
board.movePiece(*this);
// If there is a captured piece, delete it
if (captured_piece) {
delete captured_piece;
}
}
return;
}
// Check if the move targets the specified piece
bool Move::isTargeted(Piece *piece) {
if (endX == piece->getX() && endY == piece->getY()) {
return true;
}
return false;
}
// Draw the move as a highlighted circle on the board
void Move::draw(sf::RenderWindow& window) {
sf::CircleShape highlightedCircle(15);
// Set the position of the highlighted circle
highlightedCircle.setPosition(endX * 100 + 35, endY * 100 + 35);
// Set the color based on whether a piece was captured or not
if (captured_piece == nullptr) {
highlightedCircle.setFillColor(sf::Color(80, 80, 80, 200)); // Grey color
} else {
highlightedCircle.setFillColor(sf::Color(194, 24, 7, 130)); // Red color for capture
}
// Draw the highlighted circle
window.draw(highlightedCircle);
}