private void btnPesca_Click(object sender, EventArgs e) { Carta carta = mazzo.PescaCarta(); ManoGiocatore.Add(carta); Label lblcarta = new Label(); lblcarta.Location = new Point((ManoLabelsGiocatore[ManoLabelsGiocatore.Count - 1].Location.X + 78), 250); string nomeimg = "../" + carta.ToString() + ".bmp"; Image imgcarta = Image.FromFile(nomeimg); lblcarta.Size = new Size(imgcarta.Width, imgcarta.Height); lblcarta.Image = imgcarta; ManoLabelsGiocatore.Add(lblcarta); TotaleGiocatore += carta.CalcolaValoreCarta(); if (TotaleGiocatore > 21) { int TotConAsso1 = 0; int piudiunasso = 0; foreach (Carta c in ManoGiocatore) { if (c.CalcolaValoreCarta() == 11) { TotConAsso1 += 1; } } if (TotConAsso1 > 1) { piudiunasso = 1; } foreach (Carta c in ManoGiocatore) { if (c.CalcolaValoreCarta() != 11) { TotConAsso1 += c.CalcolaValoreCarta(); } } if (TotConAsso1 <= 11 && piudiunasso == 1) { TotConAsso1 += 10; } TotaleGiocatore = TotConAsso1; } lblGiocatore.Text = "GIOCATORE: " + TotaleGiocatore; lblImgMazzo.Text = "" + mazzo.NumeroCarteMazzo(); this.Controls.Add(lblcarta); if (TotaleGiocatore > 21) { DateEnd = new DateTime(); DateEnd = DateTime.Now; vincitore = "dealer"; Label lblSconfittaGiocatore = new Label(); lblSconfittaGiocatore.Location = new Point(130, 164); lblSconfittaGiocatore.Font = new Font(lblSconfittaGiocatore.Font.FontFamily, 26); lblSconfittaGiocatore.BackColor = Color.Transparent; lblSconfittaGiocatore.ForeColor = Color.White; lblSconfittaGiocatore.Name = "lblSconfittaGiocatore"; lblSconfittaGiocatore.Text = "Il Dealer Ha vinto!"; lblSconfittaGiocatore.AutoSize = true; lblSconfittaGiocatore.Visible = true; btnGiocaAgain = new Button(); btnGiocaAgain.Location = new Point(12, 370); btnGiocaAgain.AutoSize = true; btnGiocaAgain.Width = 197; btnGiocaAgain.Font = new Font(btnGiocaAgain.Font.FontFamily, 20); btnGiocaAgain.Text = "Nuova Partita"; btnGiocaAgain.Name = "btnGiocaAgain"; btnGiocaAgain.BackColor = Color.White; btnGiocaAgain.Click += new EventHandler(this.btnGiocaAgain_Click); btnTornaMenu = new Button(); btnTornaMenu.Location = new Point(525, 370); btnTornaMenu.AutoSize = true; btnTornaMenu.Font = new Font(btnTornaMenu.Font.FontFamily, 20); btnTornaMenu.Text = "Torna al Menù"; btnTornaMenu.Name = "btnTornaMenu"; btnTornaMenu.BackColor = Color.White; btnTornaMenu.Click += new EventHandler(this.Form1_Load); this.Controls.Remove(btnPesca); this.Controls.Remove(btnMantieni); this.Controls.Remove(btnRaddoppia); this.Controls.Add(lblSconfittaGiocatore); this.Controls.Add(btnTornaMenu); this.Controls.Add(btnGiocaAgain); SaveXml(); MessageBox.Show("Peccato! Hai perso " + puntata, "Sconfitta", MessageBoxButtons.OK, MessageBoxIcon.Information); lblSoldi.Text = "Soldi disponibili: " + soldi; } else if (TotaleGiocatore == 21) { btnMantieni.PerformClick(); this.Controls.Remove(btnPesca); this.Controls.Remove(btnMantieni); this.Controls.Remove(btnRaddoppia); } }
private void btnMantieni_Click(object sender, EventArgs e) { this.Controls.Remove(lblCartaCoperta); ManoLabelsDealer.Remove(lblCartaCoperta); Label lblCartaScoperta = new Label(); lblCartaScoperta.Location = new Point((ManoLabelsDealer[ManoLabelsDealer.Count - 1].Location.X + 78), 33); string nomeimgscoperta = "../" + ManoDealer[ManoDealer.Count - 1].ToString() + ".bmp"; Image imgcartascoperta = Image.FromFile(nomeimgscoperta); lblCartaScoperta.Size = new Size(imgcartascoperta.Width, imgcartascoperta.Height); lblCartaScoperta.Image = imgcartascoperta; int valCartaScoperta = ManoDealer[ManoDealer.Count - 1].CalcolaValoreCarta(); int valCarta3 = ManoDealer[0].CalcolaValoreCarta(); if (valCartaScoperta == 11 && valCarta3 == 11) { valCartaScoperta = 1; } ManoLabelsDealer.Add(lblCartaScoperta); TotaleDealer = valCartaScoperta + valCarta3; lblDealer.Text = "DEALER: " + TotaleDealer; this.Controls.Add(lblCartaScoperta); while (TotaleDealer <= 16 && TotaleDealer <= TotaleGiocatore) { Carta carta = mazzo.PescaCarta(); ManoDealer.Add(carta); Label lblcarta = new Label(); lblcarta.Location = new Point((ManoLabelsDealer[ManoLabelsDealer.Count - 1].Location.X + 78), 33); string nomeimg = "../" + carta.ToString() + ".bmp"; Image imgcarta = Image.FromFile(nomeimg); lblcarta.Size = new Size(imgcarta.Width, imgcarta.Height); lblcarta.Image = imgcarta; ManoLabelsDealer.Add(lblcarta); TotaleDealer += carta.CalcolaValoreCarta(); if (TotaleDealer > 21) { int TotConAsso1 = 0; int piudiunasso = 0; foreach (Carta c in ManoDealer) { if (c.CalcolaValoreCarta() == 11) { TotConAsso1 += 1; } } if (TotConAsso1 > 1) { piudiunasso = 1; } foreach (Carta c in ManoDealer) { if (c.CalcolaValoreCarta() != 11) { TotConAsso1 += c.CalcolaValoreCarta(); } } if (TotConAsso1 <= 11 && piudiunasso == 1) { TotConAsso1 += 10; } TotaleDealer = TotConAsso1; } lblDealer.Text = "DEALER: " + TotaleDealer; lblImgMazzo.Text = "" + mazzo.NumeroCarteMazzo(); this.Controls.Add(lblcarta); } if (TotaleDealer < TotaleGiocatore || TotaleDealer > 21) { DateEnd = new DateTime(); DateEnd = DateTime.Now; vincitore = "player"; soldi += puntata * 2; Label lblSconfittaDealer = new Label(); lblSconfittaDealer.Location = new Point(130, 164); lblSconfittaDealer.Font = new Font(lblSconfittaDealer.Font.FontFamily, 26); lblSconfittaDealer.BackColor = Color.Transparent; lblSconfittaDealer.ForeColor = Color.White; lblSconfittaDealer.Name = "lblSconfittaDealer"; lblSconfittaDealer.Text = "Il Giocatore Ha vinto!"; lblSconfittaDealer.AutoSize = true; lblSconfittaDealer.Visible = true; this.Controls.Add(lblSconfittaDealer); MessageBox.Show("Complimenti! Hai vinto " + puntata * 2, "Vittoria", MessageBoxButtons.OK, MessageBoxIcon.Information); lblSoldi.Text = "Soldi disponibili: " + soldi; } else if (TotaleGiocatore == TotaleDealer) { DateEnd = new DateTime(); DateEnd = DateTime.Now; vincitore = "tie"; soldi += puntata; Label lblPareggio = new Label(); lblPareggio.Location = new Point(130, 164); lblPareggio.Font = new Font(lblPareggio.Font.FontFamily, 26); lblPareggio.BackColor = Color.Transparent; lblPareggio.ForeColor = Color.White; lblPareggio.Name = "lblPareggio"; lblPareggio.Text = "Pareggio!"; lblPareggio.AutoSize = true; lblPareggio.Visible = true; this.Controls.Add(lblPareggio); } else { DateEnd = new DateTime(); DateEnd = DateTime.Now; vincitore = "dealer"; Label lblSconfittaGiocatore = new Label(); lblSconfittaGiocatore.Location = new Point(130, 164); lblSconfittaGiocatore.Font = new Font(lblSconfittaGiocatore.Font.FontFamily, 26); lblSconfittaGiocatore.BackColor = Color.Transparent; lblSconfittaGiocatore.ForeColor = Color.White; lblSconfittaGiocatore.Name = "lblSconfittaGiocatore"; lblSconfittaGiocatore.Text = "Il Dealer Ha vinto!"; lblSconfittaGiocatore.AutoSize = true; lblSconfittaGiocatore.Visible = true; this.Controls.Add(lblSconfittaGiocatore); MessageBox.Show("Peccato! Hai perso " + puntata, "Sconfitta", MessageBoxButtons.OK, MessageBoxIcon.Information); lblSoldi.Text = "Soldi disponibili: " + soldi; } SaveXml(); btnGiocaAgain = new Button(); btnGiocaAgain.Location = new Point(12, 370); btnGiocaAgain.AutoSize = true; btnGiocaAgain.Width = 197; btnGiocaAgain.Font = new Font(btnGiocaAgain.Font.FontFamily, 20); btnGiocaAgain.Text = "Nuova Partita"; btnGiocaAgain.Name = "btnGiocaAgain"; btnGiocaAgain.BackColor = Color.White; btnGiocaAgain.Click += new EventHandler(this.btnGiocaAgain_Click); btnTornaMenu = new Button(); btnTornaMenu.Location = new Point(525, 370); btnTornaMenu.AutoSize = true; btnTornaMenu.Font = new Font(btnTornaMenu.Font.FontFamily, 20); btnTornaMenu.Text = "Torna al Menù"; btnTornaMenu.Name = "btnTornaMenu"; btnTornaMenu.BackColor = Color.White; btnTornaMenu.Click += new EventHandler(this.Form1_Load); this.Controls.Remove(btnPesca); this.Controls.Remove(btnMantieni); this.Controls.Remove(btnRaddoppia); this.Controls.Add(btnTornaMenu); this.Controls.Add(btnGiocaAgain); }
private void btnGioca_Click(object sender, EventArgs e) { DateStart = new DateTime(); DateStart = DateTime.Now; this.Controls.Clear(); this.BackgroundImage = null; this.BackColor = Color.ForestGreen; lblSoldi.Location = new Point(545, 13); lblSoldi.Font = new Font(lblBlackJack.Font.FontFamily, 14); Label lblVincitaMax = new Label(); lblVincitaMax.Location = new Point(545, 43); lblVincitaMax.Font = new Font(lblVincitaMax.Font.FontFamily, 14); lblVincitaMax.AutoSize = true; lblVincitaMax.BackColor = Color.Transparent; lblVincitaMax.ForeColor = Color.White; lblVincitaMax.Text = "Vincita potenziale: " + puntata * 2; ViewPuntata = new Button(); ViewPuntata.Image = Image.FromFile("../fish.bmp"); ViewPuntata.AutoSize = true; ViewPuntata.Location = new Point(55, 140); ViewPuntata.ForeColor = Color.White; ViewPuntata.Font = new Font(ViewPuntata.Font.FontFamily, 18); ViewPuntata.Text = "" + puntata; System.Drawing.Drawing2D.GraphicsPath myGraphicsPathPuntata = new System.Drawing.Drawing2D.GraphicsPath(); myGraphicsPathPuntata.AddEllipse(5, 5, 70, 70); ViewPuntata.Region = new Region(myGraphicsPathPuntata); ManoGiocatore = new List <Carta>(); ManoDealer = new List <Carta>(); ManoLabelsGiocatore = new List <Label>(); ManoLabelsDealer = new List <Label>(); mazzo = new Mazzo(); mazzo.MescolaMazzo(); Carta carta1 = mazzo.PescaCarta(); Carta carta2 = mazzo.PescaCarta(); ManoGiocatore.Add(carta1); ManoGiocatore.Add(carta2); Label lblcarta1 = new Label(); lblcarta1.Location = new Point(12, 250); string nomeimg = "../" + carta1.ToString() + ".bmp"; Image imgcarta1 = Image.FromFile(nomeimg); lblcarta1.Size = new Size(imgcarta1.Width, imgcarta1.Height); lblcarta1.Image = imgcarta1; Label lblcarta2 = new Label(); lblcarta2.Location = new Point(90, 250); string nomeimg2 = "../" + carta2.ToString() + ".bmp"; Image imgcarta2 = Image.FromFile(nomeimg2); lblcarta2.Size = new Size(imgcarta2.Width, imgcarta2.Height); lblcarta2.Image = imgcarta2; ManoLabelsGiocatore.Add(lblcarta1); ManoLabelsGiocatore.Add(lblcarta2); int valCarta1 = carta1.CalcolaValoreCarta(); int valCarta2 = carta2.CalcolaValoreCarta(); if (carta1.CalcolaValoreCarta() == 11 && carta2.CalcolaValoreCarta() == 11) { valCarta1 = 1; } TotaleGiocatore = valCarta1 + valCarta2; lblGiocatore = new Label(); lblGiocatore.Location = new Point(8, 230); lblGiocatore.Font = new Font(lblGiocatore.Font.FontFamily, 12); lblGiocatore.AutoSize = true; lblGiocatore.BackColor = Color.Transparent; lblGiocatore.ForeColor = Color.White; lblGiocatore.Text = "GIOCATORE: " + TotaleGiocatore; Carta carta3 = mazzo.PescaCarta(); Carta carta4 = mazzo.PescaCarta(); ManoDealer.Add(carta3); ManoDealer.Add(carta4); Label lblcarta3 = new Label(); lblcarta3.Location = new Point(12, 33); string nomeimg3 = "../" + carta3.ToString() + ".bmp"; Image imgcarta3 = Image.FromFile(nomeimg3); lblcarta3.Size = new Size(imgcarta3.Width, imgcarta3.Height); lblcarta3.Image = imgcarta3; lblCartaCoperta = new Label(); lblCartaCoperta.Location = new Point(90, 33); string nomeimgcoperta = "../cartaCoperta.bmp"; Image imgcartacoperta = Image.FromFile(nomeimgcoperta); lblCartaCoperta.Size = new Size(imgcartacoperta.Width, imgcartacoperta.Height); lblCartaCoperta.Image = imgcartacoperta; lblImgMazzo = new Label(); lblImgMazzo.Location = new Point(650, 250); Image imgMazzo = Image.FromFile("../mazzoCarte.bmp"); lblImgMazzo.Size = new Size(imgMazzo.Width, imgMazzo.Height); lblImgMazzo.Image = imgMazzo; lblImgMazzo.TextAlign = ContentAlignment.MiddleCenter; lblImgMazzo.ForeColor = Color.White; lblImgMazzo.Font = new Font(lblGiocatore.Font.FontFamily, 28, FontStyle.Bold); lblImgMazzo.Text = "" + mazzo.NumeroCarteMazzo(); ManoLabelsDealer.Add(lblcarta3); ManoLabelsDealer.Add(lblCartaCoperta); int valCarta3 = carta3.CalcolaValoreCarta(); int valCarta4 = carta4.CalcolaValoreCarta(); if (carta3.CalcolaValoreCarta() == 11 && carta4.CalcolaValoreCarta() == 11) { valCarta3 = 11; } TotaleDealer = valCarta3; int TotaleDealerVero = valCarta3 + valCarta4; lblDealer = new Label(); lblDealer.Location = new Point(8, 13); lblDealer.Font = new Font(lblDealer.Font.FontFamily, 12); lblDealer.AutoSize = true; lblDealer.BackColor = Color.Transparent; lblDealer.ForeColor = Color.White; lblDealer.Text = "DEALER: " + TotaleDealer; btnPesca = new Button(); btnPesca.Location = new Point(12, 370); btnPesca.AutoSize = true; btnPesca.Font = new Font(btnPesca.Font.FontFamily, 26); btnPesca.Visible = true; btnPesca.Text = "Pesca"; btnPesca.Name = "btnPesca"; btnPesca.BackColor = Color.White; btnPesca.Click += new EventHandler(this.btnPesca_Click); btnMantieni = new Button(); btnMantieni.Location = new Point(140, 370); btnMantieni.AutoSize = true; btnMantieni.Font = new Font(btnPesca.Font.FontFamily, 26); btnMantieni.Visible = true; btnMantieni.Text = "Mantieni"; btnMantieni.Name = "btnMantieni"; btnMantieni.BackColor = Color.White; btnMantieni.Click += new EventHandler(this.btnMantieni_Click); btnRaddoppia = new Button(); btnRaddoppia.Location = new Point(302, 370); btnRaddoppia.AutoSize = true; btnRaddoppia.Font = new Font(btnPesca.Font.FontFamily, 26); btnRaddoppia.Visible = true; btnRaddoppia.Text = "Raddoppia"; btnRaddoppia.Name = "btnRaddoppia"; btnRaddoppia.BackColor = Color.White; btnRaddoppia.Click += new EventHandler(this.btnRaddoppia_Click); this.Controls.Add(lblGiocatore); this.Controls.Add(lblDealer); this.Controls.Add(btnPesca); this.Controls.Add(btnMantieni); this.Controls.Add(btnRaddoppia); this.Controls.Add(lblImgMazzo); this.Controls.Add(lblcarta1); this.Controls.Add(lblcarta2); this.Controls.Add(lblcarta3); this.Controls.Add(lblCartaCoperta); this.Controls.Add(lblSoldi); this.Controls.Add(ViewPuntata); this.Controls.Add(lblVincitaMax); this.AutoSize = true; if (TotaleGiocatore == 21 && TotaleDealerVero != 21) { DateEnd = new DateTime(); DateEnd = DateTime.Now; soldi += puntata * 2; lblSoldi.Text = "Soldi disponibili: " + soldi; vincitore = "player"; Label lblSconfittaDealer = new Label(); lblSconfittaDealer.Location = new Point(130, 164); lblSconfittaDealer.Font = new Font(lblSconfittaDealer.Font.FontFamily, 26); lblSconfittaDealer.BackColor = Color.Transparent; lblSconfittaDealer.ForeColor = Color.White; lblSconfittaDealer.Name = "lblSconfittaDealer"; lblSconfittaDealer.Text = "BLACKJACK! Il Giocatore Ha vinto!"; lblSconfittaDealer.AutoSize = true; lblSconfittaDealer.Visible = true; btnGiocaAgain = new Button(); btnGiocaAgain.Location = new Point(12, 370); btnGiocaAgain.AutoSize = true; btnGiocaAgain.Width = 197; btnGiocaAgain.Font = new Font(btnGiocaAgain.Font.FontFamily, 20); btnGiocaAgain.Text = "Nuova Partita"; btnGiocaAgain.Name = "btnGiocaAgain"; btnGiocaAgain.BackColor = Color.White; btnGiocaAgain.Click += new EventHandler(this.btnGiocaAgain_Click); btnTornaMenu.Location = new Point(525, 370); btnTornaMenu.AutoSize = true; btnTornaMenu.Font = new Font(btnTornaMenu.Font.FontFamily, 20); btnTornaMenu.Text = "Torna al Menù"; btnTornaMenu.Name = "btnTornaMenu"; btnTornaMenu.BackColor = Color.White; btnTornaMenu.Click += new EventHandler(this.Form1_Load); this.Controls.Remove(lblCartaCoperta); ManoLabelsDealer.Remove(lblCartaCoperta); Label lblCartaScoperta = new Label(); lblCartaScoperta.Location = new Point((ManoLabelsDealer[ManoLabelsDealer.Count - 1].Location.X + 78), 33); string nomeimgscoperta = "../" + carta4.ToString() + ".bmp"; Image imgcartascoperta = Image.FromFile(nomeimgscoperta); lblCartaScoperta.Size = new Size(imgcartascoperta.Width, imgcartascoperta.Height); lblCartaScoperta.Image = imgcartascoperta; ManoLabelsDealer.Add(lblCartaScoperta); lblDealer.Text = "DEALER: " + TotaleDealerVero; this.Controls.Remove(btnPesca); this.Controls.Remove(btnMantieni); this.Controls.Remove(btnRaddoppia); this.Controls.Add(lblSconfittaDealer); this.Controls.Add(btnGiocaAgain); this.Controls.Add(btnTornaMenu); this.Controls.Add(lblCartaScoperta); SaveXml(); MessageBox.Show("Complimenti! Hai vinto " + puntata * 2, "Vittoria", MessageBoxButtons.OK, MessageBoxIcon.Information); lblSoldi.Text = "Soldi disponibili: " + soldi; } if (TotaleDealerVero == 21 && TotaleGiocatore != 21) { DateEnd = new DateTime(); DateEnd = DateTime.Now; vincitore = "dealer"; Label lblSconfittaGiocatore = new Label(); lblSconfittaGiocatore.Location = new Point(130, 164); lblSconfittaGiocatore.Font = new Font(lblSconfittaGiocatore.Font.FontFamily, 26); lblSconfittaGiocatore.BackColor = Color.Transparent; lblSconfittaGiocatore.ForeColor = Color.White; lblSconfittaGiocatore.Name = "lblSconfittaGiocatore"; lblSconfittaGiocatore.Text = "BLACKJACK! Il Dealer Ha vinto!"; lblSconfittaGiocatore.AutoSize = true; lblSconfittaGiocatore.Visible = true; btnGiocaAgain = new Button(); btnGiocaAgain.Location = new Point(12, 370); btnGiocaAgain.AutoSize = true; btnGiocaAgain.Width = 197; btnGiocaAgain.Font = new Font(btnGiocaAgain.Font.FontFamily, 20); btnGiocaAgain.Text = "Nuova Partita"; btnGiocaAgain.Name = "btnGiocaAgain"; btnGiocaAgain.BackColor = Color.White; btnGiocaAgain.Click += new EventHandler(this.btnGiocaAgain_Click); btnTornaMenu.Location = new Point(525, 370); btnTornaMenu.AutoSize = true; btnTornaMenu.Font = new Font(btnTornaMenu.Font.FontFamily, 20); btnTornaMenu.Text = "Torna al Menù"; btnTornaMenu.Name = "btnTornaMenu"; btnTornaMenu.BackColor = Color.White; btnTornaMenu.Click += new EventHandler(this.Form1_Load); this.Controls.Remove(lblCartaCoperta); ManoLabelsDealer.Remove(lblCartaCoperta); Label lblCartaScoperta = new Label(); lblCartaScoperta.Location = new Point((ManoLabelsDealer[ManoLabelsDealer.Count - 1].Location.X + 78), 33); string nomeimgscoperta = "../" + carta4.ToString() + ".bmp"; Image imgcartascoperta = Image.FromFile(nomeimgscoperta); lblCartaScoperta.Size = new Size(imgcartascoperta.Width, imgcartascoperta.Height); lblCartaScoperta.Image = imgcartascoperta; ManoLabelsDealer.Add(lblCartaScoperta); lblDealer.Text = "DEALER: " + TotaleDealerVero; this.Controls.Remove(btnPesca); this.Controls.Remove(btnMantieni); this.Controls.Remove(btnRaddoppia); this.Controls.Add(lblSconfittaGiocatore); this.Controls.Add(btnGiocaAgain); this.Controls.Add(btnTornaMenu); this.Controls.Add(lblCartaScoperta); SaveXml(); MessageBox.Show("Peccato! Hai perso " + puntata, "Sconfitta", MessageBoxButtons.OK, MessageBoxIcon.Information); lblSoldi.Text = "Soldi disponibili: " + soldi; } }