示例#1
0
        private void btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            if (btn.BackgroundImage != null)
            {
                return; // Nếu ô đã được đánh thì ko cho đánh lại
            }
            btn.BackgroundImage = ListPlayers[CurrentPlayer].Symbol;

            StkUndoStep.Push(new PlayInfo(GetButtonCoordinate(btn), CurrentPlayer, btn.BackgroundImage));
            StkRedoStep.Clear();

            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;
            ChangePlayer();

            if (playerClicked != null)
            {
                playerClicked(this, new BtnClickEvent(GetButtonCoordinate(btn)));
            }

            if (IsEndGame())
            {
                EndGame();
            }

            if (!(IsAI) && playMode == 3)
            {
                StartAI();
            }

            IsAI = false;
        }
示例#2
0
        private bool RedoAStep()
        {
            if (StkRedoStep.Count <= 0)
            {
                return(false);
            }

            PlayInfo OldPos = StkRedoStep.Pop();

            StkUndoStep.Push(OldPos);

            Button btn = MatrixPositions[OldPos.Point.Y][OldPos.Point.X];

            btn.BackgroundImage = OldPos.Symbol;

            if (StkRedoStep.Count <= 0)
            {
                CurrentPlayer = OldPos.CurrentPlayer == 1 ? 0 : 1;
            }
            else
            {
                OldPos = StkRedoStep.Peek();
            }

            ChangePlayer();

            return(true);
        }
示例#3
0
        public void OtherPlayerClicked(Point point)
        {
            Button btn = MatrixPositions[point.Y][point.X];

            if (btn.BackgroundImage != null)
            {
                return; // Nếu ô đã được đánh thì ko cho đánh lại
            }
            btn.BackgroundImage = ListPlayers[CurrentPlayer].Symbol;

            StkUndoStep.Push(new PlayInfo(GetButtonCoordinate(btn), CurrentPlayer, btn.BackgroundImage));
            StkRedoStep.Clear();

            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;
            ChangePlayer();

            if (IsEndGame())
            {
                EndGame();
            }
        }