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

Merge branch 'BlackJack'

parents 7cbe6a01 c10cb020
No related branches found
No related tags found
No related merge requests found
Showing
with 187 additions and 8 deletions
using System;
using Microsoft.VisualBasic.Devices;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
......@@ -8,25 +9,203 @@ 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;
int deploydMoney = 0;
const string DIR = @"..\..\..\Resources\BlackJack\";
FontFamily BJFont = FontFamily.GenericSansSerif;
Size screen = Screen.PrimaryScreen.WorkingArea.Size;
// visibility depends on game state
Panel SetupPanel;
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);
money = ReadMoney();
SetupUI();
}
private int ReadMoney() //TODO read money from local file
{
return 1000;
}
private void BlackJack_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
private void SetupUI()
{
//Setup
#region SetupPanel
SetupPanel = new Panel();
SetupPanel.Size = new Size(screen.Width/2,screen.Height);// /4
SetupPanel.Location = new Point(screen.Width / 4, 0);
//DefaultPanel.BackColor = Color.Blue; //DEBUG
SetupPanel.Paint += DefaultPaint;
//money buttons
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(SetupPanel.Width / 4, SetupPanel.Height / 6); // /2
b.Location = new Point(i * b.Size.Width, SetupPanel.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;
SetupPanel.Controls.Add(b);
goofyIndex++;
}
// Deal button
Button dealButton = new Button();
dealButton.Text = "DEAL";
dealButton.Size = new Size(SetupPanel.Width/4, SetupPanel.Height / 6);
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 (deploydMoney == 0)
return;
SetupPanel.Hide();
GamePanel.Show();
state = BJSTATE.Game;
};
SetupPanel.Controls.Add(dealButton);
Controls.Add(SetupPanel);
#endregion
//Game
#region GamePanel
GamePanel = new Panel();
GamePanel.BackColor = Color.AliceBlue; //DEBUG
GamePanel.Hide(); //Hide until the game state is reached
Controls.Add(GamePanel);
#endregion
//Result
#region ResultPanel
ResultPanel = new Panel();
ResultPanel.Hide(); //Hide until the result state is reached
Controls.Add(ResultPanel);
#endregion
}
private void moneyButtonClick(object sender, EventArgs e)
{
Button b = (Button) sender;
(int, string, Color) chip = chipInfo[int.Parse(b.Name)];
if(money >= chip.Item1)
{
deploydMoney += chip.Item1;
money -= chip.Item1;
}
Invalidate(true);
}
private void BlackJack_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
//default draw
Font moneyFont = new Font(BJFont, screen.Width/50, FontStyle.Bold);
g.DrawString("Money: " + money.ToString(), moneyFont, Brushes.Black, new PointF(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 DefaultPaint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
string s = "CRAZY BLACKJACK READY TO GO GAMBLING??";
Point p = new Point(0,0);
// draw deployd money
// Might update this to butiful chipss
string s = "Deployd Money: " + deploydMoney.ToString();
Font deplMoneyFont = new Font(BJFont, SetupPanel.Width / 20, FontStyle.Bold);
SizeF pf = g.MeasureString(s, deplMoneyFont);
PointF p = new PointF(SetupPanel.Width / 2 - pf.Width / 2, SetupPanel.Height / 2);
g.DrawString(s, deplMoneyFont, Brushes.Black, p);
}
private void Game_Paint(Graphics g)
{
Image img = Image.FromFile("../../..//Resources/bj.jpg");
}
private void Result_Paint(Graphics g)
{
}
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);
g.DrawImage(img,new Point(0,0));
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);
g.DrawString(s, SettingForm.mainFont, Brushes.Red, p);
//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