Esempio n. 1
0
        public IBet TakeBet(IRaceLineup race)
        {
            ISnail pickToWin = chooseSnail(race);
            int betAmount = getBetAmount(pickToWin, race.Player.Money);

            return createBet(pickToWin, betAmount);
        }
Esempio n. 2
0
        public void PlaceBet(IRaceLineup race, IBet bet)
        {
            if (bet.WagerAmount <= 0 || bet.WagerAmount > race.Player.Money)
            {
                throw new ArgumentOutOfRangeException("Wager must be a positive value less than the player's current money.");
            }
            if (!race.Snails.Contains(bet.PickToWin))
            {
                throw new ArgumentException("Must bet on a snail that is participating in the race.");
            }

            race.Player.Money -= bet.WagerAmount;
            this.Bet = bet;
        }
Esempio n. 3
0
        private ISnail chooseSnail(IRaceLineup race)
        {
            int selection = 0;

            this.printSnailChoices(race, null);
            Console.CursorVisible = true;
            int.TryParse(Console.ReadLine(), out selection);

            while (selection <= 0 || selection > race.Snails.Count())
            {
                this.printSnailChoices(race, string.Format("You must enter a number from 1 to {0}.\n", race.Snails.Count()));
                int.TryParse(Console.ReadLine(), out selection);
            }
            Console.CursorVisible = false;

            return race.Snails.ElementAt(selection - 1);
        }
Esempio n. 4
0
 private void printSnailChoices(IRaceLineup race, string additionalText)
 {
     using (IOutputMethod view = createView())
     {
         view.Write("\n\n");
         view.Write(this.leftMargin + "Please choose one of the following snails:\n\n");
         view.Write(this.leftMargin + "Name:               Number:\n\n");
         int snailNumber = 1;
         foreach (var snail in race.Snails)
         {
             view.Write(this.leftMargin + "{0, -20}{1}\n", snail.Name, snailNumber);
             snailNumber++;
         }
         view.Write("\n");
         if (additionalText != null)
         {
             view.Write(this.leftMargin + additionalText + "\n");
         }
         view.Write(this.leftMargin + "Which snail would you like to bet on? ");
     }
 }