Exemple #1
0
 public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (serverversion.Major > 0)
         {
             lock (SynchronizeRoot)
             {
                 if (full)
                 {
                     // Send information about the client.
                     communicator.SendString(CurrentPlayer.Company);
                     communicator.SendString(CurrentPlayer.Name);
                     // Clear and reset game informations.
                     while (PlayTimer.Enabled)
                     {
                         PlayTimer.Stop();
                     }
                     while (StockIndexes.Count > 0)
                     {
                         StockIndexes.Clear();
                     }
                     while (Stocks.Count > 0)
                     {
                         Stocks.Clear();
                     }
                     while (Players.Count > 0)
                     {
                         Players.Clear();
                     }
                     MarketState.Reset(Random);
                     CurrentPlayer = null;
                 }
                 // Receive new game informations.
                 StockIndexes.ClientCommunication(serverversion, communicator, full, null);
                 Stocks.ClientCommunication(serverversion, communicator, full, StockIndexes);
                 CurrentPlayer = (Player)Players.ClientCommunication(serverversion, communicator, full, Stocks);
                 MarketState.ClientCommunication(serverversion, communicator, full, null);
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
Exemple #2
0
 public void Reset(System.Random random, bool startingserver)
 {
     try
     {
         bool b = true;
         if (BeforeResetEvent != null && !startingserver)
         {
             b = BeforeResetEvent();
         }
         if (b)
         {
             while (PlayTimer.Enabled)
             {
                 PlayTimer.Stop();
             }
             FileName = null;
             Stocks.Reset(random);
             Players.Reset(random);
             MarketState.Reset(random);
             while (!PlayTimer.Enabled)
             {
                 PlayTimer.Start();
             }
             if (AfterResetEvent != null && !startingserver)
             {
                 AfterResetEvent();
             }
             if (UpdateStockInformationsEvent != null)
             {
                 UpdateStockInformationsEvent();
             }
             if (UpdatePlayerInformationsEvent != null)
             {
                 UpdatePlayerInformationsEvent();
             }
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
Exemple #3
0
 public System.Object Load(Version fv, WsgFileStream fs, System.Object obj)
 {
     try
     {
         if (BeforeLoadEvent != null)
         {
             BeforeLoadEvent();
         }
         if (fv.Major > 0)
         {
             while (PlayTimer.Enabled)
             {
                 PlayTimer.Stop();
             }
             fs.Seek(0, System.IO.SeekOrigin.Begin);
             Version loadedfv = (Version)FileVersion.Load(fv, fs, null);
             while (StockIndexes.Count > 0)
             {
                 StockIndexes.Clear();
             }
             while (Stocks.Count > 0)
             {
                 Stocks.Clear();
             }
             while (Players.Count > 0)
             {
                 Players.Clear();
             }
             MarketState.Reset(Random);
             CurrentPlayer = null;
             StockIndexes.Load(loadedfv, fs, null);
             Stocks.Load(loadedfv, fs, StockIndexes);
             CurrentPlayer = (Player)Players.Load(loadedfv, fs, Stocks);
             MarketState.Load(loadedfv, fs, null);
             FileName = fs.Name;
             while (!PlayTimer.Enabled)
             {
                 PlayTimer.Start();
             }
         }
         if (AfterLoadEvent != null)
         {
             AfterLoadEvent();
         }
         if (UpdateStockInformationsEvent != null)
         {
             UpdateStockInformationsEvent();
         }
         if (UpdatePlayerInformationsEvent != null)
         {
             UpdatePlayerInformationsEvent();
         }
         return(this);
     }
     catch (VersionNotSupportedException ex)
     {
         while (!PlayTimer.Enabled)
         {
             PlayTimer.Start();
         }
         throw ex;
     }
     catch (System.Exception ex)
     {
         while (!PlayTimer.Enabled)
         {
             PlayTimer.Start();
         }
         throw ex;
     }
 }