static void Main() { Console.OutputEncoding = System.Text.Encoding.UTF8; //draw blank chessboard if (gameActive == false) { for (int i = 0; i < 8; i++) { Console.Write("|"); for (int j = 0; j < 8; j++) { if (((i + j) % 2) == 0) { //black squares Console.Write("\u2395" + " "); } else { //white squares Console.Write("\u23f9" + " "); } } Console.WriteLine("|"); } AskPlayerToStart(); } //build chessboard with pieces and assign each piece in 2d array if (gameActive == true && gameStarted == false) { for (int i = 0; i < 8; i++) { Console.Write("|"); for (int j = 0; j < 8; j++) { if (i == 0) { if (j == 0 || j == 7) { Console.Write(chessPieces[2] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "rook"; boardArray[i, j].teamColor = "black"; } else if (j == 1 || j == 6) { Console.Write(chessPieces[4] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "knight"; boardArray[i, j].teamColor = "black"; } else if (j == 2 || j == 5) { Console.Write(chessPieces[3] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "bishop"; boardArray[i, j].teamColor = "black"; } else if (j == 3) { Console.Write(chessPieces[1] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "queen"; boardArray[i, j].teamColor = "black"; } else if (j == 4) { Console.Write(chessPieces[0] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "king"; boardArray[i, j].teamColor = "black"; } } else if (i == 1) { Console.Write(chessPieces[5] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "pawn"; boardArray[i, j].teamColor = "black"; } else if (i == 6) { Console.Write(chessPieces[11] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "pawn"; boardArray[i, j].teamColor = "white"; } else if (i == 7) { if (j == 0 || j == 7) { Console.Write(chessPieces[8] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "rook"; boardArray[i, j].teamColor = "white"; } else if (j == 1 || j == 6) { Console.Write(chessPieces[10] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "knight"; boardArray[i, j].teamColor = "white"; } else if (j == 2 || j == 5) { Console.Write(chessPieces[9] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "bishop"; boardArray[i, j].teamColor = "white"; } else if (j == 3) { Console.Write(chessPieces[7] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "king"; boardArray[i, j].teamColor = "white"; } else if (j == 4) { Console.Write(chessPieces[6] + " "); boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "queen"; boardArray[i, j].teamColor = "white"; } } else if (((i + j) % 2) == 0) { //black squares boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "empty"; boardArray[i, j].teamColor = "empty"; Console.Write("\u2395" + " "); } else { //white squares boardArray[i, j] = new ChessPiece(); boardArray[i, j].chessClass = "empty"; boardArray[i, j].teamColor = "empty"; Console.Write("\u23f9" + " "); } } Console.WriteLine("|"); for (int j = 0; j < 8; j++) { if (j == 0 || j == 7) { if (((i + j) % 2) == 0) { boardArray[i, j].spaceColor = "black"; } else { boardArray[i, j].spaceColor = "white"; } } } } } Console.ReadLine(); Main(); }
//public string HPosition { get; set; } //public string VPosition { get; set; } /// <summary> /// Constructor for the ChessSquare class /// Initializes properties and determines within the class itself whether square are occupied or not, /// and whether squares are occupied /// </summary> public ChessSquare() { //increases the number of squares on the board //whenever a new object of ChessSquare is created SquareCount++; ///determines the position of each square that is created and determines the color ///for example, if SquareCount is even on even rows, make the squares black if (SquareCount % 2 == 0 && RowCount % 2 == 0) { this.IsBlack = true; } else if (SquareCount % 2 == 1 && RowCount % 2 == 0) { this.IsBlack = false; } else if (SquareCount % 2 == 1 && RowCount % 2 == 1) { this.IsBlack = true; } else if (SquareCount % 2 == 0 && RowCount % 2 == 1) { this.IsBlack = false; } ///<summary> ///using a square's position and automatically occupies it with a chess piece /// </summary> //Sets rooks if (SquareCount == 1 || SquareCount == 8 || SquareCount == 57 || SquareCount == 64) { this.ChessPiece = new ChessRook(); this.IsOccupied = true; } //Sets knights else if (SquareCount == 2 || SquareCount == 7 || SquareCount == 58 || SquareCount == 63) { this.ChessPiece = new ChessKnight(); this.IsOccupied = true; } //Sets bishops else if (SquareCount == 3 || SquareCount == 6 || SquareCount == 59 || SquareCount == 62) { this.ChessPiece = new ChessBishop(); this.IsOccupied = true; } //Sets kings else if (SquareCount == 4 || SquareCount == 61) { this.ChessPiece = new ChessKing(); this.IsOccupied = true; } //Sets queens else if (SquareCount == 5 || SquareCount == 60) { this.ChessPiece = new ChessQueen(); this.IsOccupied = true; } //Sets pawns else if (SquareCount > 8 && SquareCount < 17 || SquareCount > 48 && SquareCount < 57) { this.ChessPiece = new ChessPawn(); this.IsOccupied = true; } else { this.IsOccupied = false; } ///<div>Not currently in use. ///Provides a square with a string HPosition and a string VPosition. ///if(RowCount == 0) ///{ /// this.HPosition = "A"; /// if(SquareCount % 8 == 0) /// { /// this.VPosition = 8 + ""; /// } /// else /// { /// this.VPosition = SquareCount % 8 + ""; /// } ///} ///if (RowCount == 1) ///{ /// this.HPosition = "B"; /// if (SquareCount % 8 == 0) /// { /// this.VPosition = 8 + ""; /// } /// else /// { /// this.VPosition = SquareCount % 8 + ""; /// } ///} ///if (RowCount == 2) ///{ /// this.HPosition = "C"; /// if (SquareCount % 8 == 0) /// { /// this.VPosition = 8 + ""; /// } /// else /// { /// this.VPosition = SquareCount % 8 + ""; /// } ///} ///if (RowCount == 3) ///{ /// this.HPosition = "D"; /// if (SquareCount % 8 == 0) /// { /// this.VPosition = 8 + ""; /// } /// else /// { /// this.VPosition = SquareCount % 8 + ""; /// } ///} ///if (RowCount == 4) ///{ /// this.HPosition = "E"; /// if (SquareCount % 8 == 0) /// { /// this.VPosition = 8 + ""; /// } /// else /// { /// this.VPosition = SquareCount % 8 + ""; /// } ///} ///if (RowCount == 5) ///{ /// this.HPosition = "F"; /// if (SquareCount % 8 == 0) /// { /// this.VPosition = 8 + ""; /// } /// else /// { /// this.VPosition = SquareCount % 8 + ""; /// } ///} ///if (RowCount == 6) ///{ /// this.HPosition = "G"; /// if (SquareCount % 8 == 0) /// { /// this.VPosition = 8 + ""; /// } /// else /// { /// this.VPosition = SquareCount % 8 + ""; /// } ///} ///if (RowCount == 7) ///{ /// this.HPosition = "H"; /// if (SquareCount % 8 == 0) /// { /// this.VPosition = 8 + ""; /// } /// else /// { /// this.VPosition = SquareCount % 8 + ""; /// } ///} ///</div> if (SquareCount % 8 == 0) { RowCount++; } }