コード例 #1
0
 public Player(int id, Version serverversion, ICommunicateable communicator, bool full, System.Object obj) : base()
 {
     try
     {
         Id           = id;
         Deposit      = new Deposit(this, (Stocks)obj);
         ValueHistory = new DoubleHistory();
         ClientCommunication(serverversion, communicator, full, obj);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
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;
     }
 }
コード例 #3
0
 public void ClientBuyingStocks(Version serverversion, ICommunicateable communicator, INetworkTradeable tradeable, MarketState marketstate, int stockstobuy)
 {
     try
     {
         if (serverversion.Major > 0)
         {
             lock (SynchronizeRoot)
             {
                 tradeable.ClientBuyStocks(serverversion, communicator, marketstate, stockstobuy);
             }
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #4
0
 public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (serverversion.Major > 0)
         {
             State     = (MarketStateType)communicator.ReceiveInt();
             Epochs    = communicator.ReceiveInt();
             Brokerage = communicator.ReceiveDouble();
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #5
0
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             communicator.SendInt((int)State);
             communicator.SendInt(Epochs);
             communicator.SendDouble(Brokerage);
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #6
0
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             communicator.SendInt(Count);
             communicator.SendDouble(LastBuyPrice);
             communicator.SendDouble(LastSellPrice);
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #7
0
 public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (serverversion.Major > 0)
         {
             Count         = communicator.ReceiveInt();
             LastBuyPrice  = communicator.ReceiveDouble();
             LastSellPrice = communicator.ReceiveDouble();
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #8
0
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             if (full)
             {
                 communicator.SendString(Id);
                 communicator.SendString(Name);
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #9
0
 public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (serverversion.Major > 0)
         {
             if (full)
             {
                 Id   = communicator.ReceiveString();
                 Name = communicator.ReceiveString();
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #10
0
 public void ClientBuyingStocks(Version clientversion, ICommunicateable communicator, string stockid, Player player)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             lock (SynchronizeRoot)
             {
                 DepositContent content = null;
                 if (player.Deposit.TryGetValue(stockid, out content))
                 {
                     content.ServerBuyStocks(clientversion, communicator);
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #11
0
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             communicator.SendInt(this.Count);
             if (this.Count > 0)
             {
                 foreach (INetworkable n in this.Values)
                 {
                     n.ServerCommunication(clientversion, communicator, full, obj);
                 }
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #12
0
 public System.Object ServerCommunication(Version clientversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             communicator.SendInt(this.Count);
             if (this.Count > 0)
             {
                 foreach (double d in this)
                 {
                     communicator.SendDouble(d);
                 }
             }
         }
         return(this);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #13
0
 public void ServerSellStocks(Version clientversion, ICommunicateable communicator)
 {
     try
     {
         if (clientversion.Major > 0)
         {
             int    stockstosell = communicator.ReceiveInt();
             double stockprice   = communicator.ReceiveDouble();
             double price        = communicator.ReceiveDouble();
             double brokerage    = communicator.ReceiveDouble();
             if (stockstosell > 0 && stockstosell < Count && price >= brokerage)
             {
                 Count -= stockstosell;
                 Stock.OwnedByPlayers -= stockstosell;
                 Stock.Available      += stockstosell;
                 if (Count <= 0)
                 {
                     LastBuyPrice  = 0;
                     LastSellPrice = 0;
                 }
                 else
                 {
                     LastSellPrice = stockprice;
                 }
                 Deposit.Player.Capital += price - brokerage;
             }
             communicator.SendInt(Count);
             communicator.SendInt(Stock.OwnedByPlayers);
             communicator.SendInt(Stock.Available);
             communicator.SendDouble(LastBuyPrice);
             communicator.SendDouble(LastSellPrice);
             communicator.SendDouble(Deposit.Player.Capital);
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #14
0
 public void ClientSellStocks(Version serverversion, ICommunicateable communicator, MarketState marketstate, int stockstosell)
 {
     try
     {
         if (serverversion.Major > 0)
         {
             communicator.SendInt(stockstosell);
             communicator.SendDouble(Stock.Price);
             communicator.SendDouble(Stock.CalculatePrice(stockstosell));
             communicator.SendDouble(Stock.CalculateBrokerage(marketstate, stockstosell));
             Count = communicator.ReceiveInt();
             Stock.OwnedByPlayers   = communicator.ReceiveInt();
             Stock.Available        = communicator.ReceiveInt();
             LastBuyPrice           = communicator.ReceiveDouble();
             LastSellPrice          = communicator.ReceiveDouble();
             Deposit.Player.Capital = communicator.ReceiveDouble();
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
コード例 #15
0
 public System.Object ClientCommunication(Version serverversion, ICommunicateable communicator, bool full, System.Object obj)
 {
     try
     {
         if (serverversion.Major > 0)
         {
             while (NewPlayers.Count > 0)
             {
                 NewPlayers.Clear();
             }
             while (DisconnectedPlayers.Count > 0)
             {
                 DisconnectedPlayers.Clear();
             }
             DisconnectedPlayers.AddRange(this);
             int c = communicator.ReceiveInt();
             if (c > 0)
             {
                 for (int i = 0; i < c; i++)
                 {
                     int  playerid      = communicator.ReceiveInt();
                     bool containplayer = Contains(playerid);
                     communicator.SendBool(containplayer);
                     if (!containplayer)
                     {
                         Player player = new Player(playerid, serverversion, communicator, true, obj);
                         this.Add(player);
                         NewPlayers.Add(player);
                     }
                     else
                     {
                         Player player = GetPlayer(playerid);
                         player.ClientCommunication(serverversion, communicator, false, obj);
                         while (DisconnectedPlayers.Contains(player))
                         {
                             DisconnectedPlayers.Remove(player);
                         }
                     }
                 }
             }
             if (DisconnectedPlayers.Count > 0)
             {
                 foreach (Player p in DisconnectedPlayers)
                 {
                     while (this.Contains(p))
                     {
                         this.Remove(p);
                     }
                 }
             }
         }
         foreach (Player player in this)
         {
             if (player.IsYou)
             {
                 return(player);
             }
         }
         return(null);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }