コード例 #1
0
ファイル: Shop.cs プロジェクト: miguelmartin75/Trader
        private Money GenerateNewPriceForItem(Item item)
        {
            Money money = new Money();

            double randomPercentage = 0.0;
            randomPercentage = ((random.Next(MaxProfitPercentage) + MinProfitPercentage) / 100.0);

            money.Amount = item.Value + (item.Value * randomPercentage);

            return money;
        }
コード例 #2
0
ファイル: TraderGame.cs プロジェクト: miguelmartin75/Trader
        private void lotteryEvent()
        {
            if (OnPlayerEntersTheLotteryEvent != null)
            {
                OnPlayerEntersTheLotteryEvent(this, "You entered the lottery!");
            }

            // detemines if the player won money
            int percentageToWin = random.Next(100) + 1;

            if (OnPlayerLosesOrGainsMoney != null)
            {
                /*
                   50% chance to double your money.
                   25% chance nothing happens.
                   25% chance to lose half your credits.
                 */

                Money moneyLostOrGained = null;

                LottoOptions options = LottoOptions.NothingHappens;

                // 50%
                if (percentageToWin < 50)
                {
                    options = LottoOptions.WinCredits;
                    moneyLostOrGained = new Money(player.Money.Amount / 2.0);
                    player.Money.Amount += moneyLostOrGained.Amount;
                }
                // 25%
                else if (percentageToWin < 75)
                {
                    options = LottoOptions.LoseCredits;
                    moneyLostOrGained = new Money(player.Money.Amount / 2.0);
                    player.Money.Amount -= moneyLostOrGained.Amount;
                }
                // 25%
                else
                {
                    options = LottoOptions.NothingHappens;
                }

                this.OnPlayerLosesOrGainsMoney
                    (
                    this,
                    options != LottoOptions.WinCredits,
                    moneyLostOrGained,
                    options == LottoOptions.WinCredits ? "You won the lottery!" : "You lost the lottery!"
                    );
            }
        }
コード例 #3
0
ファイル: TraderGame.cs プロジェクト: miguelmartin75/Trader
        private void enemyEvent()
        {
            if (OnPlayerIsInteruptedByEnemyEvent == null || enemies.Count <= 0)
            {
                return;
            }

            Enemy enemy = enemies[random.Next(enemies.Count)];
            bool userWishesToFight = OnPlayerIsInteruptedByEnemyEvent(this, enemy) == EnemyInvolvement.Fight;

            /*
                You can stay at fight and have a 50% chance to win
                   : if you win you gain a randomized loot reward
                   : if you lose you lose all but 10 credits.
                You can run with 75% chance to lose half your credits.
             */

            if (userWishesToFight)
            {
                bool playerWonFight = (random.Next(2) == 1);
                if (playerWonFight)
                {
                    Money randomMoneyAmount = generateRandomMoneyAmount();
                    player.Money.Amount += randomMoneyAmount.Amount;

                    if(this.OnPlayerLosesOrGainsMoney != null)
                        this.OnPlayerLosesOrGainsMoney(this, false, randomMoneyAmount, "You won against the enemy: " + enemy.Name);
                }
                else
                {
                    Money moneyLost = new Money(player.Money.Amount - 10);

                    player.Money.Amount -= Math.Abs(moneyLost.Amount);
                    player.Health.Current-= enemy.DamageAmount;

                    if(this.OnPlayerLosesOrGainsMoney != null)
                        this.OnPlayerLosesOrGainsMoney(this, true, moneyLost, "You lost against the enemy: " + enemy.Name);
                }
            }
            else
            {
                int randomPercentage = random.Next(100) + 1;
                if (randomPercentage <= 75)
                {
                    Money decreasedMoneyAmount = new Money(player.Money.Amount / 2.0);
                    this.player.Money.Amount -= decreasedMoneyAmount.Amount;

                    this.OnPlayerLosesOrGainsMoney(this, true, decreasedMoneyAmount, "You attempted to run away, but failed!");
                }
            }
        }
コード例 #4
0
ファイル: TraderGame.cs プロジェクト: miguelmartin75/Trader
        public Money PriceOf(Item[] items, Shop shop)
        {
            Money money = new Money();
            for(int i = 0; i < items.Length; ++i)
            {
                money.Amount += shop.PriceOf(items[i]).Amount;
            }

            return money;
        }
コード例 #5
0
ファイル: Player.cs プロジェクト: miguelmartin75/Trader
 public Player(string name, Location location, Money money)
     : this(name)
 {
     Location = location;
     this.money = money;
 }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: miguelmartin75/Trader
 private void onPlayerWinsOrLosesMoney(object sender, bool decreaseMoney, Money money, string reason)
 {
     if (money != null && money.Amount > 0)
     {
         MessageBox.Show("You " + (decreaseMoney ? "lost " : "won ") + money.ToString() + ", because: " + reason, "Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     else
     {
         MessageBox.Show("Luckily, you did not lose or gain any money, because: "  + reason, "Notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
 }