-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
344 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,213 @@ | ||
class Program | ||
using System.Text.RegularExpressions; | ||
|
||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Spore.Clear(); | ||
for(int i=0;i<CardType.Cards.Length;i++) | ||
Console.Title = "Magic Card Trick"; | ||
Console.CursorVisible = false; | ||
List<Card> deck = new List<Card>(); | ||
deck.Add(new Card( | ||
$"<Red>♥<Reset>A", | ||
[@" ", @" <Red>♥<Reset> ", @" "], | ||
SporeTraceColor.White | ||
)); | ||
for(int i=2;i<11;i++) | ||
{ | ||
deck.Add(new Card( | ||
$"<Red>♥<Reset>{i}", | ||
[@" ", @" <Red>♥<Reset> ", @" "], | ||
SporeTraceColor.White | ||
)); | ||
} | ||
deck.Add(new Card( | ||
$"<Red>♥<Reset>J", | ||
[@" ", @" <Red>♥<Reset> ", @" "], | ||
SporeTraceColor.White | ||
)); | ||
deck.Add(new Card( | ||
$"<Red>♥<Reset>Q", | ||
[@" ", @" <Red>♥<Reset> ", @" "], | ||
SporeTraceColor.White | ||
)); | ||
deck.Add(new Card( | ||
$"<Red>♥<Reset>K", | ||
[@" ", @" <Red>♥<Reset> ", @" "], | ||
SporeTraceColor.White | ||
)); | ||
string savedName = ""; | ||
int selectedCard = 0; | ||
while(true) | ||
{ | ||
Spore.Clear(); | ||
Spore.Color("Pick a card (using the Up/Down arrows and Enter to select):"); | ||
for(int i=0;i<deck.Count;i++) | ||
{ | ||
Card c = deck[i]; | ||
if(i == selectedCard){c.RimColor = SporeTraceColor.Green;}else{c.RimColor = SporeTraceColor.White;} | ||
c.DisplayCard(0, i+1); | ||
} | ||
ConsoleKey key = Console.ReadKey(true).Key; | ||
if(key == ConsoleKey.UpArrow){ | ||
selectedCard--; | ||
}else if(key == ConsoleKey.DownArrow){ | ||
selectedCard++; | ||
}else if(key == ConsoleKey.Enter){ | ||
Spore.Clear(); | ||
savedName = deck[selectedCard].Name; | ||
break; | ||
} | ||
selectedCard = Math.Clamp(selectedCard, 0, deck.Count-1); | ||
} | ||
Random rng = new Random(); | ||
for(int i=0;i<5;i++) | ||
{ | ||
Spore.Clear(); | ||
Spore.Color("Shuffling the deck..."); | ||
Shuffle(deck); | ||
for(int j=0;j<deck.Count;j++) | ||
{ | ||
Card c = deck[j]; | ||
c.RimColor = SporeTraceColor.White; | ||
c.DisplayCard(0, j+1); | ||
} | ||
Thread.Sleep(200); | ||
} | ||
for(int i=0;i<10;i++) | ||
{ | ||
Spore.Clear(); | ||
Spore.Color("Finding your card..."); | ||
deck[rng.Next(deck.Count)].DisplayCard(0, 1); | ||
Thread.Sleep(200); | ||
} | ||
bool selection = false; | ||
while(true) | ||
{ | ||
string cardType = CardType.Cards[i]; | ||
Spore.Color( | ||
$"<Reset>┌{cardType}<Red>♥<Reset>{(cardType.Length == 1 ? '─' : "")}──┐ " | ||
+ | ||
$"<Reset>┌{cardType}<White>♣<Reset>{(cardType.Length == 1 ? '─' : "")}──┐ " | ||
+ | ||
$"<Reset>┌{cardType}<Red>♦<Reset>{(cardType.Length == 1 ? '─' : "")}──┐ " | ||
+ | ||
$"<Reset>┌{cardType}<White>♠<Reset>{(cardType.Length == 1 ? '─' : "")}──┐\n" | ||
); | ||
if(i == CardType.Cards.Length-1) | ||
Spore.Clear(); | ||
Spore.Color("Is this your card?"); | ||
foreach(Card c in deck) | ||
{ | ||
Spore.Color( | ||
"│ │ │ │ │ │ │ │ \n"+ | ||
"│ │ │ │ │ │ │ │ \n"+ | ||
"│ │ │ │ │ │ │ │ \n"+ | ||
$"└──{(cardType.Length == 1 ? '─' : "")}<Red>♥<Reset>{cardType}┘ "+ | ||
$"└──{(cardType.Length == 1 ? '─' : "")}<White>♣<Reset>{cardType}┘ "+ | ||
$"└──{(cardType.Length == 1 ? '─' : "")}<Red>♦<Reset>{cardType}┘ "+ | ||
$"└──{(cardType.Length == 1 ? '─' : "")}<White>♠<Reset>{cardType}┘\n" | ||
); | ||
if(c.Name == savedName) | ||
{ | ||
c.DisplayCard(0, 1); | ||
break; | ||
} | ||
} | ||
Spore.Color($"{(!selection ? "<Red>" : "<Reset>")}>No {(selection ? "<Green>" : "<Reset>")}>Yes"); | ||
ConsoleKey key = Console.ReadKey(true).Key; | ||
if(key == ConsoleKey.LeftArrow){selection = false;} | ||
else if(key == ConsoleKey.RightArrow){selection = true;} | ||
else if(key == ConsoleKey.Enter){break;} | ||
} | ||
Spore.Clear(); | ||
if(!selection) | ||
{ | ||
Spore.Color("LIAR!!!"); | ||
}else{ | ||
Spore.Color("Thanks for playing!"); | ||
} | ||
Console.ReadKey(true); | ||
} | ||
|
||
public static void Shuffle(List<Card> list) | ||
{ | ||
Random rng = new Random(); | ||
int n = list.Count; | ||
while(n > 1){ | ||
n--; | ||
int k = rng.Next(n + 1); | ||
Card value = list[k]; | ||
list[k] = list[n]; | ||
list[n] = value; | ||
} | ||
} | ||
} | ||
|
||
public static class CardType | ||
public struct Card | ||
{ | ||
public static readonly string Ace = "A"; | ||
public static readonly string Two = "2"; | ||
public static readonly string Three = "3"; | ||
public static readonly string Four = "4"; | ||
public static readonly string Five = "5"; | ||
public static readonly string Six = "6"; | ||
public static readonly string Seven = "7"; | ||
public static readonly string Eight = "8"; | ||
public static readonly string Nine = "9"; | ||
public static readonly string Ten = "10"; | ||
public static readonly string Jack = "J"; | ||
public static readonly string Queen = "Q"; | ||
public static readonly string King = "K"; | ||
public static readonly string[] Cards = new string[]{ | ||
Ace, | ||
Two, | ||
Three, | ||
Four, | ||
Five, | ||
Six, | ||
Seven, | ||
Eight, | ||
Nine, | ||
Ten, | ||
Jack, | ||
Queen, | ||
King, | ||
}; | ||
private static readonly string _colorSplitPattern = @"(<Black>|<DarkBlue>|<DarkGreen>|<DarkCyan>|<DarkRed>|<DarkMagenta>|<DarkYellow>|<Gray>|<DarkGray>|<Blue>|<Green>|<Cyan>|<Red>|<Magenta>|<Yellow>|<White>|<Previous>|<Reset>)"; | ||
public string Name = "a"; | ||
public SporeTraceColor RimColor = SporeTraceColor.White; | ||
public string[] Art = [ | ||
" ", | ||
" ", | ||
" " | ||
]; | ||
|
||
public Card(){} | ||
public Card(string name, string[] art, SporeTraceColor rimColor=SporeTraceColor.White) | ||
{ | ||
if(Regex.Replace(name, _colorSplitPattern, "").Length > 5){throw new Exception("Name parameter must be between 0-5 characters long excluding colors.");} | ||
if(art.Length != 3 || Regex.Replace(art[0], _colorSplitPattern, "").Length != 5 || Regex.Replace(art[1], _colorSplitPattern, "").Length != 5 || Regex.Replace(art[2], _colorSplitPattern, "").Length != 5){throw new Exception("Art parameter must be 3 strings of 5 chars long");} | ||
Name = name; | ||
Art = art; | ||
RimColor = rimColor; | ||
} | ||
|
||
public void DisplayCard(int x=0, int y=0) | ||
{ | ||
PrintColoredText( | ||
$"<{RimColor}>┌<Reset>{Format(Name, 5, '─')}<{RimColor}>┐<Reset>\n"+ | ||
$"<{RimColor}>│<Reset>{Center(Art[0], 5, ' ')}<{RimColor}>│<Reset>\n"+ | ||
$"<{RimColor}>│<Reset>{Center(Art[1], 5, ' ')}<{RimColor}>│<Reset>\n"+ | ||
$"<{RimColor}>│<Reset>{Center(Art[2], 5, ' ')}<{RimColor}>│<Reset>\n"+ | ||
$"<{RimColor}>└<Reset>{ReverseFormat(Name, 5, '─')}<{RimColor}>┘<Reset>\n", | ||
x, | ||
y | ||
); | ||
} | ||
|
||
private void PrintColoredText(string text, int startX, int startY) | ||
{ | ||
int currentY = startY; | ||
foreach(string line in text.Split('\n')) | ||
{ | ||
Console.SetCursorPosition(startX, currentY); | ||
Spore.Color(line); | ||
currentY++; | ||
} | ||
} | ||
|
||
private string Format(string data, int totalWidth, char d=' ') | ||
{ | ||
return $"{data}<{RimColor}>{new string(d, Math.Max(0, totalWidth-Regex.Replace(data, _colorSplitPattern, "").Length))}<Reset>"; | ||
} | ||
private string ReverseFormat(string data, int totalWidth, char d=' ') | ||
{ | ||
return $"<{RimColor}>{new string(d, Math.Max(0, totalWidth-Regex.Replace(data, _colorSplitPattern, "").Length))}<Reset>{data}"; | ||
} | ||
private string Center(string data, int totalWidth, char filler=' ') | ||
{ | ||
string m = data; | ||
for(int i=Math.Max(0, totalWidth-Regex.Replace(data, _colorSplitPattern, "").Length);i>0;i--){ | ||
m = ((i % 2 == 1) ? filler : "") + m + ((i % 2 == 0) ? filler : ""); | ||
} | ||
return m; | ||
} | ||
} | ||
|
||
// ┌─┬┐ | ||
// │ ││ | ||
// ├─┼┤ | ||
// └─┴┘ | ||
// ┌─┐ | ||
// │ │ | ||
// └─┘ | ||
|
||
// ♥ | ||
// ♦ | ||
// ♣ | ||
// ♠ | ||
// ♠ | ||
|
||
// ┌Q♠───┐ | ||
// │ │ | ||
// │ │ | ||
// │ │ | ||
// └───♥Q┘ | ||
|
||
// ┌♥1───┐ | ||
// ┌♥2───┐ | ||
// ┌♥3───┐ | ||
// ┌♥4───┐ | ||
// ┌♥5───┐ | ||
// ┌♥6───┐ | ||
// │ │ | ||
// │ ♥ │ | ||
// │ │ | ||
// └───♥6┘ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
39fd616edf72e83c9f67e219cfe69cfabee9df2b71f07218606a50410c727c10 | ||
f1b3e84d22961790211c12ea18b561b97fd7726d0033f39a47caa8fb9fa566a2 |
4 changes: 4 additions & 0 deletions
4
obj/Debug/net8.0/Cards.GeneratedMSBuildEditorConfig.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.