Exemplo n.º 1
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);
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        public bool Undo()
        {
            if (StkUndoStep.Count <= 1)
            {
                return(false);
            }

            PlayInfo OldPos = StkUndoStep.Peek();

            CurrentPlayer = OldPos.CurrentPlayer == 1 ? 0 : 1;

            bool IsUndo1 = UndoAStep();
            bool IsUndo2 = UndoAStep();

            return(IsUndo1 && IsUndo2);
        }
Exemplo n.º 4
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();
            }
        }