//public List<string> message = new List<string>(); //public void MoveWhitePiece(int x, int y, int xTarget, int yTarget)//vitas drag //{ // ChessPiece piece = this.board[x, y]; // ChessPiece targetPiece = this.board[xTarget, yTarget]; // if (piece == null)//fel som kan uppstå för vita // { // message.Add("Det finns ingen vit spelare på denna position"); // // Console.WriteLine("Det finns ingen vit spelare på denna position"); // return; // } // if (piece.IsChessPieceBlack()) // { // message.Add("Det går inte att flytta en svart pjäs"); // return; // } // if (!piece.ValidateMove(x, y, xTarget, yTarget)) // { // message.Add("Ogiltligt drag!"); // return; // } // if (targetPiece != null) // { // if (targetPiece.IsChessPieceWhite()) // { // message.Add("Du kan inte ta din egna pjäs"); // return; // } // } // this.board[x, y] = null; //När allt går rätt // // this.Draw(); // Console.WriteLine("{0},{1} till {2},{3}", x, y); // foreach (var item in message) // { // //Console.WriteLine(item); // } // if (targetPiece != null) // { // Console.WriteLine("Vit spelare slog ut " + targetPiece.GetChessPieceType()); // } // Thread.Sleep(1000); //} public void Draw()//ritar upp spelbrädan { Console.Clear(); Console.BackgroundColor = ConsoleColor.Gray; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { Console.ForegroundColor = ConsoleColor.Black; Console.Write("["); ChessPiece chessPiece = GetChessPieceAt(x, y); if (chessPiece != null && chessPiece.Color == "White") { Console.ForegroundColor = ConsoleColor.White; Console.Write(chessPiece.GetChessPieceDescription()); } else if (chessPiece != null && chessPiece.Color == "Black") { Console.ForegroundColor = ConsoleColor.Black; Console.Write(chessPiece.GetChessPieceDescription()); } else { Console.Write(" "); } Console.ForegroundColor = ConsoleColor.Black; Console.Write("]"); } Console.WriteLine(""); } }
//public List<string> message = new List<string>(); //public void MoveWhitePiece(int x, int y, int xTarget, int yTarget)//vitas drag //{ // ChessPiece piece = this.board[x, y]; // ChessPiece targetPiece = this.board[xTarget, yTarget]; // if (piece == null)//fel som kan uppstå för vita // { // message.Add("Det finns ingen vit spelare på denna position"); // // Console.WriteLine("Det finns ingen vit spelare på denna position"); // return; // } // if (piece.IsChessPieceBlack()) // { // message.Add("Det går inte att flytta en svart pjäs"); // return; // } // if (!piece.ValidateMove(x, y, xTarget, yTarget)) // { // message.Add("Ogiltligt drag!"); // return; // } // if (targetPiece != null) // { // if (targetPiece.IsChessPieceWhite()) // { // message.Add("Du kan inte ta din egna pjäs"); // return; // } // } // this.board[x, y] = null; //När allt går rätt // // this.Draw(); // Console.WriteLine("{0},{1} till {2},{3}", x, y); // foreach (var item in message) // { // //Console.WriteLine(item); // } // if (targetPiece != null) // { // Console.WriteLine("Vit spelare slog ut " + targetPiece.GetChessPieceType()); // } // Thread.Sleep(1000); //} //public void MoveBlackPiece(int x, int y, int xTarget, int yTarget)//vitas drag //{ // ChessPiece piece = this.board[x, y]; // ChessPiece targetPiece = this.board[xTarget, yTarget]; // if (piece == null)//fel som kan uppstå för vita // { // // Console.WriteLine("Det finns ingen svart spelare på denna position"); // return; // } // if (piece.IsChessPieceWhite()) // { // // Console.WriteLine("Det går inte att flytta en vit pjäs"); // return; // } // if (!piece.ValidateMove(x, y, xTarget, yTarget)) // { // // Console.WriteLine("Ogiltligt drag!"); // return; // } // if (targetPiece != null) // { // if (targetPiece.IsChessPieceBlack()) // { // // Console.WriteLine("Du kan inte ta din egna pjäs"); // return; // } // } // this.board[x, y] = null; //När allt går rätt // this.board[xTarget, yTarget] = piece; // this.Draw(); // Console.WriteLine("{0},{1} till {2},{3}", x, y, xTarget, yTarget); // if (targetPiece != null) // { // Console.WriteLine("Svart spelare slog ut vit " + targetPiece.GetChessPieceType()); // } // Thread.Sleep(1000); //} public void Draw()//ritar upp spelbrädan { Console.Clear(); for (int y = 0; y < 8; y++) { Console.Write("|"); for (int x = 0; x < 8; x++) { foreach (Player player in this.players) { ChessPiece chessPiece = player.GetChessPieceAt(x, y); if (chessPiece != null) { Console.Write(player.GetDescription() + chessPiece.GetChessPieceDescription()); } else { Console.Write(" "); } } Console.Write("|"); } Console.WriteLine(""); } }
public void StartGame() { this.Draw(); Console.WriteLine("Start Game!"); Console.ReadKey(); bool running = true; while (running) { // White player players[0].UpdateMyList(allChessPieces); ChessPiece randomWhitePiece = players[0].chessPieces[new Random().Next(0, players[0].chessPieces.Count)]; if (randomWhitePiece != null) { if (players[1] != players[0]) { players[1].Kill(randomWhitePiece.x, randomWhitePiece.y, allChessPieces); } } else { //Unable to make a move //Is the game over? running = true; } if (randomWhitePiece.GetChessPieceDescription() == "P") { randomWhitePiece.Move(true); //Console.WriteLine(WhitePlayer.messages); } else { randomWhitePiece.Move(); // Console.WriteLine(WhitePlayer.MoveMessage()); } Thread.Sleep(500); this.Draw(); //King king = new King(); // Black player players[1].UpdateMyList(allChessPieces); ChessPiece randomBlackPiece = players[1].chessPieces[new Random().Next(0, players[1].chessPieces.Count)]; if (randomBlackPiece != null) { if (players[0] != players[1]) { players[0].Kill(randomBlackPiece.x, randomBlackPiece.y, allChessPieces); } } if (randomBlackPiece.GetChessPieceDescription() == "P") { randomBlackPiece.Move(false); } else { randomBlackPiece.Move(); } this.Draw(); Thread.Sleep(500); } Console.WriteLine("Game over!"); }