public BettingPlatformEmulator()
 {
     Account        = new Account("USD");
     Players        = new List <Player>();
     BetService     = new BetService();
     PaymentService = new PaymentService();
 }
        public void Bet()
        {
            decimal amount;
            string  currency;

            SetAmountAndCurrency(out amount, out currency);
            try
            {
                ActivePlayer.Withdraw(amount, currency);
                var price = BetService.Bet(amount);
                if (price == 0)
                {
                    Console.WriteLine("You lose.");
                }
                else
                {
                    Console.WriteLine($"You won {price} {currency}");
                    ActivePlayer.Deposit(price, currency);
                }
            }
            catch (InvalidOperationException)
            {
                throw new InvalidOperationException("There is insufficient funds on your account.");
            }
            catch (NotSupportedException)
            {
                throw new NotSupportedException("Invalid currency");
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            BetService betService = new Library.BetService();
            float      odd        = 0;

            for (int i = 0; i < 10; i++)
            {
                odd = betService.GetOdds();
            }
            Console.WriteLine($"I bet 100 USD with odd {odd} and earned {betService.Bet(100)}");
            BetWhileWinLose();
        }
 public void GetOdds() => Console.WriteLine($"Odd is {BetService.GetOdds()}");
        public void Start()
        {
            bool isGoing = true;

            while (isGoing)
            {
                if (ActivePlayer == null)
                {
                    Console.Clear();
                    Console.WriteLine("1. Register\n2. Login\n3. Stop");
                    var key = Console.ReadKey().Key;
                    switch (key)
                    {
                    case ConsoleKey.NumPad1:
                    case ConsoleKey.D1:
                        Register();
                        break;

                    case ConsoleKey.NumPad2:
                    case ConsoleKey.D2:
                        Console.Clear();
                        Player player1;
                        ActivePlayer = Login();
                        break;

                    case ConsoleKey.NumPad3:
                    case ConsoleKey.D3:
                        Stop(ref isGoing);
                        break;
                    }
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("1. Deposit\n2. Withdraw\n3. GetOdd\n4. Bet\n5. Logout");
                    var key = Console.ReadKey().Key;
                    switch (key)
                    {
                    case ConsoleKey.NumPad1:
                    case ConsoleKey.D1:

                        Console.Clear();
                        Deposit();
                        break;

                    case ConsoleKey.NumPad2:
                    case ConsoleKey.D2:
                        Withdraw();
                        break;

                    case ConsoleKey.NumPad3:
                    case ConsoleKey.D3:
                        Console.Clear();
                        var odd = BetService.GetOdds();
                        Console.WriteLine($"Odd is {odd}. Press any key to continue...");
                        Console.ReadKey();
                        break;

                    case ConsoleKey.NumPad4:
                    case ConsoleKey.D4:
                        decimal bet = 0;
                        string  console;
                        Console.Clear();
                        Console.WriteLine("If you don't want to place enter 'cancel' on bet field");
                        Console.WriteLine($"Avaliable on your account {ActivePlayer.Account.Amount} {ActivePlayer.Account.Currency}");
                        do
                        {
                            Console.Write("Enter your bet->");
                            console = Console.ReadLine();
                            if (console == "cancel")
                            {
                                goto default;
                            }
                        }while (!decimal.TryParse(console, out bet));
                        bet = Math.Round(bet, 2);
                        if (bet > ActivePlayer.Account.Amount)
                        {
                            Console.WriteLine("Not enough money on your account. Press any key to continue...");
                            Console.ReadKey();
                            goto case ConsoleKey.NumPad4;
                        }
                        if (bet <= 0)
                        {
                            Console.WriteLine("Invalid bet. Press any key to continue...");
                            Console.ReadKey();
                            goto case ConsoleKey.NumPad4;
                        }

                        ActivePlayer.Account.Amount -= bet;
                        var win = BetService.Bet(bet);
                        ActivePlayer.Account.Amount += win;
                        Console.WriteLine($"You won {win}{ActivePlayer.Account.Currency}");
                        Console.ReadLine();
                        goto case ConsoleKey.NumPad4;

                    case ConsoleKey.NumPad5:
                    case ConsoleKey.D5:
                        Logout();
                        break;

                    default:
                        break;
                    }
                }
            }
        }