public void OtherPlayerMark(Point point)
        {
            Button btn = Matrix[point.Y][point.X];

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

            Mark(btn);

            PlayTimeLine.Push(new PlayInfo(GetChessPoint(btn), CurrentPlayer));

            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;

            ChangePlayer();

            if (isEndGame(btn))
            {
                CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;

                ChangePlayer();
                Player[CurrentPlayer].Score++;
                OpponentScore.Text = Player[CurrentPlayer].Score.ToString();
                EndGame();
            }
        }
        private bool RedoStep()
        {
            if (UndoTimeLine.Count <= 0)
            {
                return(false);
            }

            PlayInfo oldPoint = UndoTimeLine.Pop();

            PlayTimeLine.Push(oldPoint);
            Button btn = Matrix[oldPoint.Point.Y][oldPoint.Point.X];

            btn.BackgroundImage = Player[CurrentPlayer].Mark;

            if (UndoTimeLine.Count <= 0)
            {
                CurrentPlayer = 0;
            }
            else
            {
                oldPoint = UndoTimeLine.Peek();
            }
            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;
            ChangePlayer();

            return(true);
        }
        private bool UndoStep()
        {
            if (PlayTimeLine.Count <= 0)
            {
                return(false);
            }

            PlayInfo oldPoint = PlayTimeLine.Pop();

            UndoTimeLine.Push(oldPoint);
            Button btn = Matrix[oldPoint.Point.Y][oldPoint.Point.X];

            btn.BackgroundImage = null;

            if (PlayTimeLine.Count <= 0)
            {
                CurrentPlayer = 0;
            }
            else
            {
                oldPoint = PlayTimeLine.Peek();
            }

            ChangePlayer();

            return(true);
        }
        public bool UndoAStep()
        {
            if (PlayTimeLine.Count <= 0)
            {
                return(false);
            }
            PlayInfo oldPoint = PlayTimeLine.Pop();
            Button   btn      = Matrix[oldPoint.Point.Y][oldPoint.Point.X];

            btn.BackgroundImage = null;

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

            ChangePlayer();

            return(true);
        }
        private void btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

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

            PlayTimeLine.Push(new PlayInfo(GetChessPoint(btn), CurrentPlayer));
            UndoTimeLine.Push(new PlayInfo(GetChessPoint(btn), CurrentPlayer));
            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;
            ChangePlayer();

            if (playerMarked != null)
            {
                playerMarked(this, new ButtonClickEvent(GetChessPoint(btn)));
            }

            if (isEndGame(btn))
            {
                CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;
                ChangePlayer();
                Player[CurrentPlayer].Score++;
                PlayerScore.Text = Player[CurrentPlayer].Score.ToString();
                EndGame();
            }
        }
        /// <summary>
        /// Xử lý khi người chơi khác đánh
        /// </summary>
        /// <param name="point"></param>
        public void OtherPlayerMark(Point point)
        {
            Button btn = Matrix[point.Y][point.X];

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

            Mark(btn);

            PlayTimeLine.Push(new PlayInfo(GetChessPoint(btn), CurrentPlayer));

            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;

            ChangePlayer();

            if (isEndGame(btn))
            {
                if (btn.BackgroundImage == Player[0].Mark)
                {
                    NumberPlayerWin = 0;
                }
                else if (btn.BackgroundImage == Player[1].Mark)
                {
                    NumberPlayerWin = 1;
                }
                EndGame();
            }
        }
        //sự kiện click cho ô cờ
        private void Btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

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

            Mark(btn);

            PlayTimeLine.Push(new PlayInfo(GetChessPoint(btn), CurrentPlayer));

            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;

            ChangePlayer();

            if (playerMarked != null)
            {
                playerMarked(this, new ButtonClickEvent(GetChessPoint(btn)));
            }

            if (isEndGame(btn))
            {
                if (btn.BackgroundImage == Player[0].Mark)
                {
                    NumberPlayerWin = 0;
                }
                else if (btn.BackgroundImage == Player[1].Mark)
                {
                    NumberPlayerWin = 1;
                }
                EndGame();
            }
        }
示例#8
0
        public void OtherPlayerMark(Point point)
        {
            Button btn = Matrix[point.Y][point.X];

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

            Mark(btn);

            PlayTimeLine.Push(new PlayInfo(GetChessPoint(btn), CurrentPlayer));

            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;

            ChangePlayer();

            //tmCooldown.Start();
            //prcbTime.Value = 0;
            //socket.Send(new SocketData((int)SocketCommand.SEND_POINT, "", new Point(0, 0)));

            if (isEndGame(btn))
            {
                EndGame();
                socket.Send(new SocketData((int)SocketCommand.END_GAME, "", new Point()));
            }
        }
示例#9
0
        void btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

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

            PlayTimeLine.Push(new PlayInfo(GetChessPoint(btn), CurrentPlayer));

            CurrentPlayer = CurrentPlayer == 1 ? 0 : 1;

            ChangePlayer();

            tmCooldown.Start();
            pnlChessBoard.Enabled = false;
            prcbTime.Value        = 0;

            socket.Send(new SocketData((int)SocketCommand.SEND_POINT, "", GetChessPoint(btn)));
            undoToolStripMenuItem.Enabled = false;

            Listen();

            if (isEndGame(btn))
            {
                EndGame();
                socket.Send(new SocketData((int)SocketCommand.END_GAME, "", new Point()));
            }
        }
        public bool Redo()
        {
            if (UndoTimeLine.Count <= 0)
            {
                return(false);
            }

            bool isRedo1 = RedoStep();
            bool isRedo2 = RedoStep();

            PlayInfo oldPoint = PlayTimeLine.Peek();

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

            return(isRedo1 && isRedo2);
        }
        /// <summary>
        /// Đi lại cho quân cờ
        /// </summary>
        /// <returns></returns>
        public bool Undo()
        {
            if (PlayTimeLine.Count <= 0)
            {
                return(false);
            }

            bool isUndo1 = UndoAStep();
            bool isUndo2 = UndoAStep();

            if (PlayTimeLine.Count <= 0)
            {
                CurrentPlayer = 0;
            }
            else
            {
                PlayInfo oldPoint = PlayTimeLine.Peek();
                CurrentPlayer = oldPoint.CurrentPlayer == 1 ? 0 : 1;
            }

            return(isUndo1 && isUndo2);
        }