public void Play(Casino casino) { var bets = new[] { 1, 5, 10, 25, 50, 100 }; var random = new Random(); var numbers = new int[3, 3]; string betString; int bet; do { Console.Clear(); Console.WriteLine("********** Jednoręki bandyta **********\n"); Console.WriteLine("Stan konta: {0:c}\n", casino.Money); for (int i = 0; i < bets.Length; i++) { Console.WriteLine("{0}) {1:c}", i + 1, bets[i]); } Console.WriteLine("9) Powrót\n"); Console.Write("Wybierz opcję: "); betString = Console.ReadLine(); if (int.TryParse(betString, out bet)) { if (bet != 9) { try { casino.TakeMoney(bets[bet - 1]); Console.WriteLine("\nTwoje liczby\n"); for (int i = 0; i < numbers.GetLength(0); i++) { for (int j = 0; j < numbers.GetLength(1); j++) { numbers[i, j] = random.Next(10); Console.Write($"{numbers[i,j]} "); } Console.WriteLine(); } var result = CheckNumbers(numbers); if (result) { Console.WriteLine("\nWygrałeś!\n"); casino.AddMoney(bets[bet - 1] * 2); } else { Console.WriteLine("\nPrzegrałeś!\n"); } } catch (IndexOutOfRangeException) { Console.WriteLine("Nie rozumiem polecenia!"); } catch (Exception e) { Console.WriteLine(e.Message); } } } else { Console.WriteLine("Nie rozumiem polecenia!"); } Console.WriteLine("Naciśnij enter aby kontynuować..."); Console.ReadLine(); } while (bet != 9); }
public void Play(Casino casino) { var deck = CreateDeck().Result; // To show card colors in console Console.OutputEncoding = Encoding.UTF8; var bets = new[] { 1, 5, 10, 25, 50, 100 }; string betString, playerOptionString; int bet, deckPosition, playerOption; List <Card> playerCards, casinoCards; bool playerContinue; do { Console.Clear(); Console.WriteLine("********** Blackjack **********\n"); Console.WriteLine("Stan konta: {0:c}\n", casino.Money); for (int i = 0; i < bets.Length; i++) { Console.WriteLine("{0}) {1:c}", i + 1, bets[i]); } Console.WriteLine("9) Powrót\n"); Console.Write("Wybierz opcję: "); betString = Console.ReadLine(); if (int.TryParse(betString, out bet)) { if (bet != 9) { try { casino.TakeMoney(bets[bet - 1]); deck.Shuffle(); deckPosition = 0; playerCards = new List <Card>(); casinoCards = new List <Card>(); playerCards.Add(deck[deckPosition++]); casinoCards.Add(deck[deckPosition++]); playerCards.Add(deck[deckPosition++]); if (playerCards.Sum(x => x.Value) == 21) { Console.WriteLine("\nBlackjack!"); Console.Write("Twoje karty: "); PrintCards(playerCards); casino.AddMoney(3 * bets[bet - 1]); break; } else { casinoCards.Add(deck[deckPosition++]); if (casinoCards.Sum(x => x.Value) > 10) { var higherCard = casinoCards.OrderBy(x => x.Value).First(); Console.WriteLine($"\nKarta krupiera: {higherCard.Color}{higherCard.Symbol}"); } else { var lowerCard = casinoCards.OrderByDescending(x => x.Value).First(); Console.WriteLine($"\nKarta krupiera: {lowerCard.Color}{lowerCard.Symbol}\n"); } Console.Write("Twoje karty: "); PrintCards(playerCards); Console.WriteLine($"\nWartość: {playerCards.Sum(x => x.Value)}"); playerContinue = true; do { Console.WriteLine("\nWybierz opcję:\n1) Dobierz\n2) Pas"); Console.Write("Twoja decyzja: "); playerOptionString = Console.ReadLine(); if (int.TryParse(playerOptionString, out playerOption)) { if (playerOption == 1) { playerCards.Add(deck[deckPosition++]); Console.Write("Twoje karty: "); PrintCards(playerCards); Console.WriteLine($"\nWartość: {playerCards.Sum(x => x.Value)}"); if (playerCards.Sum(x => x.Value) > 21) { Console.WriteLine("\nPrzegrałeś! Za dużo!"); playerContinue = false; } } else if (playerOption == 2) { Console.Write("\nTwoje karty: "); PrintCards(playerCards); Console.WriteLine($"\nWartość: {playerCards.Sum(x => x.Value)}"); playerContinue = false; } else { Console.WriteLine("\nNie rozumiem polecenia!"); } } } while (playerContinue); if (playerCards.Sum(x => x.Value) > 21) { } else { while (casinoCards.Sum(x => x.Value) < 16) { casinoCards.Add(deck[deckPosition++]); Console.Write("Karty krupiera: "); PrintCards(casinoCards); Console.WriteLine($"\nWartość kart krupiera: {casinoCards.Sum(x => x.Value)}"); } if (casinoCards.Sum(x => x.Value) > 21) { Console.WriteLine($"\nWygrałeś!\nWartość Twoich kart: {playerCards.Sum(x => x.Value)}\nWartość kart krupiera: {casinoCards.Sum(x => x.Value)}\n"); casino.AddMoney(2 * bets[bet - 1]); } else if (casinoCards.Sum(x => x.Value) > playerCards.Sum(x => x.Value)) { Console.WriteLine($"\nPrzegrałeś!\nWartość Twoich kart: {playerCards.Sum(x => x.Value)}\nWartość kart krupiera: {casinoCards.Sum(x => x.Value)}\n"); } else if (casinoCards.Sum(x => x.Value) < playerCards.Sum(x => x.Value)) { Console.WriteLine($"\nWygrałeś!\nWartość Twoich kart: {playerCards.Sum(x => x.Value)}\nWartość kart krupiera: {casinoCards.Sum(x => x.Value)}\n"); casino.AddMoney(2 * bets[bet - 1]); } else { Console.WriteLine($"\nRemis!\nWartość Twoich kart: {playerCards.Sum(x => x.Value)}\nWartość kart krupiera: {casinoCards.Sum(x => x.Value)}\n"); casino.AddMoney(bets[bet - 1]); } } } } catch (IndexOutOfRangeException) { Console.WriteLine("Nie rozumiem polecenia!"); } catch (Exception e) { Console.WriteLine(e.Message); } } } Console.WriteLine("Naciśnij enter aby kontynuować..."); Console.ReadLine(); } while (bet != 9); }