Skip to content
Snippets Groups Projects
Commit 5879e4a9 authored by bionic85's avatar bionic85
Browse files

Started with BlackJack

parent e98a49f6
No related branches found
No related tags found
No related merge requests found
Showing
with 139 additions and 7 deletions
......@@ -8,25 +8,157 @@ using System.Windows.Forms;
namespace PuzzlePlayer_Namespace
{
enum BJSTATE // the different states the game can be in
{
Setup, // choose how much money the player deploys
Game, // play the game
Result, // see te result and then restart
}
internal class BlackJack : Form
{
BJSTATE state;
int money = 1000;
int deploydMoney = 0;
const string DIR = @"..\..\..\Resources\BlackJack\";
FontFamily BJFont = FontFamily.GenericSansSerif;
Size screen = Screen.PrimaryScreen.WorkingArea.Size;
Panel DefaultPanel; // always visible
Panel SetupPanel; // visibility depends on game state
Panel GamePanel;
Panel ResultPanel;
(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;
WindowState = FormWindowState.Maximized;
BackColor = Color.DarkGreen;
Paint += BlackJack_Paint;
Size = new Size(500, 400);
SetupUI();
}
private void SetupUI()
{
//Default
DefaultPanel = new Panel();
DefaultPanel.Size = new Size(screen.Width/2,screen.Height);
DefaultPanel.Location = new Point(screen.Width / 4, 0);
//DefaultPanel.BackColor = Color.Blue; //DEBUG
int goofyIndex = 0; //dw
for(int j = 1; j <= 2; j++)
for(int i = 0; i < 4; i++)
{
Button b = new Button();
b.Size = new Size(DefaultPanel.Width / 4, DefaultPanel.Height / 5);
b.Location = new Point(i * b.Size.Width, DefaultPanel.Height - b.Size.Height*j);
b.Name = goofyIndex.ToString(); // for getting the index for chipInfo later
(int, string, Color) chip = chipInfo[goofyIndex];
b.Text = chip.Item2;
b.BackColor = chip.Item3;
b.Font = new Font(BJFont, b.Size.Width / 5);
b.Click += moneyButtonClick;
DefaultPanel.Controls.Add(b);
goofyIndex++;
}
Controls.Add(DefaultPanel);
//Setup
SetupPanel = new Panel();
//Game
GamePanel = new Panel();
//Result
ResultPanel = new Panel();
}
private void moneyButtonClick(object sender, EventArgs e)
{
Button b = (Button) sender;
(int, string, Color) chip = chipInfo[int.Parse(b.Name)];
if(money > chip.Item1)
{
//bababababa
}
}
private void BlackJack_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
private void BlackJack_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
string s = "CRAZY BLACKJACK READY TO GO GAMBLING??";
Point p = new Point(0,0);
Image img = Image.FromFile("../../..//Resources/bj.jpg");
//default draw
Font moneyFont = new Font(BJFont, screen.Width/50, FontStyle.Bold);
g.DrawString("Money: " + money.ToString(), moneyFont, Brushes.Black, new PointF(0,0));
g.DrawImage(img,new Point(0,0));
switch(state) // paint according to the current state
{
case BJSTATE.Setup:
Setup_Paint(g);
break;
case BJSTATE.Game:
Game_Paint(g);
break;
case BJSTATE.Result:
Result_Paint(g);
break;
}
}
private void Setup_Paint(Graphics g)
{
}
private void Game_Paint(Graphics g)
{
}
private void Result_Paint(Graphics g)
{
g.DrawString(s, SettingForm.mainFont, Brushes.Red, p);
}
private void DrawChip(Graphics g, Color c, int r, Point pos, string value)
{
// Chip
Brush brush = new SolidBrush(c);
g.FillEllipse(brush, pos.X - r, pos.Y - r, r * 2, r * 2);
// White Squares
int squareSize = r / 2;
Rectangle rect = new Rectangle(pos.X - squareSize/2, pos.Y - r, squareSize, squareSize);
g.FillRectangle(Brushes.White, rect);
rect.Offset(new Point(0, r*2-squareSize));
g.FillRectangle(Brushes.White, rect);
rect = new Rectangle(pos.X - r, pos.Y - squareSize/2, squareSize, squareSize);
g.FillRectangle(Brushes.White, rect);
rect.Offset(new Point(r * 2 - squareSize, 0));
g.FillRectangle(Brushes.White, rect);
//text
Font f = new Font(BJFont, r/2);
SizeF fontSize = g.MeasureString(value.ToString(), f);
g.DrawString(value.ToString(), f, Brushes.Black, new PointF(pos.X-fontSize.Width/2, pos.Y-fontSize.Height/2));
}
private void DrawCard(Graphics g, Point pos, int width, string cardName) //cardName needs to be in format: num_of_kind
{
Image img = Image.FromFile(DIR + "cards/" + cardName + ".png"); //img is 500x726
g.DrawImage(img, pos.X,pos.Y,width, (float)(width*1.4));
}
}
}
PuzzlePlayer/Resources/BlackJack/cards/10_of_clubs.png

53.4 KiB

PuzzlePlayer/Resources/BlackJack/cards/10_of_diamonds.png

45.2 KiB

PuzzlePlayer/Resources/BlackJack/cards/10_of_hearts.png

45.2 KiB

PuzzlePlayer/Resources/BlackJack/cards/10_of_spades.png

49.3 KiB

PuzzlePlayer/Resources/BlackJack/cards/2_of_clubs.png

23 KiB

PuzzlePlayer/Resources/BlackJack/cards/2_of_diamonds.png

19.4 KiB

PuzzlePlayer/Resources/BlackJack/cards/2_of_hearts.png

19.7 KiB

PuzzlePlayer/Resources/BlackJack/cards/2_of_spades.png

21.4 KiB

PuzzlePlayer/Resources/BlackJack/cards/3_of_clubs.png

28.5 KiB

PuzzlePlayer/Resources/BlackJack/cards/3_of_diamonds.png

23.7 KiB

PuzzlePlayer/Resources/BlackJack/cards/3_of_hearts.png

24.2 KiB

PuzzlePlayer/Resources/BlackJack/cards/3_of_spades.png

26.3 KiB

PuzzlePlayer/Resources/BlackJack/cards/4_of_clubs.png

28 KiB

PuzzlePlayer/Resources/BlackJack/cards/4_of_diamonds.png

23.6 KiB

PuzzlePlayer/Resources/BlackJack/cards/4_of_hearts.png

24.1 KiB

PuzzlePlayer/Resources/BlackJack/cards/4_of_spades.png

25.8 KiB

PuzzlePlayer/Resources/BlackJack/cards/5_of_clubs.png

34 KiB

PuzzlePlayer/Resources/BlackJack/cards/5_of_diamonds.png

28.6 KiB

PuzzlePlayer/Resources/BlackJack/cards/5_of_hearts.png

29.1 KiB

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