Skip to content

Commit

Permalink
List cards in order on view
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarcederberg committed Aug 3, 2021
1 parent dbe8b2a commit ff8c55c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Classes/ISpread.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace tarot{
public interface ISpread<T, U> where T : IDeck<U> where U : ICard {
public void AddCards(T deck);
public void EnqueueCards(T deck);

public string SerializeSpread();

Expand Down
2 changes: 1 addition & 1 deletion Classes/TarotSpread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public TarotSpread(string[] positions){
this._spread_cards = new TarotCard[Length()];
}

public void AddCards(TarotDeck deck){
public void EnqueueCards(TarotDeck deck){
for (int i = 0; i < Length(); i++){
this._spread_cards[i] = deck.RequeueCard();
}
Expand Down
10 changes: 5 additions & 5 deletions Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public class SpreadOptions{
public string Name{get; set;}
}

[Verb("list", HelpText = "List all available cards or spreads.")]
public class ListOption{
[Option('c',"card", SetName = "cards", MetaValue = "string", Required = true, HelpText = "List all, or a specific card.")]
[Verb("view", HelpText = "View all available cards or spreads.")]
public class ViewOptions{
[Option('c',"card", SetName = "cards", MetaValue = "string", Required = true, HelpText = "List all, or view a specific card.")]
public bool Card{get; set;}

[Option('s',"spread", SetName = "spread", MetaValue = "string", Required = true, HelpText = "List all, or a specific spread.")]
[Option('s',"spread", SetName = "spread", MetaValue = "string", Required = true, HelpText = "List all, or view a specific spread.")]
public bool Spread{get; set;}

[Value(0, MetaName = "name", MetaValue = "string", Required = false, HelpText = "Name of card or spread to list. Leave empty for all.")]
[Value(0, MetaName = "name", MetaValue = "string", Required = false, HelpText = "Name of card or spread to view. Leave empty for all.")]
public string Name{get; set;}
}

Expand Down
144 changes: 75 additions & 69 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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(ViewOptions),
typeof(MoveOptions), typeof(SwapOptions)};

HandleFiles(deck, spreads);
Expand All @@ -37,7 +37,7 @@ static int Main(string[] args){
(ShuffleOptions options) => Shuffle(options, deck),
(ResetOptions options) => Reset(options, deck, spreads),
(SpreadOptions options) => Spread(options, deck, spreads),
(ListOption options) => List(options, deck, spreads),
(ViewOptions options) => View(options, deck, spreads),
(MoveOptions options) => Move(options, deck),
(SwapOptions options) => Swap(options, deck),
errors => 1
Expand Down Expand Up @@ -162,10 +162,11 @@ private static int Reset(ResetOptions options, TarotDeck deck, TarotSpreads spre

private static int Spread(SpreadOptions options, TarotDeck deck, TarotSpreads spreads){
List<string> names = new List<string>(spreads.Keys);

if(names.Contains(options.Name)){
TarotSpread spread = spreads[options.Name];
spread.AddCards(deck);
string name = names.Find(n => n.ToLower() == options.Name.ToLower());

if(name is not null){
TarotSpread spread = spreads[name];
spread.EnqueueCards(deck);
spread.PrintSpread();
SaveDeck(deck);
return 0;
Expand All @@ -175,75 +176,80 @@ private static int Spread(SpreadOptions options, TarotDeck deck, TarotSpreads sp
}
}

private static int List(ListOption options, TarotDeck deck, TarotSpreads spreads){
if(options.Card){
if(options.Name != default){
TarotCard card = deck.Cards.Find((TarotCard c) => c.Name.ToLower() == options.Name.ToLower());

if(card is not null){
Console.WriteLine($"{card.GetName()}:\n\t{card.GetKeywords()}");
}else{
Console.WriteLine("That card does not exist.");
return 1;
}
}else{
foreach (TarotCard card in deck.Cards)
{
Console.WriteLine($"{card.GetName()}:\n\t{card.GetKeywords()}");
}
}
}else if(options.Spread){
List<string> names = new List<string>(spreads.Keys);
names.Sort();

if(options.Name != default){
string name = names.Find((string n) => n.ToLower() == options.Name.ToLower());

if(name is not null){
TarotSpread spread = spreads[name];
private static int View(ViewOptions options, TarotDeck deck, TarotSpreads spreads){
if(options.Card){
if(options.Name != default){
TarotCard card = deck.Cards.Find(c => c.Name.ToLower() == options.Name.ToLower());

Console.WriteLine($"{name}:");
for (int i = 0; i < spread.Length(); i++){
Console.WriteLine($"\t{i+1}. {spread.Positions[i]}");
}
}else{
Console.WriteLine("That spread does not exist.");
return 1;
}
}else{
foreach(string name in names){
if(card is not null){
Console.WriteLine($"{card.GetName()}:\n\t{card.GetKeywords()}");
}else{
Console.WriteLine("That card does not exist.");
return 1;
}
}else{
List<TarotCard> cards_in_order = Utilities.Deserialize<List<TarotCard>>(defaultCardsFilePath);
try{
cards_in_order.AddRange(Utilities.Deserialize<List<TarotCard>>(userCardsFilePath));
}catch (System.Exception){}

for (int i = 0; i < cards_in_order.Count; i++){
TarotCard card = cards_in_order[i];
Console.WriteLine($"{card.GetName()}:\n\tKeywords: {card.GetKeywords()}");
}
}
}else if(options.Spread){
List<string> names = new List<string>(spreads.Keys);
names.Sort();

if(options.Name != default){
string name = names.Find(n => n.ToLower() == options.Name.ToLower());

if(name is not null){
TarotSpread spread = spreads[name];

Console.WriteLine($"{name}:");
for (int i = 0; i < spread.Length(); i++){
Console.WriteLine($"\t{i+1}. {spread.Positions[i]}");
}
}else{
Console.WriteLine("That spread does not exist.");
return 1;
}
}else{
foreach(string name in names){
TarotSpread spread = spreads[name];

Console.WriteLine($"{name}:");
for (int i = 0; i < spread.Length(); i++){
Console.WriteLine($"\t{i+1}. {spread.Positions[i]}");
}
}
}
}
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;
}
}
}
}
}
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;
}
}
}
}
7 changes: 4 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ C# Tarot-reading application

### Todo

- [ ] List cards in order
- [ ] Flags for retrieving in .json-format.
- [ ] Add option for drawing reverse cards
- [ ] ⚠️Switch uint arguments to int, handle out-of-range cases.
- [ ] ⚠️Customize help.
- [ ] ⚠️Refactor input-handling.
- [ ] ⚠️Add documentation
- [ ] ⚠️Rework shuffling.
- [ ] 🐞Error-handling for parsing/saving files
- [ ] ⚠️Error-handling for parsing/saving files

### In Progress


### Done ✓

- [x] List cards in order
- [x] Move listing spreads and viewing one single spread to a verb that also allows viewing a specific card or all cards
- [x] Add tarot card meanings/keywords.
- [x] Function to reset deck and/or spreads, either from original or from own chosen file.
- [x] Current Spreads-file, similar to current deck.
- [x] Commands to swap, or insert cards at specific positions in deck, for posibility to do interactive shuffling.
- [x] Commands to swap, or insert cards at specific positions in deck, for posibility to do interactive shuffling.

0 comments on commit ff8c55c

Please sign in to comment.