示例#1
0
 private void ResetButton()
 {
     this.Dispatcher.Invoke(() =>
     {
         foreach (Button Bt in CaroButt)
         {
             BoxInformation Infor = (BoxInformation)Bt.Tag;
             Infor.Checked        = false;
             if ((Infor.Row + Infor.Col) % 2 == 0)
             {
                 Bt.Background = Brushes.Gray;
             }
             else
             {
                 Bt.Background = Brushes.LightGray;
             }
         }
     });
 }
示例#2
0
        private void Check(bool isMe, Button BeCheckedButt)
        {
            BoxInformation Infor = (BoxInformation)BeCheckedButt.Tag;

            if (Infor.Checked == true)
            {
                return;
            }

            if (isMe == true)
            {
                BeCheckedButt.Background = Brushes.Black;
                GomokuSocket.Emit("MyStepIs", JObject.FromObject(new { row = Infor.Row, col = Infor.Col }));
            }
            else
            {
                BeCheckedButt.Background = Brushes.White;
            }

            Infor.Checked = true;
            YourTurn      = !YourTurn;
        }
示例#3
0
        private void Check_Click(object sender, RoutedEventArgs e)
        {
            Button         Bt    = (Button)sender;
            BoxInformation Infor = (BoxInformation)Bt.Tag;
            int            Row   = Infor.Row;
            int            Col   = Infor.Col;

            if (isWaiting)
            {
                return;
            }

            if (Board.CurrentMode == PlayMode.Offline || Board.CurrentMode == PlayMode.Machine)
            {
                Brush BackupBackGround = Bt.Background;
                bool  isValid          = true;

                if (Board.PlayingPlayer == State.Player1)
                {
                    Bt.Background = Brushes.Black;
                }
                if (Board.PlayingPlayer == State.Player2)
                {
                    Bt.Background = Brushes.White;
                }

                this.Dispatcher.Invoke(() =>
                {
                    isValid = PlayBoard.Place(Row, Col);
                    if (!isValid)
                    {
                        Bt.Background = BackupBackGround;
                        return;
                    }

                    if (Board.CurrentMode == PlayMode.Machine)
                    {
                        Thread AIThread = new Thread(PlayBoard.AIPlace); //Create a new thread to run AI algorithm
                        AIThread.Start();
                    }
                });

                if (isWin)
                {
                    isWin = false;
                    return;
                }

                if (Board.CurrentMode == PlayMode.Machine && isValid)
                {
                    isWaiting            = true;
                    Mouse.OverrideCursor = Cursors.Wait;
                }
            }
            if (Board.CurrentMode == PlayMode.Online)
            {
                if (YourTurn == true)
                {
                    Check(true, Bt);
                }
                else
                {
                    PushMessage("That's not your turn", "Server");
                }
            }
        }