Exemplo n.º 1
0
        private void Board_MouseUp(object sender, MouseEventArgs e)
        {
            int sizeUnit = (int)Math.Round(Board.Image.Width / 16.0);

            if (Picked.Occupant == Piece.NONE)
            {
                return;
            }
            if (e.X >= Board.Width || e.Y >= Board.Height || e.X < 0 || e.Y < 0)
            {
                Picked = new Square(0, 'z');
                Board.Invalidate();
                return;
            }
            int  X       = e.X / (2 * sizeUnit);
            int  Y       = e.Y / (2 * sizeUnit);
            bool Success = Game.Move(new Move(Picked.File - 'a', 8 - Picked.Rank, X, Y));

            if (Success)
            {
                Dropped = new Square(Game.Board[X][Y].Rank,
                                     Game.Board[X][Y].File,
                                     Game.Board[X][Y].Occupant);
            }
            Picked.Occupant = Piece.NONE;
            Board.Invalidate();
        }
Exemplo n.º 2
0
        private void Board_MouseUp(object sender, MouseEventArgs e)
        {
            int sizeUnit = (int)Math.Round(Board.Image.Width / 16.0);

            if (Picked.Occupant == Piece.NONE)
            {
                return;
            }
            if (e.X >= Board.Width || e.Y >= Board.Height || e.X < 0 || e.Y < 0)
            {
                Picked = new Square(0, 'z');
                Board.Invalidate();
                return;
            }
            int  X       = e.X / (2 * sizeUnit);
            int  Y       = e.Y / (2 * sizeUnit);
            bool Success = Game.Move(new Move(Picked.File - 'a', 8 - Picked.Rank, X, Y));

            if (TimeFlag == false)
            {
                // Start Timer.
                MainTimer.Start();
                TimeFlag = true;
            }


            if (Success)
            {
                Dropped = new Square(Game.Board[X][Y].Rank, Game.Board[X][Y].File, Game.Board[X][Y].Occupant);

                // If there is a Checkmate or Stalemate stop the time.
                if (Game.IsCheckmateFlag || Game.IsStalemateFlag)
                {
                    MainTimer.Stop();

                    if (Game.IsCheckmateFlag)
                    {
                        MessageBox.Show("Game Have Finished: Checkmate");
                    }
                    else if (Game.IsStalemateFlag)
                    {
                        MessageBox.Show("Game Have Finished: Stalemate");
                    }
                }

                // Data Binding - Updating the List When A Move Is Valid.
                listBox1.Items.Add(Game.Moves[Game.Moves.Count - 1]);
            }
            Picked.Occupant = Piece.NONE;
            Board.Invalidate();
        }