Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <vector>
- #include <Windows.h>
- namespace ChessApp {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Collections::Generic;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- // Оголошення класу фігури
- class ChessPiece {
- protected:
- public:
- bool isBlack; // true for white pieces, false for black pieces
- int capturedPositionX;
- int capturedPositionY;
- // Constructor to set the color of the piece
- ChessPiece(bool isBlack) : isBlack(isBlack) {}
- virtual bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) = 0;
- void Capture(int x, int y)
- {
- capturedPositionX = x;
- capturedPositionY = y;
- }
- };
- // Оголошення класу фігури Канцлер
- class Chancellor : public ChessPiece {
- public:
- Chancellor(bool isBlack) : ChessPiece(isBlack) {}
- bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) {
- // Chancellor moves like a combination of a Rook and a Knight
- int dx = abs(fromX - toX);
- int dy = abs(fromY - toY);
- // Check if the move is like a Knight (L-shaped)
- if ((dx == 2 && dy == 1) || (dx == 1 && dy == 2)) {
- // A Knight-like move is valid, check if the destination cell is empty or has an opponent's piece
- ChessPiece* targetPiece = board[toX][toY];
- return targetPiece == nullptr || (targetPiece->isBlack != isBlack);
- }
- // Check if the move is like a Rook (horizontally or vertically)
- if ((dx == 0 && dy > 0) || (dx > 0 && dy == 0)) {
- // A Rook-like move is valid, check for obstacles along the path
- int stepX = (toX > fromX) ? 1 : (toX < fromX) ? -1 : 0;
- int stepY = (toY > fromY) ? 1 : (toY < fromY) ? -1 : 0;
- int x = fromX + stepX;
- int y = fromY + stepY;
- while (x != toX || y != toY) {
- if (board[x][y] != nullptr) {
- // There is an obstacle in the way, move is invalid
- return false;
- }
- x += stepX;
- y += stepY;
- }
- // Check if the destination cell is empty or has an opponent's piece
- ChessPiece* targetPiece = board[toX][toY];
- return targetPiece == nullptr || (targetPiece->isBlack != isBlack);
- }
- return false; // Invalid move for the Chancellor
- }
- };
- // Оголошення класу фігури Архієпископ
- class Archbishop : public ChessPiece {
- public:
- Archbishop(bool isBlack) : ChessPiece(isBlack) {}
- bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) {
- // Archbishop moves like a combination of a Bishop and a Knight
- int dx = abs(fromX - toX);
- int dy = abs(fromY - toY);
- // Check if the move is like a Knight (L-shaped)
- if ((dx == 2 && dy == 1) || (dx == 1 && dy == 2)) {
- // A Knight-like move is valid, check if the destination cell is empty or has an opponent's piece
- ChessPiece* targetPiece = board[toX][toY];
- return targetPiece == nullptr || (targetPiece->isBlack != isBlack);
- }
- // Check if the move is like a Bishop (diagonally)
- if (dx == dy) {
- // A Bishop-like move is valid, check for obstacles along the path
- int stepX = (toX > fromX) ? 1 : (toX < fromX) ? -1 : 0;
- int stepY = (toY > fromY) ? 1 : (toY < fromY) ? -1 : 0;
- int x = fromX + stepX;
- int y = fromY + stepY;
- while (x != toX || y != toY) {
- if (board[x][y] != nullptr) {
- // There is an obstacle in the way, move is invalid
- return false;
- }
- x += stepX;
- y += stepY;
- }
- // Check if the destination cell is empty or has an opponent's piece
- ChessPiece* targetPiece = board[toX][toY];
- return targetPiece == nullptr || (targetPiece->isBlack != isBlack);
- }
- return false; // Invalid move for the Archbishop
- }
- };
- // Оголошення класу фігури Слон
- class Bishop : public ChessPiece {
- public:
- Bishop(bool isBlack) : ChessPiece(isBlack) {}
- bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) {
- // Bishop moves diagonally
- int dx = abs(fromX - toX);
- int dy = abs(fromY - toY);
- if (dx != dy) {
- return false; // Bishop can only move diagonally
- }
- // Check if there are any pieces in the path
- int xDir = (toX > fromX) ? 1 : -1;
- int yDir = (toY > fromY) ? 1 : -1;
- int x = fromX + xDir;
- int y = fromY + yDir;
- while (x != toX && y != toY) {
- if (x < 0 || x >= 10 || y < 0 || y >= 8) {
- return false; // Out of bounds
- }
- if (board[x][y] != nullptr) {
- return false; // There is a piece in the path
- }
- x += xDir;
- y += yDir;
- }
- // Check if the destination position is empty or has an opponent's piece
- if (x < 0 || x >= 10 || y < 0 || y >= 8) {
- return false; // Out of bounds
- }
- ChessPiece* destinationPiece = board[x][y];
- if (destinationPiece != nullptr && destinationPiece->isBlack == isBlack) {
- return false; // Cannot capture own piece
- }
- return true;
- }
- };
- // Оголошення класу фігури Король
- class King : public ChessPiece {
- public:
- King(bool isBlack) : ChessPiece(isBlack) {}
- bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) {
- // King moves one square in any direction
- int dx = abs(fromX - toX);
- int dy = abs(fromY - toY);
- return (dx <= 1 && dy <= 1);
- }
- };
- // Оголошення класу фігури Королева
- class Queen : public ChessPiece {
- public:
- Queen(bool isBlack) : ChessPiece(isBlack) {}
- bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) {
- // Queen moves like a combination of a Rook and a Bishop
- int dx = abs(fromX - toX);
- int dy = abs(fromY - toY);
- // Check if the move is along a straight line or diagonal
- if (!((fromX == toX && fromY != toY) || (fromX != toX && fromY == toY) || (dx == dy))) {
- return false;
- }
- // Check for obstacles along the path (straight or diagonal)
- int stepX = (toX == fromX) ? 0 : (toX > fromX) ? 1 : -1;
- int stepY = (toY == fromY) ? 0 : (toY > fromY) ? 1 : -1;
- int x = fromX + stepX;
- int y = fromY + stepY;
- while (x != toX || y != toY) {
- if (board[x][y] != nullptr) {
- // There is an obstacle in the way, move is invalid
- return false;
- }
- x += stepX;
- y += stepY;
- }
- return true;
- }
- };
- // Оголошення класу фігури Ладья (Rook)
- class Rook : public ChessPiece {
- public:
- Rook(bool isBlack) : ChessPiece(isBlack) {}
- bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) override {
- // Rook moves along a straight line (horizontal or vertical)
- int dx = abs(fromX - toX);
- int dy = abs(fromY - toY);
- // Check if the move is along a straight line
- if (!((fromX == toX && fromY != toY) || (fromX != toX && fromY == toY))) {
- return false;
- }
- // Check for obstacles along the path
- int stepX = (toX == fromX) ? 0 : (toX > fromX) ? 1 : -1;
- int stepY = (toY == fromY) ? 0 : (toY > fromY) ? 1 : -1;
- int x = fromX + stepX;
- int y = fromY + stepY;
- while (x != toX || y != toY) {
- if (board[x][y] != nullptr) {
- // There is an obstacle in the way, move is invalid
- return false;
- }
- x += stepX;
- y += stepY;
- }
- return true;
- }
- };
- // Оголошення класу фігури Конь (Knight)
- class Knight : public ChessPiece {
- public:
- Knight(bool isBlack) : ChessPiece(isBlack) {}
- bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) override {
- // Логіка перевірки ходу Коня (Knight)
- // Реалізуйте правила руху для фігури Коня (Knight)
- // Рух Коня може бути здійснений у вигляді букви "L" (дві клітинки по одній осі і одна по іншій)
- int dx = abs(fromX - toX);
- int dy = abs(fromY - toY);
- return (dx == 2 && dy == 1) || (dx == 1 && dy == 2);
- }
- };
- // Оголошення класу фігури Пішак
- class Pawn : public ChessPiece {
- public:
- Pawn(bool isBlack) : ChessPiece(isBlack) {}
- bool isValidMove(int fromX, int fromY, int toX, int toY, std::vector<std::vector<ChessPiece*>>& board) {
- int dx = abs(fromX - toX);
- int dy = abs(fromY - toY);
- if (board[fromX][fromY] == nullptr) {
- return false; // No piece to move
- }
- if (isBlack) {
- if (fromX == toX && fromY == toY - 1 && board[toX][toY] == nullptr) {
- return true; // Move one square forward
- }
- if (fromX == toX - 1 && fromY == toY - 1 && board[toX][toY] != nullptr && !board[toX][toY]->isBlack) {
- return true; // Capture diagonally to the left
- }
- if (fromX == toX + 1 && fromY == toY - 1 && board[toX][toY] != nullptr && !board[toX][toY]->isBlack) {
- return true; // Capture diagonally to the right
- }
- if (fromY == 1 && toY == 3 && fromX == toX && board[toX][toY] == nullptr && board[toX][toY - 1] == nullptr) {
- return true; // Move two squares forward on the first move
- }
- }
- else {
- if (fromX == toX && fromY == toY + 1 && board[toX][toY] == nullptr) {
- return true; // Move one square forward
- }
- if (fromX == toX - 1 && fromY == toY + 1 && board[toX][toY] != nullptr && board[toX][toY]->isBlack) {
- return true; // Capture diagonally to the left
- }
- if (fromX == toX + 1 && fromY == toY + 1 && board[toX][toY] != nullptr && board[toX][toY]->isBlack) {
- return true; // Capture diagonally to the right
- }
- if (fromY == 6 && toY == 4 && fromX == toX && board[toX][toY] == nullptr && board[toX][toY + 1] == nullptr) {
- return true; // Move two squares forward on the first move
- }
- }
- return false;
- }
- };
- // Оголошення класу дошки
- class ChessBoard {
- private:
- std::vector<std::vector<ChessPiece*>> board;
- public:
- ChessBoard() : board(10, std::vector<ChessPiece*>(8, nullptr)) {
- // Початкове розташування фігур на дошці
- board[0][0] = new Rook(true); // Ладья
- board[1][0] = new Knight(true); // Конь
- board[2][0] = new Archbishop(true); // Архієпископ
- board[3][0] = new Bishop(true); // Слон
- board[4][0] = new Queen(true); // Королева
- board[5][0] = new King(true); // Король
- board[6][0] = new Bishop(true); // Слон
- board[7][0] = new Chancellor(true); // Канцлер
- board[8][0] = new Knight(true); // Конь
- board[9][0] = new Rook(true); // Ладья
- // Вторая линия фигур (белые пешки)
- for (int y = 0; y < 10; y++) {
- board[y][1] = new Pawn(true); // Пішаки (другая лінія)
- }
- // Седьмая линия фигур (черные пешки)
- for (int y = 0; y < 10; y++) {
- board[y][6] = new Pawn(false); // Пішаки (сьома лінія)
- }
- // Восьмая линия фигур (черные фигуры)
- board[0][7] = new Rook(false); // Ладья
- board[1][7] = new Knight(false); // Конь
- board[2][7] = new Archbishop(false); // Архієпископ
- board[3][7] = new Bishop(false); // Слон
- board[4][7] = new Queen(false); // Королева
- board[5][7] = new King(false); // Король
- board[6][7] = new Bishop(false); // Слон
- board[7][7] = new Chancellor(false); // Канцлер
- board[8][7] = new Knight(false); // Конь
- board[9][7] = new Rook(false); // Ладья
- }
- ~ChessBoard() {
- // Звільняємо пам'ять від фігур
- for (int i = 0; i < 8; i++) {
- for (int j = 0; j < 8; j++) {
- delete board[i][j];
- }
- }
- }
- ChessPiece* getPiece(int x, int y) {
- // Метод для отримання фігури на позиції (x, y) на дошці
- // Повертає nullptr, якщо клітинка порожня
- if (x >= 0 && x < 10 && y >= 0 && y < 8) {
- return board[x][y];
- }
- return nullptr;
- }
- bool makeMove(int fromX, int fromY, int toX, int toY) {
- // Метод для здійснення ходу
- if (!isValidMove(fromX, fromY, toX, toY)) {
- return false;
- }
- ChessPiece* piece = board[fromX][fromY];
- board[fromX][fromY] = nullptr;
- board[toX][toY] = piece;
- return true;
- }
- bool isValidMove(int fromX, int fromY, int toX, int toY) {
- // Метод для перевірки чи дозволений хід фігури з позиції (fromX, fromY) на позицію (toX, toY)
- // Включає логіку перевірки правил руху для конкретної фігури
- // Перевірка чи позиції відповідають допустимому діапазону
- if (fromX < 0 || fromX >= 10 || fromY < 0 || fromY >= 8 ||
- toX < 0 || toX >= 10 || toY < 0 || toY >= 8) {
- return false;
- }
- // Перевірка чи на позиції (fromX, fromY) є фігура
- ChessPiece* piece = board[fromX][fromY];
- if (piece == nullptr) {
- return false;
- }
- // Перевірка чи хід є допустимим для даної фігури
- if (!piece->isValidMove(fromX, fromY, toX, toY, board)) {
- return false;
- }
- // Перевірка, чи на позиції (toX, toY) є фігура того ж кольору
- ChessPiece* targetPiece = board[toX][toY];
- if (targetPiece != nullptr && targetPiece->isBlack == piece->isBlack) {
- return false;
- }
- // Тут можна додати інші перевірки, такі як перевірка на шах, коректний хід пішака,
- // правила рокіровки, взяття фігур і т.д.
- return true;
- }
- bool movePiece(int fromX, int fromY, int toX, int toY) {
- // Здійснюємо хід фігурою
- if (fromX < 0 || fromX >= 8 || fromY < 0 || fromY >= 8 || toX < 0 || toX >= 8 || toY < 0 || toY >= 8) {
- return false; // За межами дошки
- }
- ChessPiece* piece = board[fromX][fromY];
- if (piece == nullptr) {
- return false; // Немає фігури для переміщення
- }
- if (piece->isValidMove(fromX, fromY, toX, toY, board)) {
- delete board[toX][toY];
- board[toX][toY] = piece;
- board[fromX][fromY] = nullptr;
- return true;
- }
- return false;
- }
- };
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- // Ініціалізація гри
- board = new ChessBoard();
- // Ініціалізація capturedPieces
- capturedPieces = gcnew array<PictureBox^>(32);
- // Ініціалізація panelCaptured
- panelCaptured = gcnew Panel();
- panelCaptured->Location = System::Drawing::Point(10, 500); // Змініть координати на відповідні
- panelCaptured->Size = System::Drawing::Size(300, 100); // Змініть розмір на відповідний
- panelCaptured->BorderStyle = BorderStyle::FixedSingle;
- this->Controls->Add(panelCaptured);
- InitializeChessboard();
- // Підписка на події кліків по клітинках
- for (int x = 0; x < 10; x++) {
- for (int y = 0; y < 8; y++) {
- boardPictureBoxes[x, y]->Click += gcnew EventHandler(this, &MyForm::Cell_Click);
- }
- }
- }
- protected:
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private:
- System::ComponentModel::Container^ components;
- // Графічний інтерфейс
- array<PictureBox^, 2>^ boardPictureBoxes;
- ChessBoard* board;
- Graphics^ g;
- int selectedX = -1; // Stores the X coordinate of the selected piece
- int selectedY = -1; // Stores the Y coordinate of the selected piece
- // Додаткові поля для зберігання інформації про допустимі ходи для вибраної фігури
- bool validMovesHighlighted = false;
- List<Tuple<int, int>^>^ validMoves = gcnew List<Tuple<int, int>^>();
- array<PictureBox^>^ capturedPieces; // New array to hold the captured pieces
- Panel^ panelCaptured; // Panel to display captured pieces
- const int imageWidth = 40; // Зменшені розміри фігур по ширині
- const int imageHeight = 40; // Зменшені розміри фігур по висоті
- void InitializeComponent(void)
- {
- this->components = gcnew System::ComponentModel::Container();
- this->Size = System::Drawing::Size(820, 660);
- this->Text = L"MyForm";
- this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- // Створення PictureBox для клітинок шахівниці
- boardPictureBoxes = gcnew array<PictureBox^, 2>(10, 8);
- for (int x = 0; x < 10; x++) {
- for (int y = 0; y < 8; y++) {
- boardPictureBoxes[x, y] = gcnew PictureBox();
- boardPictureBoxes[x, y]->Size = System::Drawing::Size(60, 60);
- boardPictureBoxes[x, y]->Location = System::Drawing::Point(x * 60, y * 60);
- boardPictureBoxes[x, y]->BackColor = ((x + y) % 2 == 0) ? Color::Bisque : Color::DarkOrange;
- this->Controls->Add(boardPictureBoxes[x, y]);
- }
- }
- }
- // Method to update the captured pieces display
- void DrawCapturedPieces()
- {
- // Clear the captured pieces panel before redrawing
- panelCaptured->Controls->Clear();
- int x = 0;
- int y = 0;
- // Loop through the captured pieces array and add PictureBoxes to the panel
- for (int i = 0; i < capturedPieces->Length; i++)
- {
- if (capturedPieces[i] != nullptr)
- {
- capturedPieces[i]->Location = System::Drawing::Point(x, y);
- panelCaptured->Controls->Add(capturedPieces[i]);
- x += capturedPieces[i]->Width + 5;
- // Move to the next row after every 4 pieces
- if ((i + 1) % 4 == 0)
- {
- x = 0;
- y += capturedPieces[i]->Height + 5;
- }
- }
- }
- }
- void UpdateCapturedPiecesDisplay() {
- // Display the captured pieces on the form
- int capturedCount = 0;
- for (int x = 0; x < 10; x++) {
- for (int y = 0; y < 8; y++) {
- ChessPiece* piece = board->getPiece(x, y);
- if (piece != nullptr && piece->isBlack != board->getPiece(selectedX, selectedY)->isBlack) {
- // The piece at (x, y) is an opponent's piece captured by the current player
- Image^ capturedImage = LoadImageForPiece(piece, x, y);
- capturedPieces[capturedCount]->Image = capturedImage;
- capturedCount++;
- }
- }
- }
- }
- Image^ LoadImageForPiece(ChessPiece* piece, int x, int y) {
- Image^ image = nullptr;
- if (dynamic_cast<Chancellor*>(piece)) {
- if (piece->isBlack) {
- image = Image::FromFile("C:\\chess\\black-chess\\сhancellor.png");
- }
- else {
- image = Image::FromFile("C:\\chess\\white-chess\\сhancellor.png");
- }
- }
- else if (dynamic_cast<Archbishop*>(piece)) {
- if (piece->isBlack) {
- image = Image::FromFile("C:\\chess\\black-chess\\archbishop.png");
- }
- else {
- image = Image::FromFile("C:\\chess\\white-chess\\archbishop.png");
- }
- }
- else if (dynamic_cast<Pawn*>(piece)) {
- if (piece->isBlack) {
- image = Image::FromFile("C:\\chess\\black-chess\\pawn.png");
- }
- else {
- image = Image::FromFile("C:\\chess\\white-chess\\pawn.png");
- }
- }
- else if (dynamic_cast<Queen*>(piece)) {
- if (piece->isBlack) {
- image = Image::FromFile("C:\\chess\\black-chess\\queen.png");
- }
- else {
- image = Image::FromFile("C:\\chess\\white-chess\\queen.png");
- }
- }
- else if (dynamic_cast<King*>(piece)) {
- if (piece->isBlack) {
- image = Image::FromFile("C:\\chess\\black-chess\\king.png");
- }
- else {
- image = Image::FromFile("C:\\chess\\white-chess\\king.png");
- }
- }
- else if (dynamic_cast<Bishop*>(piece)) {
- if (piece->isBlack) {
- image = Image::FromFile("C:\\chess\\black-chess\\bishop.png");
- }
- else {
- image = Image::FromFile("C:\\chess\\white-chess\\bishop.png");
- }
- }
- else if (dynamic_cast<Knight*>(piece)) {
- if (piece->isBlack) {
- image = Image::FromFile("C:\\chess\\black-chess\\knight.png");
- }
- else {
- image = Image::FromFile("C:\\chess\\white-chess\\knight.png");
- }
- }
- else if (dynamic_cast<Rook*>(piece)) {
- if (piece->isBlack) {
- image = Image::FromFile("C:\\chess\\black-chess\\rook.png");
- }
- else {
- image = Image::FromFile("C:\\chess\\white-chess\\rook.png");
- }
- }
- if (image != nullptr) {
- // Змініть розмір зображення фігури на imageWidth та imageHeight
- image = gcnew Bitmap(image, imageWidth, imageHeight);
- }
- return image;
- }
- void Cell_Click(Object^ sender, EventArgs^ e) {
- PictureBox^ pictureBox = (PictureBox^)sender;
- int x = pictureBox->Location.X / 60;
- int y = pictureBox->Location.Y / 60;
- // If no piece is currently selected, try to select one
- if (selectedX == -1 && selectedY == -1) {
- ChessPiece* piece = board->getPiece(x, y);
- if (piece != nullptr) {
- validMoves = GetValidMoves(x, y);
- HighlightValidMoves();
- // Highlight the selected piece (e.g., change the border color of the PictureBox)
- pictureBox->BorderStyle = BorderStyle::FixedSingle;
- // Update selected coordinates
- selectedX = x;
- selectedY = y;
- }
- }
- else {
- // A piece is already selected, try to make a move to the clicked cell
- if (board->isValidMove(selectedX, selectedY, x, y)) {
- // Attempt to make the move
- bool moveResult = board->makeMove(selectedX, selectedY, x, y);
- if (moveResult) {
- // Move was successful, update the graphical representation
- DrawPiece(selectedX, selectedY); // Clear the source cell
- DrawPiece(x, y); // Draw the piece on the destination cell
- }
- }
- validMoves->Clear();
- UnhighlightValidMoves();
- // Unhighlight the selected piece (e.g., reset the border color of the PictureBox)
- boardPictureBoxes[selectedX, selectedY]->BorderStyle = BorderStyle::None;
- // Reset selected coordinates
- selectedX = -1;
- selectedY = -1;
- }
- DrawCapturedPieces();
- }
- List<Tuple<int, int>^>^ GetValidMoves(int x, int y) {
- List<Tuple<int, int>^>^ moves = gcnew List<Tuple<int, int>^>();
- ChessPiece* piece = board->getPiece(x, y);
- if (piece != nullptr) {
- for (int destX = 0; destX < 10; destX++) {
- for (int destY = 0; destY < 8; destY++) {
- if (board->isValidMove(x, y, destX, destY)) {
- moves->Add(gcnew Tuple<int, int>(destX, destY));
- }
- }
- }
- }
- return moves;
- }
- void HighlightValidMoves() {
- for each (Tuple<int, int> ^ move in validMoves) {
- int x = move->Item1;
- int y = move->Item2;
- boardPictureBoxes[x, y]->BackColor = Color::Green;
- }
- }
- void UnhighlightValidMoves() {
- for (int x = 0; x < 10; x++) {
- for (int y = 0; y < 8; y++) {
- if ((x + y) % 2 == 0) {
- boardPictureBoxes[x, y]->BackColor = Color::Bisque;
- }
- else {
- boardPictureBoxes[x, y]->BackColor = Color::DarkOrange;
- }
- }
- }
- }
- void InitializeChessboard() {
- // ... (rest of the code remains unchanged) ...
- // Initialize graphical representation of the chessboard
- for (int x = 0; x < 10; x++) {
- for (int y = 0; y < 8; y++) {
- // Update the graphical representation of the chessboard
- DrawPiece(x, y); // Draw the piece or an empty cell at (x, y)
- }
- }
- }
- void DrawPiece(int x, int y) {
- ChessPiece* piece = board->getPiece(x, y);
- if (piece != nullptr) {
- boardPictureBoxes[x, y]->SizeMode = PictureBoxSizeMode::Zoom;
- Image^ image = LoadImageForPiece(piece, x, y);
- if (image != nullptr) {
- // Display the piece on the chessboard
- boardPictureBoxes[x, y]->Image = image;
- }
- }
- else {
- // Display an empty cell on the chessboard
- boardPictureBoxes[x, y]->Image = nullptr;
- boardPictureBoxes[x, y]->BackColor = ((x + y) % 2 == 0) ? Color::Bisque : Color::DarkOrange;
- }
- }
- };
- }
Add Comment
Please, Sign In to add comment