Esempio n. 1
0
        private void JoinGameButton_Click(object sender, EventArgs e)
        {
            string    ip = IPAddressInputTextBox.Text;
            IPAddress ipAddress;

            if (IPAddress.TryParse(ip, out ipAddress))
            {
                string username = UserNameTextBox2.Text;
                clientState = new ClientState(username);
                client      = new ClientNew(ipAddress, port, username, clientState);
                backgroundWorker1.DoWork        += PictureBoxUpdated;
                client.OtherPlayerNamesReceived += OnOtherPlayerNamesReceived;
                client.UserCardsReceived        += OnUserCardsReceived;
                client.CurrentCardReceived      += OnCurrentCardReceived;
                client.Start();
            }
            else
            {
                MessageBox.Show("IP incorrectly entered, try again!");
            }
        }
Esempio n. 2
0
        private bool JoinServer(string username, IPAddress ipAddress)
        {
            clientState = new ClientState(username);
            client      = new ClientNew(ipAddress, port, username, clientState);

            client.UserCardsReceived        += Client_UserCardsReceived;
            client.CurrentCardReceived      += Client_CurrentCardReceived;
            client.OtherPlayerCardsReceived += Client_OtherPlayerCardsReceived;
            client.OtherPlayerNamesReceived += Client_OtherPlayerNamesReceived;

            try
            {
                client.Start();
                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Some error occured, " + e.ToString());
                MessageBox.Show("Error, try again", "Connection failed", MessageBoxButtons.OK);
                Debug.WriteLine(e.ToString());
                return(false);
            }
        }
Esempio n. 3
0
 private bool StartServer(string username)
 {
     server = new ServerNew(gameState);
     server.PlayersChanged += GameState_PlayersChanged;
     if (server.Initialize(username))
     {
         //Server started successfully, begin accepting connections
         server.StartAccept();
         IPAddress ip = server.GetIPAddress();
         clientState = new ClientState(username);
         client      = new ClientNew(ip, port, username, clientState);
         client.UserCardsReceived        += Client_UserCardsReceived;
         client.CurrentCardReceived      += Client_CurrentCardReceived;
         client.OtherPlayerCardsReceived += Client_OtherPlayerCardsReceived;
         client.OtherPlayerNamesReceived += Client_OtherPlayerNamesReceived;
         client.Start();
         return(true);
     }
     else
     {
         return(false);
     }
 }