This commit is contained in:
2022-07-05 23:23:57 +10:00
commit 52ad5893a1
31 changed files with 538 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
<Properties StartupConfiguration="{FD2FB25C-F802-4614-8B99-DF92BF48F6DC}|Default">
<MultiItemStartupConfigurations />
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
<MonoDevelop.Ide.Workbench ActiveDocument="StripJackNaked/Program.cs">
<Files>
<File FileName="StripJackNaked/Program.cs" Line="66" Column="1" />
<File FileName="Cards.cs" Line="69" Column="14" />
</Files>
<Pads>
<Pad Id="ProjectPad">
<State name="__root__">
<Node name="StripJackNaked" expanded="True" selected="True">
<Node name="StripJackNaked" expanded="True" />
</Node>
</State>
</Pad>
<Pad Id="MonoDevelop.Debugger.WatchPad">
<State>
<Value>CardsToDraw</Value>
</State>
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
<MonoDevelop.Ide.ItemProperties.StripJackNaked PreferredExecutionTarget="MonoDevelop.Default" />
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
<AuthorInfo Name="Ashley Strahle" Email="a.strahle@me.com" Copyright="" Company="" Trademark="" />
<Debugger.DebugSourceFolders />
</Properties>

File diff suppressed because one or more lines are too long

33
StripJackNaked.sln Normal file
View File

