Esempio n. 1
0
 public DataPacket createDataPacket(string newName, int newScore, Dictionary<string, int> newHighscoresList)
 {
     DataPacket packet = new DataPacket();
     packet.name = newName;
     packet.score = newScore;
     packet.highscores = newHighscoresList;
     return packet;
 }
Esempio n. 2
0
 public void addHighscore(DataPacket newHighscore)
 {
     DataPacket highscore = newHighscore;
     ServerView.writeToConsole("Received new score (Name: "+highscore.name+", score: "+highscore.score+")");
     highscores = highscores.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
     if (highscore.score > highscores.Values.Last() || highscores.Count < 6)
     {
         foreach(KeyValuePair<string, int> pair in highscores)
         {
             if(pair.Key == highscore.name && pair.Value < highscore.score)
             {
                 highscores.Remove(pair.Key);
                 break;
             }
         }
     }
     highscores.Add(highscore.name, highscore.score);
     highscores = highscores.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
     if (highscores.Count > 5) highscores.Remove(highscores.Keys.Last());
     finalizeData();
 }
Esempio n. 3
0
 public void addHighscore(DataPacket highscore)
 {
     serverModel.addHighscore(highscore);
 }
Esempio n. 4
0
 public void handleDataPacket(DataPacket data)
 {
     if (data.name == "updateHighscores") gameLogic.setHighscores(data);
 }
Esempio n. 5
0
 public void sendToServer(DataPacket data)
 {
     try
     {
         formatter.Serialize(sslStream, data);
     }
     catch
     {
         Console.WriteLine("Could not send data to server.");
     }
 }
Esempio n. 6
0
 public void setHighscores(DataPacket data)
 {
     highscores = data.highscores;
     mainForm.setHighScoreListInfoDictionary(highscores);
 }
Esempio n. 7
0
 public void sendHighscore(DataPacket highscore)
 {
     networkClient.sendToServer(highscore);
 }
Esempio n. 8
0
 public void saveHighScoreDictionary(DataPacket highscore)
 {
     highscores = highscores.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
     if (highscore.score > highscores.Values.Last() || highscores.Count <= 4)
     {
         if (highscores.Count >= 4) highscores.Remove(highscores.Keys.Last());
         highscores.Add(highscore.name, highscore.score);
     }
     highscores = highscores.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
 }
Esempio n. 9
0
 public void handleDataPacket(DataPacket data)
 {
     //if (data.name == "exit") disconnect();
     serverControl.addHighscore(data);
 }
Esempio n. 10
0
 public void sendDataToClient(DataPacket data)
 {
     try
     {
         formatter.Serialize(clientStream, data);
     }
     catch
     {
     }
 }