Beispiel #1
0
        //in case of connection detected
        private void server_Connection(object sender, commArgs e)
        {
            label_Status_CoToClient.ForeColor = Color.Black;
            label_Status_CoToClient.Text      = e.Info;
            if (radioButtonHost.Checked && server.isConnected)
            {
                //When connexion is established with client:
                panelHost.Enabled    = false;
                panel_Config.Enabled = true;
                panel_Player.Enabled = true;
                buttonReady.Enabled  = true;
                isHost = true;
                //every client is listening when created
                //for (int client = 0; client < server.ClientList.Count; client++)
                //{
                //    server.ClientList[client].ReceiveData();
                //}
            }
            else
            {
                panelHost.Enabled    = true;
                panel_Config.Enabled = false;
                panel_Player.Enabled = false;
                buttonReady.Enabled  = false;
                isHost = true;

                label_Status_CoToClient.ForeColor = Color.DarkRed;
            }
        }
 //onInfoExchange
 private void client_infoExchange(object sender, commArgs e)
 {
     if (e.Reception)
     {
         if (e.ObjectData is int[])
         {
             foreach (Control grid_9x9 in this.panel_SudokuGrid.Controls)
             {
                 if (grid_9x9 is Grid_9x9)
                 {
                     foreach (Control grid_3x3 in grid_9x9.Controls)
                     {
                         if (grid_3x3 is Grid_3x3)
                         {
                             foreach (Sudoku_Label_Nbr caseLabel in grid_3x3.Controls)
                             {
                                 if (caseLabel.Coordinates[0] == ((int[])e.ObjectData)[0] && caseLabel.Coordinates[1] == ((int[])e.ObjectData)[1])
                                 {
                                     receivedCase         = caseLabel;
                                     receivedCase.Text    = ((int[])e.ObjectData)[2].ToString();
                                     receivedCase.isRight = true;
                                     Console.WriteLine("We received a case ! Coordinates are : [ " + receivedCase.Coordinates[0] + " , " + receivedCase.Coordinates[1] + " ]" +
                                                       "\nAnd the number is " + receivedCase.Text);
                                     receivedCase.BackColor = Color.DeepSkyBlue;
                                     hiddenCount           -= 1;
                                     Console.WriteLine(hiddenCount + "case(s) left to find until the end !");
                                     checkEndGame();
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else if (e.ObjectData is Sudoku_Nbrs_Gen)
         {
             generatedGridNbrs = (Sudoku_Nbrs_Gen)e.ObjectData;
             visualGrid.Fill(generatedGridNbrs);
             //hiddenCount = visualGrid.HideDetermined(generatedGridNbrs.NumbersToKeep);
             visualGrid.HideDetermined(generatedGridNbrs.NumbersToKeep);
         }
         else if (e.ObjectData is string)
         {
             switch (((string)e.ObjectData).Split(',')[0])
             {
             case "hiddenCount":
                 hiddenCount = int.Parse(((string)e.ObjectData).Split(',')[1]);
                 break;
             }
         }
         else
         {
             Console.WriteLine("Data received but not managed");
         }
     }
 }
Beispiel #3
0
 //managing communication
 private void messageCommunication(commArgs e)
 {
     if (((string)e.ObjectData).Split('§')[0] == "name")
     {
         label_NameOtherPlayer.Text = ((string)e.ObjectData).Split('§')[1];
     }
     else if (((string)e.ObjectData).Split('§')[0] == "msg")
     {
         label_MsgReceived.Text = ((string)e.ObjectData).Split('§')[1];
     }
 }
Beispiel #4
0
 private void server_InfoExchange(object sender, commArgs e)
 {
     if (this.Visible) //because when the Game_Window will be opened, we don't want this to be triggered !
     {
         try
         {
             //We don't want to react if this is the server that sent the name, so we only care if this message is received
             if (e.Reception)
             {
                 messageCommunication(e);
             }
         }
         catch (Exception exc)
         {
             Console.WriteLine(exc);
         }
     }
 }
 private void server_InfoExchange(object sender, commArgs e)
 {
     if (e.Reception)
     {
         if (e.ObjectData is int[])
         {
             foreach (Control grid_9x9 in this.panel_SudokuGrid.Controls)
             {
                 if (grid_9x9 is Grid_9x9)
                 {
                     foreach (Control grid_3x3 in grid_9x9.Controls)
                     {
                         if (grid_3x3 is Grid_3x3)
                         {
                             foreach (Sudoku_Label_Nbr caseLabel in grid_3x3.Controls)
                             {
                                 if (caseLabel.Coordinates[0] == ((int[])e.ObjectData)[0] && caseLabel.Coordinates[1] == ((int[])e.ObjectData)[1])
                                 {
                                     receivedCase         = caseLabel;
                                     receivedCase.Text    = ((int[])e.ObjectData)[2].ToString();
                                     receivedCase.isRight = true;
                                     Console.WriteLine("We received a case ! Coordinates are : [ " + receivedCase.Coordinates[0] + " , " + receivedCase.Coordinates[1] + " ]" +
                                                       "\nAnd the number is " + receivedCase.Text);
                                     receivedCase.BackColor = Color.DeepSkyBlue;
                                     hiddenCount           -= 1;
                                     Console.WriteLine(hiddenCount + "case(s) left to find until the end !");
                                     checkEndGame();
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             Console.WriteLine("Data received but not managed");
         }
     }
 }
Beispiel #6
0
 private void client_Connection(object sender, commArgs e)
 {
     label_Status_CoToHost.ForeColor = Color.Black;
     label_Status_CoToHost.Text      = e.Info;
     if (client.isConnected)
     {
         panelClient.Enabled  = false;
         panel_Player.Enabled = true;
         buttonReady.Text     = "En attente de l'hôte";
         client.ReceiveData();
     }
     else
     {
         panelClient.Enabled             = true;
         panel_Player.Enabled            = false;
         buttonReady.Enabled             = false;
         label_Status_CoToHost.ForeColor = Color.DarkRed;
         //connexion lost with server, mandatory to restart
         radioButtonHost.Checked = true;
         radioButtonHost_MouseDown(this, null);
     }
 }
Beispiel #7
0
        //delegate methode for events on Info Exchange
        private void client_infoExchange(object sender, commArgs e)
        {
            if (this.Visible) //because when the Game_Window will be opened, we don't want this to be triggered !
            {
                try
                {
                    //We don't want to react if this is the client that sent the name, so we only care if this message is received
                    if (e.Reception)
                    {
                        messageCommunication(e);
                        switch (((string)e.ObjectData).Split(',')[0])
                        {
                        case "Difficulty":
                            comboBox_Difficulty.SelectedIndex = int.Parse(((string)e.ObjectData).Split(',')[1]);
                            break;

                        case "GameMode":
                            comboBox_GameMode.SelectedIndex = int.Parse(((string)e.ObjectData).Split(',')[1]);
                            break;

                        case "LaunchGame":
                            buttonReady_Click(this, null);
                            break;
                        }
                    }
                    if (e.Info == "Connexion Lost with the Server.")
                    {
                        panelClient.Enabled  = true;
                        panel_Player.Enabled = false;
                        buttonReady.Enabled  = false;
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc);
                }
            }
        }