diff --git a/Classes/IDeck.cs b/Classes/IDeck.cs index 5b8b65b..3f3dd1a 100644 --- a/Classes/IDeck.cs +++ b/Classes/IDeck.cs @@ -10,7 +10,7 @@ public interface IDeck where T : ICard{ public void ShuffleDeck(ShuffleType shuffleType); - public void SwapCards(int firstIndex, int otherIndex); + public void SwapCards(int firstIndex, int secondIndex); public void MoveCard(int cardIndex, int newIndexx); } diff --git a/Classes/TarotDeck.cs b/Classes/TarotDeck.cs index e7d17d3..d905b46 100644 --- a/Classes/TarotDeck.cs +++ b/Classes/TarotDeck.cs @@ -49,10 +49,10 @@ public void ShuffleDeck(ShuffleType shuffleType){ } } - public void SwapCards(int firstIndex, int otherIndex){ + public void SwapCards(int firstIndex, int secondIndex){ TarotCard temp = Cards[firstIndex]; - Cards[firstIndex] = Cards[otherIndex]; - Cards[otherIndex] = temp; + Cards[firstIndex] = Cards[secondIndex]; + Cards[secondIndex] = temp; } public void MoveCard(int oldIndex, int newIndex){ diff --git a/Options.cs b/Options.cs index 0807a71..3d3f1ee 100644 --- a/Options.cs +++ b/Options.cs @@ -51,4 +51,22 @@ public class ListOption{ [Value(0, MetaName = "name", MetaValue = "string", Required = false, HelpText = "Name of card or spread to list. Leave empty for all.")] public string Name{get; set;} } + + [Verb("move", HelpText = "Move a card to a new position in the deck.")] + public class MoveOptions{ + [Value(0, MetaName = "card index", MetaValue = "int", Required = true, HelpText = "Position of card to move.")] + public int OldIndex{get; set;} + + [Value(0, MetaName = "new index", MetaValue = "int", Required = true, HelpText = "Position of where to move the card to.")] + public int NewIndex{get; set;} + } + + [Verb("swap", HelpText = "Swap the positions of two cards in the deck")] + public class SwapOptions{ + [Value(0, MetaName = "first card index", MetaValue = "int", Required = true, HelpText = "Position of first card to swap.")] + public int FirstIndex{get; set;} + + [Value(0, MetaName = "second card index", MetaValue = "int", Required = true, HelpText = "Position of second card to swap.")] + public int SecondIndex{get; set;} + } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index 24d1173..590a6c4 100644 --- a/Program.cs +++ b/Program.cs @@ -27,7 +27,8 @@ class Program{ static int Main(string[] args){ TarotDeck deck = new TarotDeck(); TarotSpreads spreads = new TarotSpreads(); - Type[] types = {typeof(ShuffleOptions), typeof(GetOptions), typeof(ResetOptions), typeof(SpreadOptions), typeof(ListOption)}; + Type[] types = {typeof(ShuffleOptions), typeof(GetOptions), typeof(ResetOptions), typeof(SpreadOptions), typeof(ListOption), + typeof(MoveOptions), typeof(SwapOptions)}; HandleFiles(deck, spreads); @@ -37,6 +38,8 @@ static int Main(string[] args){ (ResetOptions options) => Reset(options, deck, spreads), (SpreadOptions options) => Spread(options, deck, spreads), (ListOption options) => List(options, deck, spreads), + (MoveOptions options) => Move(options, deck), + (SwapOptions options) => Swap(options, deck), errors => 1 ); } @@ -220,5 +223,27 @@ private static int List(ListOption options, TarotDeck deck, TarotSpreads spreads } return 0; } + + private static int Move(MoveOptions options, TarotDeck deck){ + if(options.OldIndex > deck.Cards.Count -1 || options.OldIndex < 0 || + options.NewIndex > deck.Cards.Count -1 || options.NewIndex < 0){ + Console.WriteLine($"Positional index is outside of the deck range [0,{deck.Cards.Count -1}]."); + return 1; + }else{ + deck.MoveCard(options.OldIndex, options.NewIndex); + return 0; + } + } + + private static int Swap(SwapOptions options, TarotDeck deck){ + if(options.FirstIndex > deck.Cards.Count -1 || options.FirstIndex < 0 || + options.SecondIndex > deck.Cards.Count -1 || options.SecondIndex < 0){ + Console.WriteLine($"Positional index is outside of the deck range [0,{deck.Cards.Count -1}]."); + return 1; + }else{ + deck.SwapCards(options.FirstIndex, options.SecondIndex); + return 0; + } + } } } \ No newline at end of file