예제 #1
0
        void buttonclick(object sender, EventArgs e)
        {
            Button button = sender as Button;

            if (button.BackgroundImage != null)
            {
                return;
            }

            Mark(button);

            TimeLineStack.Push(new InfoPlayer(GetChess(button), CurrentPlayer));

            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;

            if (IsEndGame(button))
            {
                EndGame();
                ChessBoard.Enabled = false;
                return;
            }
            else if (TimeLineStack.Count == Size.ChessBoardWidth * Size.ChessBoardHeight)
            {
                MessageBox.Show("Hai người chơi hòa", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            ChangePlayer();

            Form1.BoolUndo++;

            EnableUndo();
        }
예제 #2
0
        public bool Undo()
        {
            if (TimeLineStack.Count <= 0)
            {
                MessageBox.Show("Bàn cờ chưa được đi!!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            InfoPlayer OldPoint = TimeLineStack.Pop();
            Button     button   = Matrix[OldPoint.Point.X][OldPoint.Point.Y];

            button.BackgroundImage = null;

            for (int i = 0; i < 10; i++)
            {
                button.BackColor = Color.Red;
                Thread.Sleep(40);
                Application.DoEvents();
                button.BackColor = Color.Empty;
            }

            if (TimeLineStack.Count == 0)
            {
                CurrentPlayer = 0;
            }
            else
            {
                OldPoint      = TimeLineStack.Top();
                CurrentPlayer = OldPoint.CurrentPlayer == 1 ? 0 : 1;
            }

            ChangePlayer();
            Form1.BoolUndo++;
            return(true);
        }