예제 #1
0
파일: Form1.cs 프로젝트: jolammi/DS2020-RPS
        public void ScreenChanger(int screenOrder)
        {
            switch (screenOrder)
            {
            case 0:
            {
                aliasBox.Show();
                IPBox.Show();
                acceptButton.Show();
                quitButton1.Show();

                countLabel.Hide();
                outcomeLabel.Hide();
                quitButton.Hide();
                rockButton.Hide();
                paperButton.Hide();
                scissorButton.Hide();
                break;
            }

            case 1:
            {
                countLabel.Show();
                outcomeLabel.Show();
                rockButton.Show();
                paperButton.Show();
                scissorButton.Show();
                aliasBox.Show();
                IPBox.Show();
                acceptButton.Show();
                quitButton.Show();

                aliasBox.Hide();
                IPBox.Hide();
                acceptButton.Hide();
                quitButton1.Hide();
                break;
            }
            }
        }
예제 #2
0
        private void connectClient_Click(object sender, EventArgs e)    //When this button is clicked, the client sends an address and port to
                                                                        //find a server.
        {
            client = new TcpClient();
            System.Threading.Thread.Sleep(600);
            //User given the option to input an IP address.
            IPEndPoint IP = new IPEndPoint(IPAddress.Parse(IPBox.Text), Int32.Parse(portBox.Text));

            try
            {
                client.Connect(IP);
                if (client.Connected)
                {
                    read            = new StreamReader(client.GetStream());
                    write           = new StreamWriter(client.GetStream());
                    write.AutoFlush = true;
                    //After attempting to connect, a backgroundworker is started.
                    backgroundWorker1.RunWorkerAsync();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //The following lines are written to hide and show controls accordingly.
            connectClient.Hide();
            startServer.Hide();
            label3.Hide();
            label4.Hide();
            IPBox.Hide();
            portBox.Hide();
            textBox1.Show();
            initializeShip();
            System.Threading.Thread.Sleep(1000);
            decideFirst();
            shootTip.Show();
        }
예제 #3
0
        private void startServer_Click(object sender, EventArgs e)      //When this button is clicked, a server is started,
                                                                        //where a listener is used to find a client.
        {
            TcpListener listen = new TcpListener(IPAddress.Any, 12345);

            listen.Start();
            client          = listen.AcceptTcpClient();
            read            = new StreamReader(client.GetStream());
            write           = new StreamWriter(client.GetStream());
            write.AutoFlush = true;
            //A backgroundworker is created to start receiving data.
            backgroundWorker1.RunWorkerAsync();
            //Methods to show and hide certain controls.
            textBox1.Show();
            startServer.Hide();
            connectClient.Hide();
            label3.Hide();
            label4.Hide();
            IPBox.Hide();
            portBox.Hide();
            initializeShip();
            decideFirst();
            shootTip.Show();
        }