Add project files.
This commit is contained in:
252
BlackJ/Game.cs
Normal file
252
BlackJ/Game.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
using BlackJack;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlackJack
|
||||
{
|
||||
public class Game
|
||||
{
|
||||
|
||||
readonly Player player = new Player();
|
||||
readonly Dealer dealer = new Dealer();
|
||||
readonly Shop shop = new Shop();
|
||||
readonly Art art = new Art();
|
||||
void DisplayBalance()
|
||||
{
|
||||
Console.WriteLine("Balance: " + player.cash + "$");
|
||||
Console.WriteLine("_____________________________");
|
||||
Console.WriteLine();
|
||||
}
|
||||
public void Initialize()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.WriteLine("Welcome to BlackJack)");
|
||||
Console.WriteLine("You start with " + player.cash + "$");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("'Enter' to continue");
|
||||
Console.ReadLine();
|
||||
Menu();
|
||||
}
|
||||
|
||||
|
||||
public void Menu()
|
||||
{
|
||||
Console.Clear();
|
||||
DisplayBalance();
|
||||
Console.WriteLine("> Enter round (1)");
|
||||
Console.WriteLine("> Shop (2)");
|
||||
Console.WriteLine("> Inventory (3)");
|
||||
string input = Console.ReadLine();
|
||||
if (input == "1")
|
||||
{
|
||||
NewRound();
|
||||
}
|
||||
else if (input == "2")
|
||||
{
|
||||
|
||||
}
|
||||
else if (input == "3")
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invalid input. Press 'Enter' to try again");
|
||||
Console.ReadLine();
|
||||
Console.Clear();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void NewRound()
|
||||
{
|
||||
Console.Clear();
|
||||
|
||||
if (player.cash <= 0)
|
||||
{
|
||||
Console.WriteLine("You went bankrupt!");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
Deck deck = new Deck();
|
||||
player.RemoveHand();
|
||||
dealer.RemoveHand();
|
||||
|
||||
double bet;
|
||||
deck.Shuffle();
|
||||
|
||||
player.DrawCard(deck);
|
||||
player.DrawCard(deck);
|
||||
|
||||
dealer.DrawCard(deck);
|
||||
|
||||
void Bet()
|
||||
{
|
||||
Console.WriteLine("You have " + player.cash + "$");
|
||||
Console.WriteLine("How much do you want to bet?");
|
||||
string input = Console.ReadLine();
|
||||
|
||||
if (double.TryParse(input, out bet))
|
||||
{
|
||||
if (bet <= player.cash && bet > 0)
|
||||
{
|
||||
player.cash -= bet;
|
||||
}
|
||||
else if (bet == 676767)
|
||||
{
|
||||
double cheat;
|
||||
Console.WriteLine("Enter Cheat");
|
||||
input = Console.ReadLine();
|
||||
if (double.TryParse(input, out cheat))
|
||||
{
|
||||
player.cash += cheat;
|
||||
}
|
||||
Console.Clear();
|
||||
Bet();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invalid amount. Press 'Enter' to try again");
|
||||
Console.ReadLine();
|
||||
Console.Clear();
|
||||
Bet();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invalid amount. Press 'Enter' to try again");
|
||||
Console.ReadLine();
|
||||
Console.Clear();
|
||||
Bet();
|
||||
}
|
||||
}
|
||||
|
||||
Bet();
|
||||
|
||||
|
||||
Console.Clear();
|
||||
|
||||
void DisplayStats()
|
||||
{
|
||||
Console.WriteLine("Balance: " + player.cash + "$");
|
||||
Console.WriteLine("Bet: " + bet + "$");
|
||||
Console.WriteLine("_____________________________");
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
|
||||
void PlayersTurn()
|
||||
{
|
||||
DisplayStats();
|
||||
|
||||
Console.WriteLine("Hand: " + player.GetHandValue());
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Dealer's first card: " + dealer.GetHandValue());
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Hit (h) or Stand (s)?");
|
||||
|
||||
string input = Console.ReadLine();
|
||||
Console.Clear();
|
||||
DisplayStats();
|
||||
|
||||
if (input == "h")
|
||||
{
|
||||
Card card = player.DrawCard(deck);
|
||||
Console.WriteLine("You received " + card.Number + " " + card.Suit);
|
||||
if (player.GetHandValue() > 21)
|
||||
{
|
||||
Bust();
|
||||
}
|
||||
Console.WriteLine("Press 'Enter' to continue.");
|
||||
Console.ReadLine();
|
||||
Console.Clear();
|
||||
PlayersTurn();
|
||||
|
||||
}
|
||||
else if (input == "s")
|
||||
{
|
||||
Console.WriteLine("You chose to stand.");
|
||||
DealersTurn();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Invalid input. Press 'Enter' to try again");
|
||||
Console.ReadLine();
|
||||
Console.Clear();
|
||||
PlayersTurn();
|
||||
}
|
||||
}
|
||||
|
||||
PlayersTurn();
|
||||
|
||||
void InputNewRound()
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Press 'Enter' to enter menu.");
|
||||
Console.ReadLine();
|
||||
Menu();
|
||||
}
|
||||
|
||||
void DealersTurn()
|
||||
{
|
||||
while (dealer.GetHandValue() < 17)
|
||||
{
|
||||
dealer.DrawCard(deck);
|
||||
}
|
||||
|
||||
|
||||
int playerHand = player.GetHandValue();
|
||||
int dealerHand = dealer.GetHandValue();
|
||||
|
||||
|
||||
|
||||
if (playerHand > dealerHand || dealerHand > 21)
|
||||
{
|
||||
Console.WriteLine("You won.");
|
||||
Console.WriteLine("Your hand: " + playerHand);
|
||||
Console.WriteLine("Dealer's hand: " + dealerHand);
|
||||
|
||||
Console.WriteLine("+" + bet * 2 + "$");
|
||||
player.cash += bet * 2;
|
||||
|
||||
InputNewRound();
|
||||
}
|
||||
else if (playerHand < dealerHand)
|
||||
{
|
||||
Console.WriteLine("You lost.");
|
||||
Console.WriteLine("Your hand: " + playerHand);
|
||||
Console.WriteLine("Dealer's hand: " + dealerHand);
|
||||
|
||||
InputNewRound();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("It's a tie!");
|
||||
Console.WriteLine("Your hand: " + playerHand);
|
||||
Console.WriteLine("Dealer's hand: " + dealerHand);
|
||||
|
||||
Console.WriteLine("+" + bet + "$");
|
||||
player.cash += bet;
|
||||
|
||||
InputNewRound();
|
||||
}
|
||||
}
|
||||
|
||||
void Bust()
|
||||
{
|
||||
Console.WriteLine("You bust! Hand: " + player.GetHandValue());
|
||||
InputNewRound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user