public GameResult SellGum(MarketGum gum, int quanitity) { if (this.OwnsGum(gum) == false) { return(GameResult.YouDontOwnThisGum); } if (this.HowManyOwned(gum) < quanitity) { return(GameResult.YouDontOwnEnough); } bool sellingAll = quanitity == this.HowManyOwned(gum); int proceeds = gum.CurrentPrice * quanitity; this.Money += proceeds; for (int i = 0; i < this.OwnedGums.Count; i++) { OwnedGum g = this.OwnedGums[i]; if (g.Name == gum.Name) { if (sellingAll) { this.OwnedGums.RemoveAt(i); } else { g.Quantity -= quanitity; } } } return(GameResult.Success); }
public void initialize() { this.Gums = new List <MarketGum>(); for (int i = 0; i < Settings.GUMS.Length; i++) { MarketGum gum = new MarketGum(Settings.GUMS[i], (i + 2) * 3, (i + 2) * 7, _player); this.Gums.Add(gum); } }
public int HowManyOwned(MarketGum gum) { foreach (OwnedGum g in this.OwnedGums) { if (g.Name == gum.Name) { return(g.Quantity); } } return(0); }
private GameResult buyGum(MarketGum gum, int quantity, int transactionCost) { if (transactionCost > this.Money) { return(GameResult.NotEnoughMoney); } if (quantity > this.RemainingCapacity) { return(GameResult.NotEnoughCapacity); } if (quantity < 0) { return(GameResult.NotEnoughMoney); } OwnedGum ownedGum = new OwnedGum(); ownedGum.Name = gum.Name; ownedGum.Quantity = quantity; if (this.OwnsGum(gum) == false) { if (transactionCost == 0) { ownedGum.TotalPaid = 0; } else { ownedGum.TotalPaid = transactionCost; } this.OwnedGums.Add(ownedGum); } else { foreach (OwnedGum g in this.OwnedGums) { if (g.Name == gum.Name) { int totalCostSoFar = g.Quantity * g.AveragePrice; int totalCostForThisTransaction = transactionCost; double newAverage = (totalCostSoFar + totalCostForThisTransaction) / (double)(g.Quantity + quantity); int averagePrice = (int)Math.Ceiling(newAverage); g.Quantity += quantity; g.TotalPaid += (transactionCost); } } } this.Money -= transactionCost; return(GameResult.Success); }
public MarketState MarketChanged() { bool randomProbability = MyRandom.SomethingHappened(Settings.PROBABILITY_COLLAPSED_MARKET_STATE); int targetGum = MyRandom.Random(0, this.Gums.Count - 1); MarketGum g = this.Gums[targetGum]; if (randomProbability) { double discountFactor = MyRandom.Random(35, 65) / (double)100; g.CurrentPrice = (int)Math.Ceiling(g.CurrentPrice * discountFactor); this.CityMessage = "Prices of " + g.Name + " have tanked!"; ///Other gums are slightly depressed as well foreach (MarketGum mGum in this.Gums) { if (mGum.Name == g.Name) { continue; } double discountFactor2 = MyRandom.Random(80, 90) / (double)100; mGum.CurrentPrice = (int)Math.Ceiling(mGum.CurrentPrice * discountFactor2); } return(MarketState.Collapsed); } randomProbability = MyRandom.SomethingHappened(Settings.PROBABILITY_SPIKED_MARKET_STATE); if (randomProbability) { double spikeFactor = MyRandom.Random(125, 165) / (double)100; g.CurrentPrice = (int)Math.Floor(g.CurrentPrice * spikeFactor); this.CityMessage = "Prices of " + g.Name + " have spiked!"; ///Other gums are slightly more expensive too foreach (MarketGum mGum in this.Gums) { if (mGum.Name == g.Name) { continue; } double spikeFactor2 = MyRandom.Random(110, 120) / (double)100; mGum.CurrentPrice = (int)Math.Ceiling(mGum.CurrentPrice * spikeFactor2); } return(MarketState.Spiked); } return(MarketState.Normal); }
public bool OwnsGum(MarketGum gum) { return(this.HowManyOwned(gum) > 0); }
public GameResult BuyGum(MarketGum gum, int quantity, int totalCost) { return(buyGum(gum, quantity, totalCost)); }
public GameResult BuyGum(MarketGum gum, int quantity) { int price = gum.CurrentPrice * quantity; return(buyGum(gum, quantity, price)); }