Пример #1
0
 //Server callbacks
 /// <summary>
 /// Updates the info to the server callback
 /// </summary>
 /// <param name="newInfo">New game information</param>
 public void UpdateInfo(GameInformation newInfo)
 {
     if (System.Threading.Thread.CurrentThread == this.Dispatcher.Thread)
     {
         listPlayers.ItemsSource = null;
         listMessages.ItemsSource = null;
         listPlayers.ItemsSource = newInfo.Scoreboard;
         listMessages.ItemsSource = newInfo.Messages;
         _food = newInfo.FoodLocation;
     }
     else
         this.Dispatcher.BeginInvoke(new InfoUpdateDelegate(UpdateInfo), newInfo);
 }
Пример #2
0
 //fix sending multiple times
 /// <summary>
 /// Adds messages to the List<string> of messages, checks to see
 /// the level of message reporting from the MSGLEVEL and CONSOLELVL
 /// It then creates a GameInformation object and sends that to the client
 /// </summary>
 /// <param name="code">Level of message reporting</param>
 /// <param name="message">Contents of message</param>
 public void postMessage(int code, string message)
 {
     if (code <= MSGLEVEL)
     {
         _messages.Insert(0, message);
         if (clientCallbacks.Count != 0)
         {
             GameInformation newInfo = new GameInformation(getScoreboard(), _messages.ToArray<string>(), _foodLocation);
             foreach (ICallback c in clientCallbacks.Values)
                 c.UpdateInfo(newInfo);
         }
     }
     if (code <= CONSOLELEVEL)
     {
         string level = "";
         switch (code)
         {
             case 0:  level = "IMPORTANT: "; break;
             case 1:  level = "INFO:  ";     break;
             case 2:  level = "DEBUG: ";     break;
             case 3:  level = "VERBOSE: ";   break;
             default: level = "NONE: ";      break;
         }
         Console.WriteLine(level + message);
     }
 }