Add project files.

This commit is contained in:
eritib08
2025-09-16 10:20:05 +02:00
parent 42e8b1fddf
commit 52576e3416
12 changed files with 640 additions and 0 deletions

6
BlackJ/App.config Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

47
BlackJ/Art.cs Normal file
View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using BlackJack;
namespace BlackJack
{
public class Art
{
private Dictionary<string, string[]> artCollection = new Dictionary<string, string[]>()
{
{ "boat", new string[]
{
" .",
" ___ | _:______",
" : _`&_'&___| [] [] [] |_&______",
" | o o o o o o o o /",
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
}
},
};
public void Print(string name)
{
if (artCollection.TryGetValue(name.ToLower(), out string[] artLines))
{
foreach (var line in artLines)
{
Console.WriteLine(line);
}
}
else
{
Console.WriteLine($"No art found for '{name}'");
}
}
public string[] GetArt(string name)
{
if (artCollection.TryGetValue(name.ToLower(), out string[] artLines))
{
return artLines;
}
else
{
return null;
}
}
}
}

60
BlackJ/BlackJack.csproj Normal file
View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{10631FE8-36EE-4692-BEF8-26F9A0D01D59}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>BlackJ</RootNamespace>
<AssemblyName>BlackJ</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Art.cs" />
<Compile Include="Card.cs" />
<Compile Include="Shop.cs" />
<Compile Include="Dealer.cs" />
<Compile Include="Deck.cs" />
<Compile Include="Game.cs" />
<Compile Include="Player.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

34
BlackJ/Card.cs Normal file
View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BlackJack;
namespace BlackJack
{
public class Card
{
public Suits Suit;
public int Number;
public Card(Suits suit, int number)
{
Suit = suit;
if (number < 10)
{
Number = number;
}
else
{
Number = 10;
}
}
}
}

40
BlackJ/Dealer.cs Normal file
View File

@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BlackJack;
namespace BlackJack
{
public class Dealer
{
public List<Card> Hand = new List<Card>();
public void RemoveHand()
{
Hand = new List<Card>();
}
public int GetHandValue()
{
int total = 0;
int n = Hand.Count;
for (int i = 0; i < n; i++)
{
Card card = Hand[i];
int cardValue = card.Number;
total += cardValue;
}
return total;
}
public Card DrawCard(Deck deck)
{
Card card = deck.Cards[0];
Hand.Add(card);
deck.Cards.Remove(card);
return card;
}
}
}

63
BlackJ/Deck.cs Normal file
View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using BlackJack;
namespace BlackJack
{
public enum Suits
{
Diamonds,
Hearts,
Spade,
Clubs,
}
public class Deck
{
public List<Card> Cards = new List<Card>();
private readonly Random _rnd = new Random();
public Deck()
{
for (int i = 1; i <= 13; i++) {
foreach (Suits suit in Enum.GetValues(typeof(Suits)))
{
Card card = new Card(suit, i);
AddCard(card);
}
}
}
public void AddCard(Card card)
{
Cards.Add(card);
}
public void Shuffle()
{
int n = Cards.Count;
for (int i = 0; i < n; i++)
{
int j = _rnd.Next(0, n-1);
Card temp = Cards[i];
Cards[i] = Cards[j];
Cards[j] = temp;
}
}
public void PrintDeck()
{
for (int i = 0; i < Cards.Count; i++)
{
Card card = Cards[i];
Console.WriteLine(card.Suit.ToString() + " " + card.Number.ToString());
}
}
}
}

252
BlackJ/Game.cs Normal file
View File

