Skip to content
Snippets Groups Projects
Commit 8a99bfe2 authored by bionic85's avatar bionic85
Browse files

smol update

parent 84fbc29f
No related branches found
No related tags found
No related merge requests found
......@@ -21,9 +21,16 @@ namespace PuzzlePlayer_Namespace
struct Card
{
string name; // for drawing the card, needs to be in format num_of_kind
int value; // value of the card
int value2; // some cards have two values
public string name; // for drawing the card, needs to be in format num_of_kind
public int value; // value of the card
public int value2; // some cards have two values
public Card(string n, int val, int val2)
{
name = n;
value = val;
value2 = val2;
}
}
internal class BlackJack : Form
......@@ -40,12 +47,12 @@ namespace PuzzlePlayer_Namespace
Panel GamePanel;
Panel ResultPanel;
List<Card> cards;
List<Card> cardsLeft;
List<Card> playerCards;
List<(Card,bool)> dealerCards; // boolean is to keep track if the card is shown
(int,string,Color)[] chipInfo = { (5,"5",Color.Gray), (25, "25", Color.Blue), (50, "50", Color.Green), (100, "100", Color.DarkCyan), (500, "500", Color.Purple), (1000, "1K", Color.Red), (5000, "5K", Color.Orange), (10000, "10K", Color.Gold) };
public object Int { get; private set; }
public BlackJack()
{
state = BJSTATE.Setup;
......@@ -54,10 +61,39 @@ namespace PuzzlePlayer_Namespace
Paint += BlackJack_Paint;
money = ReadMoney();
cardsLeft = getAllCards();
SetupUI();
}
List<Card> getAllCards()
{
List<Card> cards = new List<Card>();
string[] numbers = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "ace", "jack", "king", "queen" };
string[] kinds = { "clubs", "diamonds", "hearths", "spades" };
foreach (string kind in kinds)
{
foreach (string num in numbers)
{
int val, val2 = 0;
if (num == "jack" || num == "king" || num == "queen")
val = 10;
else if (num == "ace") // if it is an ace the player can chose between 1 or 11
{
val = 11;
val2 = 1;
}
else
val = int.Parse(num);
cards.Add(new Card(num + "_of_" + kind,val,val2));
}
}
cards.Shuffle();
return cards;
}
private int ReadMoney() //TODO read money from local file
{
return 1000;
......@@ -102,14 +138,7 @@ namespace PuzzlePlayer_Namespace
dealButton.Location = new Point(SetupPanel.Width /2 - dealButton.Width/2, SetupPanel.Height /4);
dealButton.Font = new Font(BJFont, dealButton.Size.Width / 5);
dealButton.BackColor = Color.DodgerBlue;
dealButton.Click += (object o, EventArgs e) =>
{
if (deployedMoney == 0)
return;
SetupPanel.Hide();
GamePanel.Show();
state = BJSTATE.Game;
};
dealButton.Click += dealButtonClick;
SetupPanel.Controls.Add(dealButton);
Controls.Add(SetupPanel);
......@@ -137,8 +166,6 @@ namespace PuzzlePlayer_Namespace
#endregion
}
private void moneyButtonClick(object sender, EventArgs e)
{
Button b = (Button) sender;
......@@ -152,6 +179,21 @@ namespace PuzzlePlayer_Namespace
Invalidate(true);
}
private void dealButtonClick(object sender, EventArgs e)
{
if (deployedMoney == 0)
return;
SetupPanel.Hide();
playerCards.Add((Card)PopCard()); // give both dealer and player cards
dealerCards.Add(((Card)PopCard(), false)); //hided card
playerCards.Add((Card)PopCard());
dealerCards.Add(((Card)PopCard(), true));
GamePanel.Show();
state = BJSTATE.Game;
}
private void BlackJack_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
......@@ -190,7 +232,19 @@ namespace PuzzlePlayer_Namespace
private void Game_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
DrawCard(g, new Point(0, 0), 200, "9_of_spades");
for(int i = 0; i < playerCards.Count; i++)
{
int ba = 200;
Point p = new Point(i*200);
DrawCard(g, p, 200, playerCards[i].name);
}
foreach(Card c in playerCards)
{
Point p = new Point();
DrawCard(g, p, 200, c.name);
}
}
private void Result_Paint(Graphics g)
......@@ -228,5 +282,14 @@ namespace PuzzlePlayer_Namespace
Image img = SettingForm.GetEmbeddedImage("BlackJack.cards." + cardName + ".png");
g.DrawImage(img, pos.X, pos.Y, width, (float)(width * 1.4)); //img is 500x726
}
private Card? PopCard()
{
if (cardsLeft.Count == 0)
return null;
Card c = cardsLeft[cardsLeft.Count - 1];
cardsLeft.RemoveAt(cardsLeft.Count - 1);
return c;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment