I'm a beginner programmer looking for a review of my simple war card game program I made. Each player gets a deck and you pull 1 card at a time and compare the 2. Highest value wins. Do that until the deck is gone and whoever has the most points wins. Any advice is appreciated! Thank you for your time looking at this!
enum Suit
{
Hearts,
Diamonds,
Spades,
Clovers
}
enum Face
{
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
Ace
}
// MAKING WAR CARD GAME
class Program
{
public static bool isPlaying = true;
public static Player human = new Player();
public static Player cpu = new Player();
public static int round = 1;
static void Main(string[] args)
{
GameFlow.Start(human, cpu);
while (isPlaying)
{
for (int i = 0; i < 52; i++)
{
GameFlow.Gameplay(human, cpu, round);
round++;
}
round = 1;
GameFlow.Ending(human, cpu);
}
}
}
class Player
{
public string name = "CPU";
public Card currentCard = new Card(); // the current card in play
public int wins = 0 , drawCount = 0;
public Deck myDeck = new Deck();
public void DrawOne()
{
currentCard = myDeck.CurrentlyInDeck[drawCount];
drawCount++;
if (drawCount == 52)
{
drawCount = 0;
}
}
public void SetName()
{
while (name == "CPU" || name == "")
{
Console.WriteLine("What is your name human?");
name = Console.ReadLine();
if(name == "CPU" || name == "")
{
Console.WriteLine("Invalid name!! Try a real name you assclown!");
Console.ReadLine();
}
Console.Clear();
}
}
class Card
{
public Suit suit;
public Face face;
public void PrintCard()
{
Console.Write("{0} of {1}", face, suit);
}
}
class Deck
{
public List<Card> CurrentlyInDeck;
public void GenerateDeck() // Must use this to populate deck
{
CurrentlyInDeck = new List<Card>(52);
int place = 0; // tracks which card number
for (int i = 0; i < 4; i++)
{
for (int f = 0; f < 13; f++)
{
Card card = new Card();
CurrentlyInDeck.Add(card);
CurrentlyInDeck[place].suit = (Suit)i;
CurrentlyInDeck[place].face = (Face)f;
place++;
}
}
}
private static readonly Random rand = new Random();
public void Shuffle()
{
Card holder = new Card();
int random;
for (int i = 0; i < 52; i++)
{
random = rand.Next(0, 51);
holder = CurrentlyInDeck[i];
CurrentlyInDeck[i] = CurrentlyInDeck[random];
CurrentlyInDeck[random] = holder;
}
}
public void PrintDeck() // prints all cards in the deck , used for testing
{
foreach (var card in CurrentlyInDeck)
{
card.PrintCard();
}
}
}
static class Create
{
public static void Name(Player a)
{
a.SetName();
}
public static void TheirDecks(Player hum , Player cpu)
{
hum.myDeck.GenerateDeck();
cpu.myDeck.GenerateDeck();
hum.myDeck.Shuffle();
cpu.myDeck.Shuffle();
}
}
static class GameFlow
{
static public void Start(Player hum, Player cpu) //Creates initial situation
{
Words.Begin();
Create.TheirDecks(hum, cpu);
Create.Name(hum);
}
static public void ShuffleDecks(Player hum, Player cpu)
{
hum.myDeck.Shuffle();
cpu.myDeck.Shuffle();
}
static public void DrawCards(Player hum, Player cpu) // changes the current card
{
hum.DrawOne();
cpu.DrawOne();
}
static public void Gameplay(Player hum, Player cpu, int round) // The normal gameplay loop
{
GameFlow.DrawCards(hum, cpu);
Words.Template(hum, cpu, round);
GameFlow.CheckWin(hum, cpu);
}
static public void Ending(Player hum, Player cpu) // Once all the cards have been played
{
string answer = "";
bool correctForm = false;
Words.LastWords(hum, cpu);
while (!correctForm)
{
Console.WriteLine("Would you like to play again? Enter y for yes or n for no.");
answer = Console.ReadLine();
answer = answer.ToLower();
if(answer != "y" && answer != "n")
{
Console.WriteLine("Thats not a valid option you idiot!");
Console.WriteLine("Press enter to continue.");
Console.ReadLine();
Console.Clear();
Words.LastWords(hum, cpu);
}
if(answer == "y" || answer == "n")
{
correctForm = true;
}
}
if (answer == "y")
{
PlayingAgain(hum ,cpu);
Console.Clear();
}
if (answer == "n")
{
Console.WriteLine("Thanks for playing!");
Console.WriteLine("Press enter to exit.");
Environment.Exit(0);
}
}
static public void PlayingAgain(Player hum , Player cpu)
{
ShuffleDecks(hum, cpu);
hum.wins = 0;
cpu.wins = 0;
}
static public void CheckWin(Player hum , Player cpu)
{
Console.WriteLine("");
if ((int)hum.currentCard.face > (int)cpu.currentCard.face)
{
hum.wins++;
Console.WriteLine();
Console.WriteLine("You win this one! Nice!");
Console.WriteLine("Press enter to keep going.");
Console.ReadLine();
Console.Clear();
}
else if ((int)hum.currentCard.face < (int)cpu.currentCard.face)
{
cpu.wins++;
Console.WriteLine();
Console.WriteLine("Looks like the CPU won this one. You suck!");
Console.WriteLine("Press enter to keep going.");
Console.ReadLine();
Console.Clear();
}
else
{
Console.WriteLine();
Console.WriteLine("Its a draw!");
Console.WriteLine("Press enter to keep going.");
Console.ReadLine();
Console.Clear();
}
}
}
static class Words // The dialogue of the program
{
public static void Begin()
{
Console.WriteLine("Hello , welcome to war!");
Console.WriteLine("The rules are simple. Its you vs a cpu");
Console.WriteLine("You each pull 1 card from your decks and see which is highest.");
Console.WriteLine("Your card will be the one under your name , while the other is the CPUs.");
Console.WriteLine("The one with the most points at the end wins all the glory!");
Console.WriteLine("Understand?");
Console.WriteLine("Press enter if you're ready for the showdown.");
Console.ReadLine();
Console.Clear();
}
public static void Template(Player hum , Player cpu , int round) //Prints the normal screen
{
int distance = 17; //distance between the 2 names
Console.Write("{0} wins = {1}", hum.name, hum.wins);
Console.Write(" R{0}", round);
distance -= hum.name.Length;
while (distance > 0)
{
Console.Write(" ");
distance--;
}
Console.Write("{0} wins = {1}" , cpu.name , cpu.wins);
Console.WriteLine();
Console.WriteLine();
hum.currentCard.PrintCard();
Console.Write(" vs ");
cpu.currentCard.PrintCard();
}
public static void LastWords(Player hum , Player cpu)
{
Console.WriteLine("Thats all the cards!");
Console.WriteLine("So this is the final score: {0} = {1} and {2} = {3}" , hum.name, hum.wins, cpu.name, cpu.wins);
if(hum.wins > cpu.wins)
{
Console.WriteLine("You have beaten the CPU in this game of luck!!!! Congrats!!!");
}
else if(cpu.wins > hum.wins)
{
Console.WriteLine("The CPU has detroyed you and everything you have loved. Congrats!!!");
}
else
{
Console.WriteLine("Oh my! Its a draw. You both are equal warriors of luck.");
}
}
}
public static void Begin()
contains a fairly decent explanation. \$\endgroup\$