diff --git a/Class/ISpread.cs b/Class/ISpread.cs deleted file mode 100644 index 7034357..0000000 --- a/Class/ISpread.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace tarot{ - interface ISpread : Menu.IMenu{ - - } -} diff --git a/Class/IUserInterface.cs b/Class/IUserInterface.cs deleted file mode 100644 index 7f15a23..0000000 --- a/Class/IUserInterface.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace tarot{ - public interface IUserInterface{ - public bool IsActive(); - public void Show(); - public IUserInterface Switch(IUserInterface ui); - } -} \ No newline at end of file diff --git a/Class/MainUI.cs b/Class/MainUI.cs deleted file mode 100644 index 7de5261..0000000 --- a/Class/MainUI.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using tarot.Menu; -using tarot.Subscription.Logging; - -namespace tarot{ - public class MainUI : IUserInterface{ - private readonly int _width = 60; - private readonly int _height = 30; - private readonly int _visibleLogs = 10; - private readonly ListMenu _menu; - private readonly Log _log; - private readonly Deck _deck; - private Boolean _active; - - public MainUI(Deck deck) { - _deck = deck; - _log = new Log(); - - MenuEntryFunc menuEntry1 = new MenuEntryFunc("Overhand Shuffle", () =>{ - deck.ShuffleDeck(ShuffleType.Overhand); - return true; - }, new ActionLogger("Performed Overhand Shuffle", - "Failed to perform Overhand Shuffle", _log)); - - MenuEntryFunc menuEntry2 = new MenuEntryFunc("Riffle Shuffle", () => { - deck.ShuffleDeck(ShuffleType.Riffle); - return true; - }, new ActionLogger("Performed Riffle Shuffle", - "Failed to perform Riffle Shuffle", _log)); - - MenuEntryFunc menuEntry3 = new MenuEntryFunc("Take Card", () => - deck.RequeueCard(), - new ValueLogger("You retrieved: ", _log)); - - MenuEntryFunc menuEntry4 = new MenuEntryFunc("Exit", () =>{ - Environment.Exit(0); - return true; - }); - - IMenuEntry[] menuEntries = { menuEntry1, menuEntry2, menuEntry3, menuEntry4 }; - _menu = new ListMenu(menuEntries, "=> "); - } - - public bool IsActive(){ - return _active; - } - - public void Show(){ - Init(); - _active = true; - - while (_active){ - Clear(); - _menu.Draw(1, 1); - DrawLog(1, _height - 3 - _visibleLogs); - Console.SetCursorPosition(1, _height - 2); - Console.Write("> "); - - while(!Console.KeyAvailable){ - System.Threading.Thread.Sleep(100); - } - - CheckKey(Console.ReadKey()); - } - } - - public IUserInterface Switch(IUserInterface ui){ - _active = false; - ui.Show(); - return this; - } - - private void CheckKey(ConsoleKeyInfo keyInfo){ - switch (keyInfo.Key){ - case ConsoleKey.UpArrow: - case ConsoleKey.W: - _menu.Up(); - break; - case ConsoleKey.DownArrow: - case ConsoleKey.S: - _menu.Down(); - break; - case ConsoleKey.Enter: - _menu.Select(); - break; - default: - break; - } - } - - private void Clear(){ - Console.Clear(); - } - - private void Init(){ - #pragma warning disable CA1416 // Validate platform compatibility - Console.SetWindowSize(_width, _height); - Console.SetBufferSize(_width, _height); - #pragma warning restore CA1416 // Validate platform compatibility - Console.BackgroundColor = ConsoleColor.Blue; - Console.ForegroundColor = ConsoleColor.White; - Console.Clear(); - } - - public void DrawBox(){ - throw new NotImplementedException(); - } - - private void DrawLog(int x, int y){ - Console.SetCursorPosition(x, y); - Console.Write("Log:"); - for (int i = 0; i < _visibleLogs; i++){ - if(_log.Count() - i > 0) { - Console.SetCursorPosition(x, y + _visibleLogs - i); - Console.Write(_log.Get(_log.Count() - 1 - i)); - } - } - } - - private class Box{ - public Point Point1; - public Point Point2; - - public Box(Point p1, Point p2){ - this.Point1 = p1; - this.Point2 = p2; - } - - public int GetWidth(){ - return Point2.X - Point1.X; - } - - public int GetHeight(){ - return Point2.Y - Point1.Y; - } - - public void Draw(){ - Console.SetCursorPosition(Point1.X, Point1.Y); - Console.Write("┌"); - Console.SetCursorPosition(Point2.X, Point1.Y); - Console.Write("┐"); - Console.SetCursorPosition(Point1.X, Point2.Y); - Console.Write("└"); - Console.SetCursorPosition(Point2.X, Point2.Y); - Console.Write("┘"); - - for (int i = 1; i < GetWidth() - 1; i++){ - Console.SetCursorPosition(Point1.X + i, Point1.Y); - Console.Write("─"); - Console.SetCursorPosition(Point1.X + i, Point2.Y); - Console.Write("─"); - } - - for (int i = 1; i < GetHeight() - 1; i++){ - Console.SetCursorPosition(Point1.X, Point1.Y + i); - Console.Write("│"); - Console.SetCursorPosition(Point2.X, Point1.Y + i); - Console.Write("│"); - } - } - } - - private class Point{ - public int X; - public int Y; - - public Point(int x, int y){ - this.X = x; - this.Y = y; - } - } - } -} diff --git a/Class/SpreadUI.cs b/Class/SpreadUI.cs deleted file mode 100644 index b42d028..0000000 --- a/Class/SpreadUI.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace tarot{ - class SpreadUI : IUserInterface{ - private Deck deck; - private Boolean _active; - - public SpreadUI(Deck deck){ - this.deck = deck; - } - - public void Show(){ - throw new NotImplementedException(); - } - - public IUserInterface Switch(IUserInterface ui){ - throw new NotImplementedException(); - } - public bool IsActive(){ - return _active; - } - } -} diff --git a/Program.cs b/Program.cs index 0615d97..9c7b279 100644 --- a/Program.cs +++ b/Program.cs @@ -1,14 +1,55 @@ using System; -using System.Collections.Generic; +using CommandLine; namespace tarot{ class Program{ - static void Main(string[] args){ + [Verb("get", HelpText = "Retrieve cards from the deck.")] + public class GetOptions{ + [Value(0, MetaName = "amount", MetaValue = "int", Default = 1, HelpText = "Amount of cards to retrieve.")] + public uint Amount{get; set;} + } + + [Verb("shuffle", HelpText = "Shuffle the deck")] + public class ShuffleOptions{ + [Value(0, MetaName = "type", MetaValue = "string", Default = "riffle", HelpText = "What shuffle to perform.")] + public string Type{get; set;} + } + + static int Main(string[] args){ + Type[] types = {typeof(ShuffleOptions), typeof(GetOptions)}; + Deck deck = new Deck(); deck.AddToDeck(Utilities.DeserializeMajorArcana(@"Data/base_majorarcana.json")); deck.AddToDeck(Utilities.DeserializeMinorArcana(@"Data/base_minorarcana.json")); - MainUI ui = new MainUI(deck); - ui.Show(); - } + + return Parser.Default.ParseArguments(args, types) + .MapResult( + (GetOptions options) => { + options.Amount = Math.Max(1, options.Amount); + for (int i = 0; i < options.Amount; i++){ + Console.WriteLine(deck.RequeueCard().ToString()); + } + return 0; + }, + (ShuffleOptions options) => { + switch(options.Type.ToLower()){ + case "riffle": + deck.ShuffleDeck(ShuffleType.Riffle); + break; + case "overhand": + deck.ShuffleDeck(ShuffleType.Overhand); + break; + case "fisheryates" or "perfect": + deck.ShuffleDeck(ShuffleType.FisherYates); + break; + default: + Console.WriteLine("Unkown shuffletype: {0}", options.Type.ToLower()); + return 1; + } + Console.WriteLine("Performed {0} shuffle", options.Type.ToLower()); + return 0; + }, + errors => 1); + } } } diff --git a/tarot.csproj b/tarot.csproj index d6f9c01..2514c09 100644 --- a/tarot.csproj +++ b/tarot.csproj @@ -6,6 +6,7 @@ +