static string DealCard(BJPlayer P, BJDeck D, Random r) { string card = D.DrawCard(r); P.TakeCard(card); P.AddScore(CardValue(card)); return(card); }
public void CreateThreePlayers() { CreateTwoPlayers(); _player3 = new BJPlayer(3, this); PlayersMassiv.Add(_player3); PlayersNumber = 3; _player3.TakeTwoStartCards(); NextTurnEvent += _player3.TurnReaction; }
public void CreateFourPlayers() { CreateThreePlayers(); _player4 = new BJPlayer(4, this); PlayersMassiv.Add(_player4); _player4.TakeTwoStartCards(); PlayersNumber = 4; NextTurnEvent += _player4.TurnReaction; }
public void CreateTwoPlayers() { MainPlayer = new BJPlayer(1, this); _player2 = new BJPlayer(2, this); PlayersMassiv.Add(MainPlayer); PlayersMassiv.Add(_player2); PlayersNumber = 2; MainPlayer.TakeTwoStartCards(); _player2.TakeTwoStartCards(); NextTurnEvent += _player2.TurnReaction; }
static void Main(string[] args) { BJDeck Deck = new BJDeck(); Deck.CreateCards(); BJPlayer Player = new BJPlayer(); BJPlayer House = new BJPlayer(); Random rnd = new Random(); Console.WriteLine("Welcome to the game of Blackjack!"); Console.WriteLine(); DealCard(Player, Deck, rnd); DealCard(Player, Deck, rnd); DealCard(House, Deck, rnd); DealCard(House, Deck, rnd); Console.Write("You have been dealt: "); Player.ShowHand(); Console.WriteLine(); Console.WriteLine($"House has been dealt: {House.ShowCard(1)}, [?]"); Console.WriteLine(); while (true) { Console.WriteLine("What do you want to do?"); Console.WriteLine("Choose: 1 - To take another card"); Console.WriteLine("Choose: 2 - To finish"); Console.WriteLine(); string input = Console.ReadLine(); if (input != "1" && input != "2") { Console.WriteLine("Wrong input. Please choose 1 or 2."); continue; } Console.WriteLine($"I choose: {input}"); Console.WriteLine(); if (input == "1") { Console.WriteLine($"You have been dealt: {DealCard(Player, Deck,rnd)}"); DealCard(House, Deck, rnd); Console.WriteLine("House has been dealt: [?]"); Console.WriteLine(); } else if (input == "2") { break; } } Console.Write("Your cards: "); Player.ShowHand(); Console.WriteLine(); Console.Write("House cards: "); House.ShowHand(); Console.WriteLine(); Console.WriteLine($"You have {Player.ShowScore()} points vs. house {House.ShowScore()} points"); if ((Player.ShowScore() > 21 && House.ShowScore() > 21) || Player.ShowScore() == House.ShowScore()) { Console.WriteLine("Draw!"); } else if (Player.ShowScore() > 21 && House.ShowScore() <= 21) { Console.WriteLine("House wins!"); } else if (Player.ShowScore() <= 21 && House.ShowScore() > 21) { Console.WriteLine("You win!"); } else if (Player.ShowScore() <= 21 && House.ShowScore() <= 21) { if (Player.ShowScore() > House.ShowScore()) { Console.WriteLine("You win!"); } else { Console.WriteLine("House wins!"); } } Console.WriteLine(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); }