private Jugada HacerJugada(string datos) { String[] subdatos = datos.Split('#'); Carta cartPlayer = new Carta(subdatos[2]); int numCardsMesa = Convert.ToInt16(subdatos[3]); string[] str = new string[numCardsMesa]; str = subdatos[4].Split('/'); List <Carta> bazaMesa = new List <Carta>(); for (int i = 0; i < numCardsMesa; i++) { Carta carta = new Carta(str[i]); bazaMesa.Add(carta); } Jugada jugada = new Jugada(cartPlayer, bazaMesa); return(jugada); }
public void MescolaMazzo() { Random r = new Random(); int numeroMescolamenti = r.Next(50, 100); int posizione1; int posizione2; for (int i = 0; i < numeroMescolamenti; i++) { posizione1 = r.Next(mazzo.Count); do { posizione2 = r.Next(mazzo.Count); }while(posizione1 == posizione2); Carta cartaTemp = mazzo[posizione1]; mazzo[posizione1] = mazzo[posizione2]; mazzo[posizione2] = cartaTemp; } }
// cria as cartas do trunfo private Carta[] CriarCartas() { Carta dino1 = new Carta(); dino1.nome = "Herrerassauro"; dino1.num = "1A"; dino1.img = Properties.Resources.Dino1A; dino1.atr.altura = 1.5f; dino1.atr.comprimento = 4.5f; dino1.atr.peso = 300; dino1.atr.idade = 231; Carta dino2 = new Carta(); dino2.nome = "Procompsognato"; dino2.num = "1B"; dino2.img = Properties.Resources.Dino1B; dino2.atr.altura = 0.3f; dino2.atr.comprimento = 1.2f; dino2.atr.peso = 1; dino2.atr.idade = 222; Carta dino3 = new Carta(); dino3.nome = "Patagossauro"; dino3.num = "1C"; dino3.img = Properties.Resources.Dino1C; dino3.atr.altura = 8f; dino3.atr.comprimento = 18f; dino3.atr.peso = 16000; dino3.atr.idade = 169; Carta dino4 = new Carta(); dino4.nome = "Ceratossauro"; dino4.num = "1D"; dino4.img = Properties.Resources.Dino1D; dino4.atr.altura = 2f; dino4.atr.comprimento = 6f; dino4.atr.peso = 1000; dino4.atr.idade = 156; Carta dino5 = new Carta(); dino5.nome = "Pterodáctilo"; dino5.num = "2A"; dino5.img = Properties.Resources.Dino2A; dino5.atr.altura = 0.5f; dino5.atr.comprimento = 1f; dino5.atr.peso = 1; dino5.atr.idade = 150; Carta dino6 = new Carta(); dino6.nome = "Velociraptor"; dino6.num = "2B"; dino6.img = Properties.Resources.Dino2B; dino6.atr.altura = 1f; dino6.atr.comprimento = 1.8f; dino6.atr.peso = 15; dino6.atr.idade = 80; Carta dino7 = new Carta(); dino7.nome = "Triceratopo"; dino7.num = "2C"; dino7.img = Properties.Resources.Dino2C; dino7.atr.altura = 6f; dino7.atr.comprimento = 9f; dino7.atr.peso = 6000; dino7.atr.idade = 68; Carta dino8 = new Carta(); dino8.nome = "Baptornis"; dino8.num = "2D"; dino8.img = Properties.Resources.Dino2D; dino8.atr.altura = 0.8f; dino8.atr.comprimento = 1f; dino8.atr.peso = 7; dino8.atr.idade = 83; Carta[] v = new Carta[8]; v[0] = dino1; v[1] = dino2; v[2] = dino3; v[3] = dino4; v[4] = dino5; v[5] = dino6; v[6] = dino7; v[7] = dino8; return(v); }
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 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 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; } }
private void ManejarClienteAuto(TcpClient cli) { try { string data; NetworkStream ns = cli.GetStream(); StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); //sw.WriteLine("#INSCRIBIR#nombre#"); //sw.WriteLine("#REPARTECARTAS#{cartasJugador1/cartasJugador2}#cartasMesa#"); //sw.WriteLine("#TURNO#turnoJugador#idturnoJugador#"); //sw.WriteLine("#JUGADA#cartamanoJug2#numCartasMesa#cartasMesa(cartaMesa1/cartamesa2...)#"); //sw.WriteLine("#ACTUALIZAMESA#cartasMesa#"); //sw.WriteLine("#CHECKCARDS#"); //sw.Flush(); while (true) { try { data = sr.ReadLine(); Console.WriteLine(data); //para depuración es server String[] subdatos = data.Split('#'); #region comINSCRIBIR if (subdatos[1] == "INSCRIBIR") { if (jugador1 == "") { jugador1 = subdatos[2]; idJug1 = cli.Client.RemoteEndPoint.ToString(); turno = idJug1; IpJug1 = idJug1.Split(':')[0]; sw.WriteLine("Bienvenido jugador: " + jugador1); sw.Flush(); } else { sw.WriteLine("Ya hay dos jugadores"); sw.Flush(); } } #endregion #region comREPARTIRCARTAS if (subdatos[1] == "REPARTECARTAS") { if (idJug1 == cli.Client.RemoteEndPoint.ToString()) { sw.WriteLine(ListarCartasJugador1()); sw.Flush(); } sw.WriteLine(ListarCartasMesa()); sw.Flush(); } #endregion #region comESTABLECETURNO if (subdatos[1] == "TURNO") { string result = ""; if (turno.Equals(idJug1)) { result = "El turno es de " + jugador1 + "#" + idJug1; } if (turno.Equals("maquina")) { if (ListaManoautoPlay.Count == 0) { repartecartasAuto(); } result = "El turno es de la maquina"; List <List <Carta> > combinaciones = calculaCombinaciones(); if (combinaciones.Count == 0) { Carta c = chooseAutoCard(); if (c == null) { listaCartasMesa.Add(ListaManoautoPlay[0]); //mesaActualizada[mesaActualizada.Length - 1] = ListaManoautoPlay[0].nombre; ListaManoautoPlay.Remove(ListaManoautoPlay[0]); } else { listaCartasMesa.Add(c); //mesaActualizada[mesaActualizada.Length - 1] = c.nombre; Carta toRemove = ListaManoautoPlay.Find(f => f.nombre.Equals(c.nombre)); ListaManoautoPlay.Remove(toRemove); } } else { List <Carta> trick = chooseTrick(combinaciones); if (listaCartasMesa.Count == 0) { PuntosautoPlay.escobas++; } PuntosautoPlay.addBaza(trick); } turno = idJug1; } sw.WriteLine(result); sw.Flush(); } #endregion #region comJugada if (subdatos[1] == "JUGADA") { if (idJug1 == cli.Client.RemoteEndPoint.ToString()) { if (subdatos[2] == "0") { //mesaActualizada = subdatos[3].Split('/'); //string[] list_updated = subdatos[3].Split('/'); //int index = list_updated.Length - 2; //Carta carta = new Carta(list_updated[index]); //listaCartasMesa.Add(carta); getCartasMesa(subdatos[3].Split('/')); turno = "maquina"; } else { Jugada jugada = HacerJugada(data); if (jugada.checkBaza()) { sw.WriteLine("El jugador " + jugador1 + " ha hecho baza"); sw.Flush(); PuntosJugador1 = new Puntos(jugada); sw.WriteLine( PuntosJugador1.GetNumCartas() + "#" + PuntosJugador1.GetNumOros() + "#" + PuntosJugador1.GetNumSietes() + "#" + PuntosJugador1.GetSieteOros()); sw.Flush(); foreach (Carta card in bazaMesa) { Carta carta = listaCartasMesa.Find(f => f.nombre.Equals(card.nombre)); if (carta != null) { listaCartasMesa.Remove(carta); } } turno = "maquina"; } else { sw.WriteLine("No se puede hacer baza. Intentalo de nuevo"); sw.Flush(); } } } } #endregion #region comSENDTABLEUPDATED if (subdatos[1] == "SENDTABLEUPDATED") { mesaActualizada = subdatos[2].Split('/'); } #endregion #region comGETTABLEUPDATED if (subdatos[1] == "GETTABLEUPDATED") { //string mesa = ""; //for (int i = 0; i < mesaActualizada.Length; i++) //{ // if (!String.IsNullOrWhiteSpace(mesaActualizada[i])) // { // mesa += mesaActualizada[i] + "/"; // } //} //sw.WriteLine(mesa); string update = ListarCartasMesa(); sw.WriteLine(update); sw.Flush(); } #endregion #region comCheckCards if (subdatos[1] == "CHECKCARDS") { string numCartas = subdatos[2]; if (cont == 40) { endGame = true; } if (!endGame) { sw.WriteLine("OK"); sw.Flush(); if (numCartas == "0") { if (idJug1 == cli.Client.RemoteEndPoint.ToString()) { ListaManoJugador1 = new List <Carta>(); repartecartasJug1(); sw.WriteLine(ListarCartasJugador1()); sw.Flush(); } else { ListaManoautoPlay = new List <Carta>(); repartecartasAuto(); } } } else if (ListaManoautoPlay.Count == 0 && numCartas == "0") { sw.WriteLine("GetPoints"); sw.Flush(); string[] puntos = sr.ReadLine().Split('/'); Console.WriteLine(puntos.ToString()); if (idJug1 == cli.Client.RemoteEndPoint.ToString()) { Thread.Sleep(4000); PuntosJugador1 = new Puntos(); PuntosJugador1.escobas = Convert.ToInt16(puntos[0]); PuntosJugador1.cartas = Convert.ToInt16(puntos[1]); PuntosJugador1.oros = Convert.ToInt16(puntos[2]); PuntosJugador1.sietes = Convert.ToInt16(puntos[3]); PuntosJugador1.sieteOros = Convert.ToInt16(puntos[4]); //PuntosautoPlay.escobas =; PuntosautoPlay.cartas = PuntosautoPlay.GetNumCartas(); PuntosautoPlay.oros = PuntosautoPlay.GetNumOros(); PuntosautoPlay.sietes = PuntosautoPlay.GetNumSietes(); PuntosautoPlay.sieteOros = PuntosautoPlay.GetSieteOros(); ComparePoints(); string winner = Winner(); sw.WriteLine(winner); sw.Flush(); break; } } else { sw.WriteLine("NOK"); sw.Flush(); } } #endregion } catch (IOException error) { Console.WriteLine("Error: {0}", error.ToString()); break; } } ns.Close(); cli.Close(); } catch (Exception error) { Console.WriteLine("Error: {0}", error.ToString()); throw; } }
private void ManejarCliente(TcpClient cli) { string data; NetworkStream ns = cli.GetStream(); StreamReader sr = new StreamReader(ns); StreamWriter sw = new StreamWriter(ns); //sw.WriteLine("#INSCRIBIR#nombre#"); //sw.WriteLine("#REPARTECARTAS#{cartasJugador1/cartasJugador2}#cartasMesa#"); //sw.WriteLine("#JUGADA1#cartamanoJug2#numCartasMesa#cartasMesa(cartaMesa1/cartamesa2...)#"); //sw.WriteLine("#JUGADA2#cartamanoJug2#numCartasMesa#cartasMesa(cartaMesa1/cartamesa2...)#"); //sw.WriteLine("#PUNTUACION#"); sw.Flush(); while (true) { try { data = sr.ReadLine(); Console.WriteLine(data); //para depuración es server String[] subdatos = data.Split('#'); #region comINSCRIBIR if (subdatos[1] == "INSCRIBIR") { if (jugador1 == "") { jugador1 = subdatos[2]; idJug1 = cli.Client.RemoteEndPoint.ToString(); IpJug1 = idJug1.Split(':')[0]; sw.WriteLine("Bienvenido jugador: " + jugador1); sw.Flush(); } else if (jugador2 == "") { jugador2 = subdatos[2]; idJug2 = cli.Client.RemoteEndPoint.ToString(); IpJug2 = idJug2.Split(':')[0]; sw.WriteLine("Bienvenido jugador: " + jugador2); sw.Flush(); } else { sw.WriteLine("Ya hay dos jugadores"); sw.Flush(); } } #endregion #region comREPARTIRCARTAS if (subdatos[1] == "REPARTECARTAS") { repartecartasJug(); repartecartasMesa(); //foreach (Carta cartas in ListaManoJugador1) //{ // sw.WriteLine( cartas.nombre); //} sw.WriteLine(ListarCartasJugador1()); sw.Flush(); //} //else if (subdatos[2] == idJug2) // sw.WriteLine(ListarCartasJugador2()); sw.WriteLine(ListarCartasMesa()); sw.Flush(); } #endregion #region comJugada1 if (subdatos[1] == "JUGADA1") { Carta cartPlayer = new Carta(subdatos[2]); int numCardsMesa = Convert.ToInt16(subdatos[3]); string[] str = new string[numCardsMesa]; str = subdatos[4].Split('/'); List <Carta> bazaMesa = new List <Carta>(); for (int i = 0; i < numCardsMesa; i++) { Carta carta = new Carta(str[i]); bazaMesa.Add(carta); } Jugada jugada = new Jugada(cartPlayer, bazaMesa); if (jugada.checkBaza()) { sw.WriteLine("El jugador " + jugador1 + " Ha hecho baza"); } else { sw.WriteLine("No se puede hacer baza"); } } #endregion #region comJugada2 if (subdatos[1] == "JUGADA2") { Carta cartPlayer = new Carta(subdatos[2]); int numCardsMesa = Convert.ToInt16(subdatos[3]); string[] str = new string[numCardsMesa]; str = subdatos[4].Split('/'); List <Carta> bazaMesa = new List <Carta>(); for (int i = 0; i < numCardsMesa; i++) { Carta carta = new Carta(str[i]); bazaMesa.Add(carta); } Jugada jugada = new Jugada(cartPlayer, bazaMesa); if (jugada.checkBaza()) { sw.WriteLine("El jugador " + jugador2 + " Ha hecho baza"); } else { sw.WriteLine("No se puede hacer baza"); } } #endregion } catch (Exception error) { Console.WriteLine("Error: {0}", error.ToString()); break; } } ns.Close(); cli.Close(); }