@@ -0,0 +1,252 @@
using BlackJack;
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace BlackJack
{
public class Game
{
readonly Player player = new Player();
readonly Dealer dealer = new Dealer();
readonly Shop shop = new Shop();
readonly Art art = new Art();
void DisplayBalance()
{
Console.WriteLine("Balance: " + player.cash + "$");
Console.WriteLine("_____________________________");
Console.WriteLine();
}
public void Initialize()
{
Console.Clear();
Console.WriteLine("Welcome to BlackJack)");
Console.WriteLine("You start with " + player.cash + "$");
Console.WriteLine();
Console.WriteLine("'Enter' to continue");
Console.ReadLine();
Menu();
}
public void Menu()
{
Console.Clear();
DisplayBalance();
Console.WriteLine("> Enter round (1)");
Console.WriteLine("> Shop (2)");
Console.WriteLine("> Inventory (3)");
string input = Console.ReadLine();
if (input == "1")
{
NewRound();
}
else if (input == "2")
{
}
else if (input == "3")
{
}
else
{
Console.WriteLine("Invalid input. Press 'Enter' to try again");
Console.ReadLine();
Console.Clear();
Initialize();
}
}
public void NewRound()
{
Console.Clear();
if (player.cash <= 0)
{
Console.WriteLine("You went bankrupt!");
Environment.Exit(0);
}
Deck deck = new Deck();
player.RemoveHand();
dealer.RemoveHand();
double bet;
deck.Shuffle();
player.DrawCard(deck);
player.DrawCard(deck);
dealer.DrawCard(deck);
void Bet()
{
Console.WriteLine("You have " + player.cash + "$");
Console.WriteLine("How much do you want to bet?");
string input = Console.ReadLine();
if (double.TryParse(input, out bet))
{
if (bet <= player.cash && bet > 0)
{
player.cash -= bet;
}
else if (bet == 676767)
{
double cheat;
Console.WriteLine("Enter Cheat");
input = Console.ReadLine();
if (double.TryParse(input, out cheat))
{
player.cash += cheat;
}
Console.Clear();
Bet();
}
else
{
Console.WriteLine("Invalid amount. Press 'Enter' to try again");
Console.ReadLine();
Console.Clear();
Bet();
}
}
else
{
Console.WriteLine("Invalid amount. Press 'Enter' to try again");
Console.ReadLine();
Console.Clear();
Bet();
}
}
Bet();
Console.Clear();
void DisplayStats()
{
Console.WriteLine("Balance: " + player.cash + "$");
Console.WriteLine("Bet: " + bet + "$");
Console.WriteLine("_____________________________");
Console.WriteLine();
}
void PlayersTurn()
{
DisplayStats();
Console.WriteLine("Hand: " + player.GetHandValue());
Console.WriteLine();
Console.WriteLine("Dealer's first card: " + dealer.GetHandValue());
Console.WriteLine();
Console.WriteLine("Hit (h) or Stand (s)?");
string input = Console.ReadLine();
Console.Clear();
DisplayStats();
if (input == "h")
{
Card card = player.DrawCard(deck);
Console.WriteLine("You received " + card.Number + " " + card.Suit);
if (player.GetHandValue() > 21)
{
Bust();
}
Console.WriteLine("Press 'Enter' to continue.");
Console.ReadLine();
Console.Clear();
PlayersTurn();
}
else if (input == "s")
{
Console.WriteLine("You chose to stand.");
DealersTurn();
}
else
{
Console.WriteLine("Invalid input. Press 'Enter' to try again");
Console.ReadLine();
Console.Clear();
PlayersTurn();
}
}
PlayersTurn();
void InputNewRound()
{
Console.WriteLine();
Console.WriteLine("Press 'Enter' to enter menu.");
Console.ReadLine();
Menu();
}
void DealersTurn()
{
while (dealer.GetHandValue() < 17)
{
dealer.DrawCard(deck);
}
int playerHand = player.GetHandValue();
int dealerHand = dealer.GetHandValue();
if (playerHand > dealerHand || dealerHand > 21)
{
Console.WriteLine("You won.");
Console.WriteLine("Your hand: " + playerHand);
Console.WriteLine("Dealer's hand: " + dealerHand);
Console.WriteLine("+" + bet * 2 + "$");
player.cash += bet * 2;
InputNewRound();
}
else if (playerHand < dealerHand)
{
Console.WriteLine("You lost.");
Console.WriteLine("Your hand: " + playerHand);
Console.WriteLine("Dealer's hand: " + dealerHand);
InputNewRound();
}
else
{
Console.WriteLine("It's a tie!");
Console.WriteLine("Your hand: " + playerHand);
Console.WriteLine("Dealer's hand: " + dealerHand);
Console.WriteLine("+" + bet + "$");
player.cash += bet;
InputNewRound();
}
}
void Bust()
{
Console.WriteLine("You bust! Hand: " + player.GetHandValue());
InputNewRound();
}
}
}
}

45
BlackJ/Player.cs Normal file
View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BlackJack;
namespace BlackJack
{
public class Player
{
public double cash = 100;
public List<Card> Hand = new List<Card>();
public List<String[]> Inventory = new List<String[]>();
public void RemoveHand()
{
Hand = new List<Card>();
}
public int GetHandValue()
{
int total = 0;
int n = Hand.Count;
for(int i = 0; i < n; i++)
{
Card card = Hand[i];
int cardValue = card.Number;
total += cardValue;
}
return total;
}
public Card DrawCard(Deck deck)
{
Card card = deck.Cards[0];
Hand.Add(card);
deck.Cards.Remove(card);
return card;
}
}
}

18
BlackJ/Program.cs Normal file
View File

@@ -0,0 +1,18 @@
using BlackJack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlackJack
{
internal class Program
{
static void Main(string[] args)
{
Game game = new Game();
game.Initialize();
}
}
}

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BlackJ")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Gislaveds kommun")]
[assembly: AssemblyProduct("BlackJ")]
[assembly: AssemblyCopyright("Copyright © Gislaveds kommun 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("10631fe8-36ee-4692-bef8-26f9a0d01d59")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

17
BlackJ/Shop.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BlackJack;
namespace BlackJack
{
public class Shop
{
readonly Art art = new Art();
public Shop()
{
}
}
}

25
BlackJack.sln Normal file
View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36408.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlackJack", "BlackJ\BlackJack.csproj", "{10631FE8-36EE-4692-BEF8-26F9A0D01D59}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{10631FE8-36EE-4692-BEF8-26F9A0D01D59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10631FE8-36EE-4692-BEF8-26F9A0D01D59}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10631FE8-36EE-4692-BEF8-26F9A0D01D59}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10631FE8-36EE-4692-BEF8-26F9A0D01D59}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B58E74AA-816D-4A3F-8119-7B6CB941E4B5}
EndGlobalSection
EndGlobal