public void BlackJackGame(CardPlayer player, CardPlayer croupier) { CreateDeck(); ShuffleDeck(); player.Cards = new List <Card>(); croupier.Cards = new List <Card>(); Console.WriteLine($"You have {player.Money} gold."); var bet = GetPlayerBet(player); DealCards(player, 2); DealCards(croupier, 2); PlayerFirstCardsOpenReport(croupier); PlayerCardsReport(player); if (CardsValueSum(player.Cards) == 21) { Console.WriteLine("You have 21."); } else { BlackJackPlayerTurn(player); if (CardsValueSum(player.Cards) <= 21) { BlackJackCroupierTurn(croupier, CardsValueSum(player.Cards)); } } BlackJackGameResult(player, croupier, bet); Console.Write("Press any key to coninue..."); Console.ReadKey(); }
private void BlackJackGameResult(CardPlayer player, CardPlayer croupier, int bet) { if (CardsValueSum(player.Cards) > 21) { Console.WriteLine($"Sum of your cards more than 21 ({CardsValueSum(player.Cards)}).\n\nYOU LOSE!"); player.Money -= bet; croupier.Money += bet; } else if (CardsValueSum(croupier.Cards) > 21) { Console.WriteLine($"Sum of {croupier.Name} cards more than 21 ({CardsValueSum(croupier.Cards)}).\n\nYOU WIN!"); player.Money += bet; croupier.Money -= bet; } else if (CardsValueSum(player.Cards) > CardsValueSum(croupier.Cards)) { Console.WriteLine($"Sum of your cards ({CardsValueSum(player.Cards)}) more than sum of {croupier.Name} cards ({CardsValueSum(croupier.Cards)})\n\nYOU WON!"); player.Money += bet; croupier.Money -= bet; } else if (CardsValueSum(player.Cards) < CardsValueSum(croupier.Cards)) { Console.WriteLine($"Sum of your cards ({CardsValueSum(player.Cards)}) less than sum of {croupier.Name} cards ({CardsValueSum(croupier.Cards)})\n\nYOU LOSE!"); player.Money -= bet; croupier.Money += bet; } else if (CardsValueSum(player.Cards) == CardsValueSum(croupier.Cards)) { Console.WriteLine($"Sum of your cards ({CardsValueSum(player.Cards)}) equal to sum of {croupier.Name} cards ({CardsValueSum(croupier.Cards)})\n\nDRAW!"); } }
private int GetPlayerBet(CardPlayer player) { var betNumber = 0; if (player.Money >= 25) { Console.WriteLine("Your bet?\n1 - 5\n2 - 10\n3 - 25"); betNumber = ConditionParse(3); } else if (player.Money >= 10) { Console.WriteLine("Your bet?\n1 - 5\n2 - 10"); betNumber = ConditionParse(2); } else if (player.Money >= 5) { Console.WriteLine("Your bet?\n1 - 5"); betNumber = ConditionParse(1); } switch (betNumber) { case 1: return(5); case 2: return(10); case 3: return(25); } return(0); }
public CardPlayer CreatePlayer() { Console.Write("What is your name, adventurer?\nType here: "); var name = Console.ReadLine(); var fists = new Weapon() { Name = "Fists", Weight = 0, Cost = 0, MinDamage = 1, MaxDamage = 2 }; var player = new CardPlayer() { Name = name, HP = 20, MP = 0, STR = 1, INT = 1, LVL = 1, EXP = 0, Money = 0, Weapon = fists, Inventory = new List <Item>() }; return(player); }
public void BlackJackGames(CardPlayer player) { var croupier = new CardPlayer("Croupier"); var isContinue = true; while (isContinue && player.Money >= 5 && croupier.Money > 0) { Console.Clear(); BlackJackGame(player, croupier); Console.Clear(); Console.WriteLine("Do you want to start new blackjack game?\n1 - Yes\n2 - No"); if (ConditionParse(2) == 2) { isContinue = false; } } if (player.Money < 5) { Console.WriteLine("\nYou haven't enough money. CARD GAME IS OVER."); } if (croupier.Money <= 0) { Console.WriteLine($"\nYou won all {croupier.Name} money. CARD GAME IS OVER."); } Console.WriteLine("\nPress any key to exit"); Console.ReadKey(); }
public void SaveFarmGame(CardPlayer player) { var saved = false; while (saved != true) { Console.Write("Enter a name of save file: "); string saveName = Console.ReadLine() + ".sav"; if (File.Exists(saveName) == true) { Console.WriteLine("A file with this name already exists. Do you Want to overwrite it??\n1 - Yes\n2 - No"); if (ConditionParse(2) == 1) { using (StreamWriter writer = new StreamWriter(saveName)) { writer.Write(JsonConvert.SerializeObject(player)); } saved = true; } } else { using (StreamWriter writer = new StreamWriter(saveName)) { writer.Write(JsonConvert.SerializeObject(player)); } saved = true; } } }
private void BlackJackCroupierTurn(CardPlayer player, int firstPlayerCardsSum) { PlayerCardsReport(player); while (CardsValueSum(player.Cards) < firstPlayerCardsSum && CardsValueSum(player.Cards) < 21) { Thread.Sleep(1000); DealCards(player); PlayerCardsReport(player); } }
private void DealCards(CardPlayer player, int numberOfCards = 1) { if (Deck.Count < numberOfCards) { Console.WriteLine("Not enough cards in deck"); } else { player.Cards.AddRange(Deck.GetRange(0, numberOfCards)); Deck.RemoveRange(0, numberOfCards); } }
public void PlayerFirstCardsOpenReport(CardPlayer player) { Console.WriteLine($"{player.Name}'s cards:"); var count = player.Cards.Count; if (count > 0) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; for (int index = 0; index < count; index++) { Console.Write("┌─────────┐"); } Console.WriteLine(); Console.Write("│"); player.Cards[0].CardPropToConsole(); Console.Write(" │"); for (int index = 1; index < count; index++) { Console.Write("│▒▒▒▒▒▒▒▒▒│"); } Console.WriteLine(); for (int i = 0; i < 7; i++) { Console.Write("│ │"); for (int index = 1; index < count; index++) { Console.Write("│▒▒▒▒▒▒▒▒▒│"); } Console.WriteLine(); } Console.Write("│ "); player.Cards[0].CardPropToConsole(); Console.Write("│"); for (int index = 1; index < count; index++) { Console.Write("│▒▒▒▒▒▒▒▒▒│"); } Console.WriteLine(); for (int index = 0; index < count; index++) { Console.Write("└─────────┘"); } Console.WriteLine(); Console.ResetColor(); } }
public void Start() { //First Star //CreateDeck(); //ShuffleDeck(); //DeckReport(5); //CardsValueReport(Values.Jack); //CardsSuitReport(Suits.Clubs); //Second Star //EmptyCardReport(); //DeckInRowReport(6); var player = new CardPlayer("Player"); BlackJackGames(player); }
private void BlackJackPlayerTurn(CardPlayer player) { while (CardsValueSum(player.Cards) <= 21) { Console.WriteLine($"Sum of your cards is {CardsValueSum(player.Cards)}."); Console.WriteLine("1 - One more card\n2 - Enough"); if (ConditionParse(2) == 1) { DealCards(player); PlayerCardsReport(player); } else { break; } } }
public void LoadGame(string[] savFiles) { Console.WriteLine("\nSave files:"); for (int i = 0; i < savFiles.Length; i++) { Console.WriteLine($"{i + 1}. {savFiles[i]}"); } Console.Write("Select number of the save file to load:"); var player = new CardPlayer(); using (var readFile = new StreamReader(savFiles[ConditionParse(savFiles.Length) - 1])) { player = JsonConvert.DeserializeObject <CardPlayer>(readFile.ReadLine()); } Console.WriteLine("Game has loaded.\n\nPress any key to continue"); Console.ReadKey(); MainMenu(player); }
public void PlayerCardsReport(CardPlayer player) { Console.WriteLine($"{player.Name}'s cards:"); CardsInRowReport(player.Cards); }