Пример #1
0
 private void reset()
 {
     AlreadyWin       = false;
     pictureBox1.Left = -100;
     pictureBox1.Top  = -100;
     pictureBox2.Left = -100;
     pictureBox2.Top  = -100;
     who = true;
     if (isAI)
     {
         for (int i = 0; i < 17; i++)
         {
             for (int j = 0; j < 17; j++)
             {
                 piece rr = aigame.re(i, j);
                 this.Controls.Remove(rr);
             }
         }
         aigame = new AI();
     }
     else
     {
         for (int i = 0; i < 17; i++)
         {
             for (int j = 0; j < 17; j++)
             {
                 piece rr = game.re(i, j);
                 this.Controls.Remove(rr);
             }
         }
         game = new Game();
     }
 }
Пример #2
0
 private void reset()
 {
     AlreadyWin       = false;
     pictureBox1.Left = -100;
     pictureBox1.Top  = -100;
     pictureBox2.Left = -100;
     pictureBox2.Top  = -100;
     who = true;
     if (gamemode == 0)
     {
         for (int i = 0; i < 17; i++)
         {
             for (int j = 0; j < 17; j++)
             {
                 piece rr = aigame.re(i, j);
                 this.Controls.Remove(rr);
             }
         }
         aigame = new AI();
     }
     else if (gamemode == 1 || gamemode == 2)
     {
         for (int i = 0; i < 17; i++)
         {
             for (int j = 0; j < 17; j++)
             {
                 piece rr = game.re(i, j);
                 this.Controls.Remove(rr);
             }
         }
         game = new Game();
         if (gamemode == 2)
         {
             T.Close();
             Thread.Sleep(150);//為了讓rec關閉
             connect_server();
             Thread temp = new Thread(ThreadRecieve);
             temp.IsBackground = true;
             temp.Start();
             temp.Join();
             if (msg == "1")
             {
                 issend = false;
             }
             else
             {
                 issend = true;
             }
             CheckForIllegalCrossThreadCalls = false;
             who = true;
             rec = new Thread(OppenentRound);
             rec.IsBackground = true;
             rec.Start();
             gamemode = 2;
             //flag = false;
         }
     }
 }
Пример #3
0
 private void AddObject(piece p)
 {
     if (this.InvokeRequired)
     {
         var d = new SafeCallDelegate(AddObject);//https://docs.microsoft.com/zh-tw/dotnet/desktop/winforms/controls/how-to-make-thread-safe-calls-to-windows-forms-controls?view=netframeworkdesktop-4.8
         this.Invoke(d, new object[] { p });
     }
     else
     {
         this.Controls.Add(p);
     }
 }
Пример #4
0
Файл: AI.cs Проект: tkz05/GOMOKU
        public piece AINextPiece()
        {
            piece p = NewMethod();

            if (p != null)
            {
                whowin();
                nexttype = Ptype.BLACK;
                return(p);
            }
            return(null);
        }
Пример #5
0
Файл: AI.cs Проект: tkz05/GOMOKU
        public override piece placepiece(int x, int y)
        {
            piece p = board.bePlace(x, y, Ptype.BLACK, true);//獲取棋子下哪

            NowPlace        = board.Findnode(x, y);
            OriginalPlace.X = x;
            OriginalPlace.Y = y;
            if (p != null)
            {
                whowin();  //檢查是否有人獲勝
                nexttype = Ptype.WHITE;
                return(p); //回傳棋子資訊
            }
            return(null);
        }
Пример #6
0
        /*public Point Wherenode(int x,int y)
         * {
         *  return board.wherenode(x,y);
         * }*/
        public virtual piece  placepiece(int x, int y)
        {
            piece p = board.bePlace(x, y, nexttype, true);//獲取棋子下哪

            if (p != null)
            {
                whowin();//檢查是否有獲勝

                //更改下一顆棋子的顏色
                if (nexttype == Ptype.BLACK)
                {
                    nexttype = Ptype.WHITE;
                }
                else if (nexttype == Ptype.WHITE)
                {
                    nexttype = Ptype.BLACK;
                }

                return(p);//回傳棋子資訊
            }
            return(null);
        }
