Beispiel #1
0
        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);
        }
Beispiel #2
0
        private void interveneLoanShark()
        {
            if (_player.Loan == 0)
            {
                return;
            }
            int loanAge = _player.LoanOriginDay - this.DaysLeft;

            if (loanAge == 4)
            {
                if (_player.Money > 0)
                {
                    double half     = _player.Money / 2.0;
                    int    intMoney = (int)half;
                    _player.Money       -= intMoney;
                    this.CurrentMessage += "The loan shark was tired of waiting.  He took $" + intMoney;
                }
            }
            if (loanAge == 7)
            {
                if (_player.OwnedGums.Count > 0 && _player.OwnedGums[0].Quantity > 0)
                {
                    OwnedGum gum = _player.OwnedGums[0];
                    _player.OwnedGums[0].Quantity = 1;
                    this.CurrentMessage          += "The loan shark was tired of waiting.  He took most of your " + gum.Name;
                }
            }
            if (loanAge == 10)
            {
                _player.Money        = 0;
                this.CurrentMessage += "The loan shark took all of your money.  You should have payed him!";
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public MarketGum FindGum(OwnedGum gum)
        {
            if (gum == null)
            {
                return(null);
            }

            foreach (MarketGum g in this.Gums)
            {
                if (g.Name == gum.Name)
                {
                    return(g);
                }
            }
            return(null);
        }
Beispiel #5
0
        public RandomFortunes RandomFortuneHappened()
        {
            bool gainedGum = MyRandom.SomethingHappened(Settings.RANDOM_FORTUNE_GAIN_GUM_PROBABILITY);

            if (gainedGum)
            {
                if (this.Player.RemainingCapacity < 100)
                {
                    return(RandomFortunes.None);
                }
                int randomGum      = MyRandom.Random(0, this.CurrentCity.Gums.Count - 1);
                int randomCapacity = MyRandom.Random(50, this.Player.RemainingCapacity - 10);
                this.Player.BuyGum(this.CurrentCity.Gums[randomGum], randomCapacity, 0);
                this.CurrentMessage += "You found " + randomCapacity + " boxes of " + this.CurrentCity.Gums[randomGum].Name + "!";
                return(RandomFortunes.GainGum);
            }

            bool gainedCapacity = MyRandom.SomethingHappened(Settings.RANDOM_FORTUNE_GAIN_CAPACITY_PROBABILITY);

            if (gainedCapacity && this.Player.CarryingCapacity < Settings.MAX_CAPACITY)
            {
                int newCapacity = MyRandom.Random(this.Player.CarryingCapacity + 250, this.Player.CarryingCapacity + 1000);
                this.CurrentMessage         += "You now have " + newCapacity + " carrying capacity!";
                this.Player.CarryingCapacity = newCapacity;
                return(RandomFortunes.GainCapacity);
            }

            bool gainedMoney = MyRandom.SomethingHappened(Settings.RANDOM_FORTUNE_GAIN_MONEY_PROBABILITY);

            if (gainedMoney)
            {
                int money = MyRandom.Random(1000, this.Player.Money + 500);
                this.CurrentMessage += "You found $" + money + "!";
                this.Player.Money   += money;
                return(RandomFortunes.GainMoney);
            }

            bool lostMoney = MyRandom.SomethingHappened(Settings.RANDOM_FORTUNE_LOSE_MONEY_PROBABILITY);

            if (lostMoney)
            {
                if (this.Player.Money <= 100)
                {
                    return(RandomFortunes.None);
                }
                double maxMoney = this.Player.Money * .75;

                int money = MyRandom.Random(100, (int)maxMoney);
                this.CurrentMessage += "You lost $" + money + " in a Ponzi scheme.";
                this.Player.Money   -= money;
                return(RandomFortunes.LostMoney);
            }

            bool lostGum = MyRandom.SomethingHappened(Settings.RANDOM_FORTUNE_LOSE_GUM_PROBABILITY);

            if (lostGum)
            {
                if (this.Player.OwnedGums.Count == 0)
                {
                    return(RandomFortunes.None);
                }

                OwnedGum gum = this.Player.OwnedGums[0];

                if (gum.Quantity < 5)
                {
                    return(RandomFortunes.None);
                }

                double maxGumLost = gum.Quantity / 2.0;
                int    amountLost = MyRandom.Random(1, (int)maxGumLost);
                gum.Quantity        -= amountLost;
                this.CurrentMessage += "Someone has stolen " + amountLost + " boxes of " + gum.Name;
                return(RandomFortunes.LostGum);
            }



            return(RandomFortunes.None);
        }