コード例 #1
0
ファイル: ServerControl.cs プロジェクト: rvnijnatten/De-Fles
 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;
 }
コード例 #2
0
ファイル: ServerModel.cs プロジェクト: rvnijnatten/De-Fles2
 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();
 }
コード例 #3
0
ファイル: ServerControl.cs プロジェクト: rvnijnatten/De-Fles
 public void addHighscore(DataPacket highscore)
 {
     serverModel.addHighscore(highscore);
 }
コード例 #4
0
ファイル: NetworkClient.cs プロジェクト: rvnijnatten/De-Fles
 public void handleDataPacket(DataPacket data)
 {
     if (data.name == "updateHighscores") gameLogic.setHighscores(data);
 }
コード例 #5
0
ファイル: NetworkClient.cs プロジェクト: rvnijnatten/De-Fles
 public void sendToServer(DataPacket data)
 {
     try
     {
         formatter.Serialize(sslStream, data);
     }
     catch
     {
         Console.WriteLine("Could not send data to server.");
     }
 }
コード例 #6
0
ファイル: GameLogic.cs プロジェクト: rvnijnatten/De-Fles
 public void setHighscores(DataPacket data)
 {
     highscores = data.highscores;
     mainForm.setHighScoreListInfoDictionary(highscores);
 }
コード例 #7
0
ファイル: GameLogic.cs プロジェクト: rvnijnatten/De-Fles
 public void sendHighscore(DataPacket highscore)
 {
     networkClient.sendToServer(highscore);
 }
コード例 #8
0
ファイル: GameLogic.cs プロジェクト: rvnijnatten/De-Fles
 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);
 }
コード例 #9
0
ファイル: Client.cs プロジェクト: rvnijnatten/De-Fles2
 public void handleDataPacket(DataPacket data)
 {
     //if (data.name == "exit") disconnect();
     serverControl.addHighscore(data);
 }
コード例 #10
0
ファイル: Client.cs プロジェクト: rvnijnatten/De-Fles2
 public void sendDataToClient(DataPacket data)
 {
     try
     {
         formatter.Serialize(clientStream, data);
     }
     catch
     {
     }
 }