Пример #7
0
 private void WinMessage(piece p)
 {
     if (p != null)
     {
         if (gamemode == 0)
         {
             Point PP = aigame.Pictureboxpoint();
             if (who)
             {
                 pictureBox1.Left = PP.X;
                 pictureBox1.Top  = PP.Y;
                 pictureBox1.BringToFront();
                 who = false;
             }
             else
             {
                 pictureBox2.Left = PP.X;
                 pictureBox2.Top  = PP.Y;
                 pictureBox2.BringToFront();
                 who = true;
             }
         }
         else if (gamemode == 1 || gamemode == 2)
         {
             Point PP = game.Pictureboxpoint();
             if (who)
             {
                 pictureBox1.Left = PP.X;
                 pictureBox1.Top  = PP.Y;
                 pictureBox1.BringToFront();
                 who = false;
             }
             else
             {
                 pictureBox2.Left = PP.X;
                 pictureBox2.Top  = PP.Y;
                 pictureBox2.BringToFront();
                 who = true;
             }
         }
         AddObject(p);
         if (gamemode == 0)
         {
             if (aigame.Winner == Ptype.BLACK)
             {
                 MessageBox.Show("黑色獲勝");
                 AlreadyWin = true;
             }
             else if (aigame.Winner == Ptype.WHITE)
             {
                 MessageBox.Show("白色獲勝");
                 AlreadyWin = true;
             }
         }
         else if (gamemode == 1)
         {
             //看Game裡的Winner傳出的勝利者是誰
             if (game.Winner == Ptype.BLACK)
             {
                 MessageBox.Show("黑色獲勝");
                 AlreadyWin = true;
             }
             else if (game.Winner == Ptype.WHITE)
             {
                 MessageBox.Show("白色獲勝");
                 AlreadyWin = true;
             }
         }
         else if (gamemode == 2)
         {
             //看Game裡的Winner傳出的勝利者是誰
             if (game.Winner == Ptype.BLACK)
             {
                 MessageBox.Show("黑色獲勝");
                 AlreadyWin = true;
                 Send("black");
             }
             else if (game.Winner == Ptype.WHITE)
             {
                 MessageBox.Show("白色獲勝");
                 AlreadyWin = true;
                 Send("white");
             }
         }
     }
 }
Пример #8
0
        public piece re(int i, int j)
        {
            piece p = board.Re(i, j);

            return(p);
        }
Пример #9
0
 private void WinMessage(piece p)
 {
     if (p != null)
     {
         if (isAI)
         {
             Point PP = aigame.Pictureboxpoint();
             if (who)
             {
                 pictureBox1.Left = PP.X;
                 pictureBox1.Top  = PP.Y;
                 pictureBox1.BringToFront();
                 who = false;
             }
             else
             {
                 pictureBox2.Left = PP.X;
                 pictureBox2.Top  = PP.Y;
                 pictureBox2.BringToFront();
                 who = true;
             }
         }
         else
         {
             Point PP = game.Pictureboxpoint();
             if (who)
             {
                 pictureBox1.Left = PP.X;
                 pictureBox1.Top  = PP.Y;
                 pictureBox1.BringToFront();
                 who = false;
             }
             else
             {
                 pictureBox2.Left = PP.X;
                 pictureBox2.Top  = PP.Y;
                 pictureBox2.BringToFront();
                 who = true;
             }
         }
         this.Controls.Add(p);//拿到的棋子資訊就顯示在視窗
         if (isAI)
         {
             if (aigame.Winner == Ptype.BLACK)
             {
                 MessageBox.Show("黑色獲勝");
                 AlreadyWin = true;
             }
             else if (aigame.Winner == Ptype.WHITE)
             {
                 MessageBox.Show("白色獲勝");
                 AlreadyWin = true;
             }
         }
         else
         {
             //看Game裡的Winner傳出的勝利者是誰
             if (game.Winner == Ptype.BLACK)
             {
                 MessageBox.Show("黑色獲勝");
                 reset();
             }
             else if (game.Winner == Ptype.WHITE)
             {
                 MessageBox.Show("白色獲勝");
                 reset();
             }
         }
     }
 }