diff --git a/StripJackNaked/Cards.cs b/StripJackNaked/PlayingCards.cs similarity index 63% rename from StripJackNaked/Cards.cs rename to StripJackNaked/PlayingCards.cs index 6788e29..5b44a3f 100644 --- a/StripJackNaked/Cards.cs +++ b/StripJackNaked/PlayingCards.cs @@ -1,43 +1,18 @@ -namespace Cards +namespace PlayingCards { - public enum Suit - { - Spades, - Clubs, - Diamonds, - Hearts - } + public enum Suit { Spades, Clubs, Diamonds, Hearts } - public enum PictureCard - { - Jack = 1, - Queen, - King, - Ace - } + public enum PictureCard { Jack = 1, Queen, King, Ace } public class Card { public string Value; public Suit Suit; - public string NamedValue - { - get => Value + " of " + Suit; - } - public Boolean IsPicture - { - get => Enum.IsDefined(typeof(PictureCard), Value); - } - - public Boolean IsBlack - { - get => (Enum.GetName(Suit) == "Spades" || Enum.GetName(Suit) == "Clubs"); - } - - public Boolean IsRed - { - get => (Enum.GetName(Suit) == "Diamonds" || Enum.GetName(Suit) == "Hearts"); - } + public string NamedValue => Value + " of " + Suit; + public bool IsPicture => Enum.IsDefined(typeof(PictureCard), Value); + public bool IsNumber => !Enum.IsDefined(typeof(PictureCard), Value); + public bool IsBlack => (Enum.GetName(Suit) == "Spades" || Enum.GetName(Suit) == "Clubs"); + public bool IsRed => (Enum.GetName(Suit) == "Diamonds" || Enum.GetName(Suit) == "Hearts"); } public class Deck @@ -68,8 +43,8 @@ } } } - private static Random rng = new(); + private static Random rng = new(); public static void Shuffle() { Cards = Cards.OrderBy(a => rng.Next()).ToList(); @@ -78,7 +53,7 @@ public class Actions { - public static Boolean MoveCard(List From, List To, Card card = null) + public static bool MoveCard(List From, List To, Card card = null) { if (From.Count() == 0) { @@ -86,7 +61,9 @@ } if (card is null) - card = From.FirstOrDefault(); + { + card = From.FirstOrDefault(); // FIFO + } if (From.Contains(card) && !To.Contains(card)) { @@ -94,7 +71,7 @@ From.Remove(card); return true; } - return false; + return false; // If we're here, something went bang } } } \ No newline at end of file diff --git a/StripJackNaked/Program.cs b/StripJackNaked/Program.cs index bc9dd76..0f659e0 100644 --- a/StripJackNaked/Program.cs +++ b/StripJackNaked/Program.cs @@ -1,8 +1,8 @@ -using Cards; +using PlayingCards; namespace StripJackNaked { - static class Constants + internal static class Constants { public const int PlayerCount = 2; } @@ -19,38 +19,35 @@ namespace StripJackNaked class Program { - public static int NextPlayer(int CurrentPlayer) - { - return ++CurrentPlayer % Constants.PlayerCount; - } + public static int NextPlayer(int CurrentPlayer) { return ++CurrentPlayer % Constants.PlayerCount; } - public static Boolean PlayCard(List From) - { - return Actions.MoveCard(From, Kitty.Pile); - } + public static bool PlayCard(List From) { return Actions.MoveCard(From, Kitty.Pile); } - public static void TakePile(ListWinner) + public static void TakePile(List Winner) { while (Kitty.Pile.Count() > 0) { - Actions.MoveCard(Kitty.Pile, Winner); + _ = Actions.MoveCard(Kitty.Pile, Winner); } } - public static void ShowList(ListCards) + public static void ShowList(List Cards) { foreach (Card card in Cards) + { Console.Write(card.NamedValue + ((card == Cards.LastOrDefault()) ? "" : ", ")); - + } Console.WriteLine(); } - static void Main() + private static void Main() { // Init players List Players = new(); for (int i = 0; i < Constants.PlayerCount; i++) + { Players.Add(new Player()); + } // Init deck Deck.Enumerate(); @@ -61,10 +58,9 @@ namespace StripJackNaked { Card card = Deck.Cards.Last(); int player = Deck.Cards.Count() % Constants.PlayerCount; // Alternate between players 0 and 1 - Actions.MoveCard(Deck.Cards, Players[player].Hand); + _ = Actions.MoveCard(Deck.Cards, Players[player].Hand, card); } - // Init first round int CardsToDraw = 1; Card ActivePictureCard = null; @@ -82,10 +78,11 @@ namespace StripJackNaked CardsToDraw = (int)Enum.Parse(typeof(PictureCard), ActivePictureCard.Value); // Cards to draw correlates to PictureCard enum value ActivePlayer = NextPlayer(ActivePlayer); } - else - if (ActivePictureCard is not null) - // Active player didn't play a picture card when needed to - CardsToDraw--; + else if (ActivePictureCard is not null) + { + // Active player didn't play a picture card when needed to + CardsToDraw--; + } if (CardsToDraw < 1) { @@ -98,17 +95,18 @@ namespace StripJackNaked } if (ActivePictureCard is null) + { ActivePlayer = NextPlayer(ActivePlayer); - + } // Show some output - Console.WriteLine("Player 0:"); + Console.Write("Player 0: "); ShowList(Players[0].Hand); - Console.WriteLine("Player 1:"); + Console.Write("Player 1: "); ShowList(Players[1].Hand); - Console.WriteLine("Kitty:"); + Console.Write("Kitty: "); ShowList(Kitty.Pile); Console.WriteLine("---------------------");