Open kulpot opened 8 months ago
######################## Board.cs #####################################
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace ClassBoardModel { public class Board { //---------START--------- C# Chess Board 02 board cell classes ------------------------------- // the size of the board usually 8x8 public int Size { get; set; }
// 2d array of type cell.
public Cell[,] theGrid { get; set; }
// constructor
public Board(int s)
{
// initial size of the board is defined by parameter s.
Size = s;
// create a new 2D array of type cell.
theGrid = new Cell[Size, Size];
// fill the 2D array with new Cells, each with unique x and y coordinates.
for (int i = 0; i < Size; i++)
{
for (int j = 0; j < Size; j++)
{
theGrid[i, j] = new Cell(i, j);
}
}
}
//---------END--------- C# Chess Board 02 board cell classes -------------------------------
//-------START----------- C# Chess Board 03 next legal moves -------------------------------------------------
public void MarkNextLegalMoves(Cell currentCell, string chessPiece)
{
// step 1 - clear all previous legal moves
for (int i = 0; i < Size; i++)
{
for (int j = 0; j < Size; j++)
{
theGrid[i, j].LegalNextMove = false;
theGrid[i, j].CurrentlyOccupied = false;
}
}
// step 2 - find all legal moves and mark the cells as "legal"
switch (chessPiece)
{
case "Knight":
theGrid[currentCell.RowNumber + 2, currentCell.ColumnNumber + 1].LegalNextMove = true;
theGrid[currentCell.RowNumber + 2, currentCell.ColumnNumber - 1].LegalNextMove = true;
theGrid[currentCell.RowNumber - 2, currentCell.ColumnNumber + 1].LegalNextMove = true;
theGrid[currentCell.RowNumber - 2, currentCell.ColumnNumber - 1].LegalNextMove = true;
theGrid[currentCell.RowNumber + 1, currentCell.ColumnNumber + 2].LegalNextMove = true;
theGrid[currentCell.RowNumber + 1, currentCell.ColumnNumber - 2].LegalNextMove = true;
theGrid[currentCell.RowNumber - 1, currentCell.ColumnNumber + 2].LegalNextMove = true;
theGrid[currentCell.RowNumber - 1, currentCell.ColumnNumber - 2].LegalNextMove = true;
break;
case "King":
break;
case "Rook":
break;
case "Bishop":
break;
case "Queen":
break;
default:
break;
}
//--------START---------- C# Chess Board Game 06 place piece -------------------------------------------------------
theGrid[currentCell.RowNumber, currentCell.ColumnNumber].CurrentlyOccupied = true;
//---------END--------- C# Chess Board Game 06 place piece -------------------------------------------------------
}
//--------END---------- C# Chess Board 03 next legal moves -------------------------------------------------
}
}
###################### Cell.cs ########################################
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace ClassBoardModel { public class Cell { //---------START--------- C# Chess Board 02 board cell classes ------------------------------- public int RowNumber { get; set; } public int ColumnNumber { get; set; } public bool CurrentlyOccupied { get; set; } public bool LegalNextMove { get; set; }
public Cell(int x, int y)
{
RowNumber = x;
ColumnNumber = y;
}
//---------END--------- C# Chess Board 02 board cell classes -------------------------------
}
}
################################## Program.cs ###################################
using ClassBoardModel; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
//-------------------- C# Chess Board 02 board cell classes ------------------------------- //ref link:https://www.youtube.com/watch?v=SFMVyiJ2S6g&list=PLhPyEFL5u-i0YDRW6FLMd1PavZp9RcYdF&index=3
// addNewItemToSolution:class library(name:ClassBoardModel), addNewClassTo:ClassBoardModel(name:Cell.cs/Board.cs),
//-------------------- C# Chess Board 03 next legal moves ------------------------------------------------- //ref link:https://www.youtube.com/watch?v=iV9hBTi-QB8&list=PLhPyEFL5u-i0YDRW6FLMd1PavZp9RcYdF&index=5&t=20s
//-------------------- C# Chess Board 04 program flow ------------------------------------------------- //ref link:https://www.youtube.com/watch?v=xc6C2I_wAxI&list=PLhPyEFL5u-i0YDRW6FLMd1PavZp9RcYdF&index=4
// Add ref to:C# Chess Board 04->Add->Reference...->Projects->ChessBoardModel,
//-------------------- C# Chess Board 05 print board squares ----------------------------------------------- //ref link:https://www.youtube.com/watch?v=U9dsYjKaEAo&list=PLhPyEFL5u-i0YDRW6FLMd1PavZp9RcYdF&index=6
// PrintBoard method,
//-------------------- C# Chess Board Game 06 place piece ------------------------------------------------------- //ref link:https://www.youtube.com/watch?v=qV1ib7dfXvk&list=PLhPyEFL5u-i0YDRW6FLMd1PavZp9RcYdF&index=6
//
namespace C__Chess_Board_02 { class Program { //--------START---------- C# Chess Board 04 program flow ------------------------------------------------- static Board myBoard = new Board(8); //--------END---------- C# Chess Board 04 program flow -------------------------------------------------
}