@@ -0,0 +1,33 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1700.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StripJackNaked", "StripJackNaked\StripJackNaked.csproj", "{FD2FB25C-F802-4614-8B99-DF92BF48F6DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{FD2FB25C-F802-4614-8B99-DF92BF48F6DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD2FB25C-F802-4614-8B99-DF92BF48F6DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD2FB25C-F802-4614-8B99-DF92BF48F6DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD2FB25C-F802-4614-8B99-DF92BF48F6DC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9E0515AF-3796-4890-BB01-DC912AF34101}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
$0.TextStylePolicy = $1
$1.inheritsSet = null
$1.scope = text/x-csharp
$0.CSharpFormattingPolicy = $2
$2.scope = text/x-csharp
EndGlobalSection
EndGlobal

100
StripJackNaked/Cards.cs Normal file
View File

@@ -0,0 +1,100 @@
namespace Cards
{
public enum Suit
{
Spades,
Clubs,
Diamonds,
Hearts
}
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 class Deck
{
public static List<Card> Cards = new();
public static void Enumerate()
{
foreach (Suit suit in Enum.GetValues(typeof(Suit)))
{
// Add number cards
for (int i = 2; i <= 10; i++)
{
Cards.Add(new Card()
{
Value = i.ToString(),
Suit = suit
});
}
// Add picture cards
foreach (PictureCard pictureCard in Enum.GetValues(typeof(PictureCard)))
{
Cards.Add(new Card()
{
Value = Enum.GetName(pictureCard),
Suit = suit
});
}
}
}
private static Random rng = new();
public static void Shuffle()
{
Cards = Cards.OrderBy(a => rng.Next()).ToList();
}
}
public class Actions
{
public static Boolean MoveCard(List<Card> From, List<Card> To, Card card = null)
{
if (From.Count() == 0)
{
return false; // No cards available to move
}
if (card is null)
card = From.FirstOrDefault();
if (From.Contains(card) && !To.Contains(card))
{
To.Add(card);
From.Remove(card);
return true;
}
return false;
}
}
}

119
StripJackNaked/Program.cs Normal file
View File

@@ -0,0 +1,119 @@
using Cards;
namespace StripJackNaked
{
static class Constants
{
public const int PlayerCount = 2;
}
public class Kitty
{
public static List<Card> Pile = new();
}
public class Player
{
public List<Card> Hand = new();
}
class Program
{
public static int NextPlayer(int CurrentPlayer)
{
return ++CurrentPlayer % Constants.PlayerCount;
}
public static Boolean PlayCard(List<Card> From)
{
return Actions.MoveCard(From, Kitty.Pile);
}
public static void TakePile(List<Card>Winner)
{
while (Kitty.Pile.Count() > 0)
{
Actions.MoveCard(Kitty.Pile, Winner);
}
}
public static void ShowList(List<Card>Cards)
{
foreach (Card card in Cards)
Console.Write(card.NamedValue + ((card == Cards.LastOrDefault()) ? "" : ", "));
Console.WriteLine();
}
static void Main()
{
// Init players
List<Player> Players = new();
for (int i = 0; i < Constants.PlayerCount; i++)
Players.Add(new Player());
// Init deck
Deck.Enumerate();
Deck.Shuffle();
// Deal cards
while (Deck.Cards.Count > 0)
{
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);
}
// Init first round
int CardsToDraw = 1;
Card ActivePictureCard = null;
int ActivePlayer = 0; // Player 0 goes first
// Let's play
while (PlayCard(Players[ActivePlayer].Hand))
{
Card LastCard = Kitty.Pile.LastOrDefault();
if (LastCard.IsPicture)
{
// Active player just played a picture card, next player's turn
ActivePictureCard = LastCard;
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--;
if (CardsToDraw < 1)
{
// Active player lost round
TakePile(Players[NextPlayer(ActivePlayer)].Hand);
// Init next round
CardsToDraw = 1;
ActivePictureCard = null;
}
if (ActivePictureCard is null)
ActivePlayer = NextPlayer(ActivePlayer);
// Show some output
Console.WriteLine("Player 0: ");
ShowList(Players[0].Hand);
Console.WriteLine("Player 1: ");
ShowList(Players[1].Hand);
Console.WriteLine("Kitty");
ShowList(Kitty.Pile);
Console.WriteLine("---------------------");
}
Console.WriteLine("Player " + NextPlayer(ActivePlayer) + " Won!");
}
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

Binary file not shown.

View File

@@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"StripJackNaked/1.0.0": {
"runtime": {
"StripJackNaked.dll": {}
}
}
}
},
"libraries": {
"StripJackNaked/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]

View File

@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StripJackNaked")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("StripJackNaked")]
[assembly: System.Reflection.AssemblyTitleAttribute("StripJackNaked")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@@ -0,0 +1 @@
07f8689e59fb487ab70b3db1baeb91278805a416

View File

@@ -0,0 +1,10 @@
is_global = true
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = StripJackNaked
build_property.ProjectDir = /Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/

View File

@@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;

View File

@@ -0,0 +1 @@
17e3524757ed4f9d2b86f81a1cc1bb6992bfc091

View File

@@ -0,0 +1,15 @@
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/bin/Debug/net6.0/StripJackNaked
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/bin/Debug/net6.0/StripJackNaked.deps.json
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/bin/Debug/net6.0/StripJackNaked.runtimeconfig.json
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/bin/Debug/net6.0/StripJackNaked.dll
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/bin/Debug/net6.0/StripJackNaked.pdb
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/StripJackNaked.csproj.AssemblyReference.cache
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/StripJackNaked.GeneratedMSBuildEditorConfig.editorconfig
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/StripJackNaked.AssemblyInfoInputs.cache
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/StripJackNaked.AssemblyInfo.cs
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/StripJackNaked.csproj.CoreCompileInputs.cache
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/StripJackNaked.dll
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/refint/StripJackNaked.dll
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/StripJackNaked.pdb
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/StripJackNaked.genruntimeconfig.cache
/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/Debug/net6.0/ref/StripJackNaked.dll

Binary file not shown.

View File

@@ -0,0 +1 @@
342e622614f7201ca107c643ff66003d2e669c6e

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,60 @@
{
"format": 1,
"restore": {
"/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/StripJackNaked.csproj": {}
},
"projects": {
"/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/StripJackNaked.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/StripJackNaked.csproj",
"projectName": "StripJackNaked",
"projectPath": "/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/StripJackNaked.csproj",
"packagesPath": "/Users/ashleystrahle/.nuget/packages/",
"outputPath": "/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/Users/ashleystrahle/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/6.0.301/RuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/Users/ashleystrahle/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/Users/ashleystrahle/.nuget/packages/</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.0.0</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="/Users/ashleystrahle/.nuget/packages/" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@@ -0,0 +1,65 @@
{
"version": 3,
"targets": {
"net6.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net6.0": []
},
"packageFolders": {
"/Users/ashleystrahle/.nuget/packages/": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/StripJackNaked.csproj",
"projectName": "StripJackNaked",
"projectPath": "/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/StripJackNaked.csproj",
"packagesPath": "/Users/ashleystrahle/.nuget/packages/",
"outputPath": "/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/obj/",
"projectStyle": "PackageReference",
"configFilePaths": [
"/Users/ashleystrahle/.nuget/NuGet/NuGet.Config"
],
"originalTargetFrameworks": [
"net6.0"
],
"sources": {
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "/usr/local/share/dotnet/sdk/6.0.301/RuntimeIdentifierGraph.json"
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"version": 2,
"dgSpecHash": "Z1xYMGFBYg5WMmIwuVNCMmG6DVOiZVahwmnAeTkKqd21QO1lbmsQ7wszb8P1Cf+dCbPDif/UV0mTJU4E4dgPEQ==",
"success": true,
"projectFilePath": "/Users/ashleystrahle/Projects/StripJackNaked/StripJackNaked/StripJackNaked.csproj",
"expectedPackageFiles": [],
"logs": []
}