private void AnimateMove(Evaluation evaluatedMove, bool reverse = false) { var from = VisibleBoard.Squares.Single(x => x.Key.ToString() == evaluatedMove.Move.FromSquare.ToString()); var to = VisibleBoard.Squares.Single(x => x.Key.ToString() == evaluatedMove.Move.ToSquare.ToString()); var piece = from.Key.Piece ?? to.Key.Piece; if (reverse) { var temp = from; from = to; to = temp; } const float steps = 20; var dx = (to.Value.X - from.Value.X) / (steps - 1); var dy = (to.Value.Y - from.Value.Y) / (steps - 1); var animId = Guid.NewGuid(); animations.Remove(animations.Last()); animations.Add(animId); for (int i = 0; i < steps; i++) { if (!animations.Contains(animId)) { break; } var x = from.Value.X + dx * i; var y = from.Value.Y + dy * i; VisibleBoard.OffsetAnimated(piece, x, y); panel1.Invalidate(); Application.DoEvents(); } VisibleBoard.OffsetAnimated(null, 0, 0); panel1.Invalidate(); }
private void panel1_MouseDown(object sender, MouseEventArgs e) { VisibleBoard.MouseDown(e.X, e.Y); VisibleBoard.MouseX = e.X; VisibleBoard.MouseY = e.Y; panel1.Invalidate(); }
private void Form1_Load(object sender, EventArgs e) { panelEdit.Height = 0; ChessGame = new Game(); ChessGame.New(); Engine = new Engine(); VisibleBoard = new VisibleBoard(ChessGame, Engine); }
private void panel1_DragDrop(object sender, DragEventArgs e) { var chessPiecePictureBox = e.Data.GetData(typeof(ChessPiecePictureBox)) as ChessPiecePictureBox; if (!VisibleBoard.EditMode || chessPiecePictureBox == null) { return; } var clientPoint = panel1.PointToClient(new Point(e.X, e.Y)); VisibleBoard.Drop(chessPiecePictureBox.PieceType, clientPoint.X, clientPoint.Y); panel1.Invalidate(); }
private void panel1_MouseUp(object sender, MouseEventArgs e) { VisibleBoard.MouseUp(e.X, e.Y); if (VisibleBoard.EditMode) { MakeEditMove(e.X, e.Y); return; } if (VisibleBoard.MouseDownSquare == null) { return; } if (VisibleBoard.MouseUpSquare == null) { VisibleBoard.MouseDownSquare = null; panel1.Invalidate(); return; } if (Engine.ThinkingFor == null) { var cmd = new MoveCommand(VisibleBoard.MouseDownSquare.File, VisibleBoard.MouseDownSquare.Rank, VisibleBoard.MouseUpSquare.File, VisibleBoard.MouseUpSquare.Rank); if (ChessGame.TryPossibleMoveCommand(cmd)) { var evaluatedMove = new Evaluation { Move = ChessGame.OtherPlayer.Moves.First() }; MoveToList(evaluatedMove); //SetScoreLabel(evaluatedMove); panel1.Invalidate(); Application.DoEvents(); CheckForEnd(); EngineMove(); } } VisibleBoard.MouseDownSquare = null; VisibleBoard.MouseUpSquare = null; panel1.Invalidate(); }
private void panel1_Paint(object sender, PaintEventArgs e) { VisibleBoard.Paint(e.Graphics); }