Exemplo n.º 1
0
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            int w, h, r = 0, c = 0;

            if (iMatch.getPlayType() == 1)
            {
                w = pictureBox1.Width / 20;
                h = pictureBox1.Height / 20;
                c = (int)(e.X + w * 0.5) / w - 1;
                r = (int)(e.Y + h * 0.5) / h - 1;
                play(r, c, iMatch.getturn());
            }
            else if (iMatch.getPlayType() == 2)
            {
                int turn = iMatch.getturn();
                if (turn == 1)
                {
                    w = pictureBox1.Width / 20;
                    h = pictureBox1.Height / 20;
                    c = (int)(e.X + w * 0.5) / w - 1;
                    r = (int)(e.Y + h * 0.5) / h - 1;
                    play(r, c, turn);
                    autoPlay();
                }
            }
        }
Exemplo n.º 2
0
        private void RunServer()
        {
            //port는 8080으로 하고(보통8080port가 열려있습니다)
            //IP는 본인 컴퓨터 IP로 하세요..

            try
            {
                //IPAddress ipAddr = IPAddress.Parse("202.31.138.54");
                IPAddress ipAddr = IPAddress.Parse("202.31.201.212");
                //IPEndPoint ipep = new IPEndPoint(ipAddr, 9050);
                IPEndPoint  ipep        = new IPEndPoint(ipAddr, 8080);
                TcpListener newListener = new TcpListener(ipep);
                newListener.Start();
                TcpClient client = newListener.AcceptTcpClient();
                stream = client.GetStream();
                sr     = new StreamReader(stream);
                sw     = new StreamWriter(stream);
                IPEndPoint clientep = (IPEndPoint)client.Client.RemoteEndPoint;

                int r, c;
                while (!done)
                {
                    r = Int32.Parse(sr.ReadLine());
                    c = Int32.Parse(sr.ReadLine());
                    play(r, c, iMatch.getturn());
                }
            }
            catch (Exception error)
            {
                // handle exception if error in establishing connection
                MessageBox.Show(error.ToString(), "Connection Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.Environment.Exit(System.Environment.ExitCode);
            } // end catch
        }
Exemplo n.º 3
0
        // connect to server and display server-generated text
        public void RunClient()
        {
            TcpClient client;
            int       tryAgain = 0;

            // instantiate TcpClient for sending data to server
            while (tryAgain < 5)
            {
                try
                {
                    //port는 8080으로 하고(보통8080port가 열려있습니다)
                    //IP는 본인 컴퓨터 IP로 하세요..

                    DisplayStatusMessage("Attempting connection\r\n");

                    // Step 1: create TcpClient and connect to server
                    client = new TcpClient();
                    client.Connect("202.31.201.212", 8080); // 포트번호 수정  (2015.10.8)
                    // client.Connect("202.31.138.54", 9050);

                    // Step 2: get NetworkStream associated with TcpClient
                    output   = client.GetStream();
                    tryAgain = 5;

                    // create objects for writing and reading across stream

                    reader = new StreamReader(output);
                    writer = new StreamWriter(output);
                    DisplayStatusMessage("\r\nGot I/O streams\r\n");
                    // loop until server signals termination

                    int r, c;
                    while (!done)
                    {
                        r = Int32.Parse(reader.ReadLine());
                        c = Int32.Parse(reader.ReadLine());
                        play(r, c, iMatch.getturn());
                    }
                } // end try
                catch (Exception error)
                {
                    // handle exception if error in establishing connection
                    MessageBox.Show(error.ToString(), "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //System.Environment.Exit(System.Environment.ExitCode);
                    DisplayStatusMessage("Trying Again\r\n");
                    Thread.Sleep(1000);
                    tryAgain++;
                } // end catch
            }
        }         // end method RunClient