static bool PlayerTurn(Board board, FigureColor color) { StepPossibility stepState = board.GetStepPossibilities(color); if (stepState == StepPossibility.CheckMate) { Console.WriteLine($"Checkmate! {color} lost!"); return(false); } if (stepState == StepPossibility.StaleMate) { Console.WriteLine($"Stalemate! It's a draw!"); return(false); } Console.WriteLine(color); while (true) { (int, int)from = GetValidCoordinates(board, color); Figure figure = board.Figures[from.Item1, from.Item2]; if (figure != null && figure.Color == color) { (int, int)to = GetValidCoordinates(board, color); if (board.StepWithoutCheck(from.Item1, from.Item2, to.Item1, to.Item2, color)) { board.Figures[from.Item1, from.Item2] = null; board.Figures[to.Item1, to.Item2] = figure; return(true); } else { Console.Clear(); board.Draw(); Console.WriteLine(color); Console.WriteLine("You can't step there!"); } } else { Console.Clear(); board.Draw(); Console.WriteLine(color); Console.WriteLine("Not your figure you naughty boy!"); } } }
static void Main(string[] args) { Board board = new Board(); board.Draw(); int round = 0; while (true) { bool canContinue = PlayerTurn(board, round % 2 == 0 ? FigureColor.White : FigureColor.Black); if (!canContinue) { break; } Console.Clear(); board.Draw(); round++; } Console.ReadKey(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GHelper.spritebatch.Begin(); // GHelper.spritebatch.Draw(BT, BR, Color.White); // U1.Draw(); B1.Draw(); GHelper.spritebatch.End(); // TODO: Add your drawing code here base.Draw(gameTime); }
static (int, int) GetValidCoordinates(Board board, FigureColor color) { while (true) { (int, int)? input = GetCoordinates(); if (input != null) { return(input.Value); } Console.Clear(); board.Draw(); Console.WriteLine(color); Console.WriteLine("Invalid coordinates!"); } }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here _spriteBatch.Begin(); Board.Draw(_spriteBatch); foreach (Player p in gameManager.Players) { p.Draw(_spriteBatch); } _spriteBatch.End(); base.Draw(gameTime); }
public static void MakeAMove(Board board) { if (board.selected1 != null && board.selected2 != null) //if both nodes are selected { if (board.selected1.figure.move(board.selected2.x1 / 50, board.selected2.y1 / 50, board)) //if move for this figure is correct { board.selected1.colour = board.selected1.base_colour; //reseting select color board.selected2.colour = board.selected2.base_colour; board.selected2.figure = board.selected1.figure; board.selected2.figure.jump(board.selected2.x1 / 50, board.selected2.y1 / 50); board.selected1.figure = null; board.selected2 = null; board.selected1 = null; board.Draw(); } } return; }
public Form1() { InitializeComponent(); board = new Board(pictureBox1); board.Draw(); }