ho questo progetto di win form, mi servirebbe che tu mi generassi delle funzioni per contare il valore delle carte del giocatore e del computer e permettere al giocatore di prendere una carta ovviamente calcolando il suo valore, ti spiego un pò di logistica, le carte sono rinominate in questo modo _ numerocarta+suffisso cioè il tipo di carta, bene se numero carta è = ad 1 signfica che è un asso mentre dal 2 al 10 normale e dal 11 (compreso 11) all 13 sono jack regina king. se il giocatore fa black jack ha vinto e quindi gli devi assegnare il doppio dei punti mentre se perde devi farli rimanere uguali. ricorda tutto il codice che devi scrivere non devi stravolgere ciò che ho già scritto io a meno che io non te o abbia detto, devi cercare di mantenerlo il più semplice possibile faccio la quarta superiore e non ho capacità nell'ambito quindi scrivi anche di più facendo più passaggi ma non usare comandi strani. ecco il codice: namespace blackjack
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.pbfiches1 = new System.Windows.Forms.PictureBox();
this.pbfiches5 = new System.Windows.Forms.PictureBox();
this.pbfiches25 = new System.Windows.Forms.PictureBox();
this.scrittapunteggio = new System.Windows.Forms.Label();
this.lblpuntata = new System.Windows.Forms.Label();
this.lblmazziere = new System.Windows.Forms.Label();
this.lblgiocatorestatic = new System.Windows.Forms.Label();
this.pb1pc = new System.Windows.Forms.PictureBox();
this.pb2pc = new System.Windows.Forms.PictureBox();
this.pb3pc = new System.Windows.Forms.PictureBox();
this.pb1p = new System.Windows.Forms.PictureBox();
this.pb2p = new System.Windows.Forms.PictureBox();
this.pb3p = new System.Windows.Forms.PictureBox();
this.pb4p = new System.Windows.Forms.PictureBox();
this.pb5p = new System.Windows.Forms.PictureBox();
this.lblsoldistatica = new System.Windows.Forms.Label();
this.lblsoldi = new System.Windows.Forms.Label();
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.btnprendi = new System.Windows.Forms.Button();
this.btnrimani = new System.Windows.Forms.Button();
this.lblscrittainiziale = new System.Windows.Forms.Label();
this.btninizia = new System.Windows.Forms.Button();
this.btnesci = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.lblpunteggiopc = new System.Windows.Forms.Label();
this.lblpunteggio = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.pbfiches1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbfiches5)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pbfiches25)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb1pc)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb2pc)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb3pc)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb1p)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb2p)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb3p)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb4p)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb5p)).BeginInit();
this.SuspendLayout();
//
// pbfiches1
//
this.pbfiches1.Image = global::blackjack.Properties.Resources.plus1;
this.pbfiches1.Location = new System.Drawing.Point(273, 202);
this.pbfiches1.Name = "pbfiches1";
this.pbfiches1.Size = new System.Drawing.Size(52, 50);
this.pbfiches1.TabIndex = 0;
this.pbfiches1.TabStop = false;
this.pbfiches1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// pbfiches5
//
this.pbfiches5.Image = global::blackjack.Properties.Resources.plus5;
this.pbfiches5.Location = new System.Drawing.Point(376, 202);
this.pbfiches5.Name = "pbfiches5";
this.pbfiches5.Size = new System.Drawing.Size(52, 50);
this.pbfiches5.TabIndex = 1;
this.pbfiches5.TabStop = false;
this.pbfiches5.Click += new System.EventHandler(this.pictureBox2_Click);
//
// pbfiches25
//
this.pbfiches25.Image = global::blackjack.Properties.Resources.plus25;
this.pbfiches25.Location = new System.Drawing.Point(487, 202);
this.pbfiches25.Name = "pbfiches25";
this.pbfiches25.Size = new System.Drawing.Size(50, 50);
this.pbfiches25.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pbfiches25.TabIndex = 2;
this.pbfiches25.TabStop = false;
this.pbfiches25.Click += new System.EventHandler(this.pictureBox3_Click);
//
// scrittapunteggio
//
this.scrittapunteggio.AutoSize = true;
this.scrittapunteggio.Location = new System.Drawing.Point(671, 77);
this.scrittapunteggio.Name = "scrittapunteggio";
this.scrittapunteggio.Size = new System.Drawing.Size(44, 13);
this.scrittapunteggio.TabIndex = 3;
this.scrittapunteggio.Text = "Puntata";
//
// lblpuntata
//
this.lblpuntata.AutoSize = true;
this.lblpuntata.Location = new System.Drawing.Point(671, 103);
this.lblpuntata.Name = "lblpuntata";
this.lblpuntata.Size = new System.Drawing.Size(35, 13);
this.lblpuntata.TabIndex = 4;
this.lblpuntata.Text = "label2";
//
// lblmazziere
//
this.lblmazziere.AutoSize = true;
this.lblmazziere.Location = new System.Drawing.Point(50, 32);
this.lblmazziere.Name = "lblmazziere";
this.lblmazziere.Size = new System.Drawing.Size(48, 13);
this.lblmazziere.TabIndex = 5;
this.lblmazziere.Text = "mazziere";
this.lblmazziere.Visible = false;
this.lblmazziere.Click += new System.EventHandler(this.label1_Click);
//
// lblgiocatorestatic
//
this.lblgiocatorestatic.AutoSize = true;
this.lblgiocatorestatic.Location = new System.Drawing.Point(50, 428);
this.lblgiocatorestatic.Name = "lblgiocatorestatic";
this.lblgiocatorestatic.Size = new System.Drawing.Size(51, 13);
this.lblgiocatorestatic.TabIndex = 6;
this.lblgiocatorestatic.Text = "giocatore";
this.lblgiocatorestatic.Visible = false;
//
// pb1pc
//
this.pb1pc.Location = new System.Drawing.Point(53, 67);
this.pb1pc.Name = "pb1pc";
this.pb1pc.Size = new System.Drawing.Size(80, 114);
this.pb1pc.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pb1pc.TabIndex = 7;
this.pb1pc.TabStop = false;
//
// pb2pc
//
this.pb2pc.Location = new System.Drawing.Point(139, 67);
this.pb2pc.Name = "pb2pc";
this.pb2pc.Size = new System.Drawing.Size(80, 114);
this.pb2pc.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pb2pc.TabIndex = 8;
this.pb2pc.TabStop = false;
//
// pb3pc
//
this.pb3pc.Location = new System.Drawing.Point(225, 67);
this.pb3pc.Name = "pb3pc";
this.pb3pc.Size = new System.Drawing.Size(80, 114);
this.pb3pc.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pb3pc.TabIndex = 9;
this.pb3pc.TabStop = false;
//
// pb1p
//
this.pb1p.Location = new System.Drawing.Point(53, 299);
this.pb1p.Name = "pb1p";
this.pb1p.Size = new System.Drawing.Size(80, 114);
this.pb1p.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pb1p.TabIndex = 10;
this.pb1p.TabStop = false;
//
// pb2p
//
this.pb2p.Location = new System.Drawing.Point(139, 299);
this.pb2p.Name = "pb2p";
this.pb2p.Size = new System.Drawing.Size(80, 114);
this.pb2p.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pb2p.TabIndex = 11;
this.pb2p.TabStop = false;
//
// pb3p
//
this.pb3p.Location = new System.Drawing.Point(225, 299);
this.pb3p.Name = "pb3p";
this.pb3p.Size = new System.Drawing.Size(80, 114);
this.pb3p.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pb3p.TabIndex = 12;
this.pb3p.TabStop = false;
//
// pb4p
//
this.pb4p.Location = new System.Drawing.Point(311, 299);
this.pb4p.Name = "pb4p";
this.pb4p.Size = new System.Drawing.Size(80, 114);
this.pb4p.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pb4p.TabIndex = 13;
this.pb4p.TabStop = false;
//
// pb5p
//
this.pb5p.Location = new System.Drawing.Point(397, 299);
this.pb5p.Name = "pb5p";
this.pb5p.Size = new System.Drawing.Size(80, 114);
this.pb5p.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pb5p.TabIndex = 14;
this.pb5p.TabStop = false;
//
// lblsoldistatica
//
this.lblsoldistatica.AutoSize = true;
this.lblsoldistatica.Location = new System.Drawing.Point(671, 32);
this.lblsoldistatica.Name = "lblsoldistatica";
this.lblsoldistatica.Size = new System.Drawing.Size(30, 13);
this.lblsoldistatica.TabIndex = 15;
this.lblsoldistatica.Text = "Soldi";
//
// lblsoldi
//
this.lblsoldi.AutoSize = true;
this.lblsoldi.Location = new System.Drawing.Point(671, 55);
this.lblsoldi.Name = "lblsoldi";
this.lblsoldi.Size = new System.Drawing.Size(35, 13);
this.lblsoldi.TabIndex = 16;
this.lblsoldi.Text = "label4";
//
// btnprendi
//
this.btnprendi.Location = new System.Drawing.Point(562, 317);
this.btnprendi.Name = "btnprendi";
this.btnprendi.Size = new System.Drawing.Size(75, 23);
this.btnprendi.TabIndex = 19;
this.btnprendi.Text = "prendi carta";
this.btnprendi.UseVisualStyleBackColor = true;
this.btnprendi.Visible = false;
this.btnprendi.Click += new System.EventHandler(this.btnprendi_Click);
//
// btnrimani
//
this.btnrimani.Location = new System.Drawing.Point(562, 346);
this.btnrimani.Name = "btnrimani";
this.btnrimani.Size = new System.Drawing.Size(75, 23);
this.btnrimani.TabIndex = 20;
this.btnrimani.Text = "rimani";
this.btnrimani.UseVisualStyleBackColor = true;
this.btnrimani.Visible = false;
this.btnrimani.Click += new System.EventHandler(this.btnrimani_Click);
//
// lblscrittainiziale
//
this.lblscrittainiziale.AutoSize = true;
this.lblscrittainiziale.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblscrittainiziale.Location = new System.Drawing.Point(329, 168);
this.lblscrittainiziale.Name = "lblscrittainiziale";
this.lblscrittainiziale.Size = new System.Drawing.Size(130, 13);
this.lblscrittainiziale.TabIndex = 21;
this.lblscrittainiziale.Text = "scegli quanto puntare";
//
// btninizia
//
this.btninizia.Location = new System.Drawing.Point(364, 258);
this.btninizia.Name = "btninizia";
this.btninizia.Size = new System.Drawing.Size(75, 23);
this.btninizia.TabIndex = 22;
this.btninizia.Text = "inizia";
this.btninizia.UseVisualStyleBackColor = true;
this.btninizia.Click += new System.EventHandler(this.btninizia_Click);
//
// btnesci
//
this.btnesci.Location = new System.Drawing.Point(364, 288);
this.btnesci.Name = "btnesci";
this.btnesci.Size = new System.Drawing.Size(75, 23);
this.btnesci.TabIndex = 23;
this.btnesci.Text = "esci";
this.btnesci.UseVisualStyleBackColor = true;
this.btnesci.Click += new System.EventHandler(this.button1_Click);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(584, 182);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(0, 13);
this.label5.TabIndex = 24;
//
// lblpunteggiopc
//
this.lblpunteggiopc.AutoSize = true;
this.lblpunteggiopc.Location = new System.Drawing.Point(97, 32);
this.lblpunteggiopc.Name = "lblpunteggiopc";
this.lblpunteggiopc.Size = new System.Drawing.Size(35, 13);
this.lblpunteggiopc.TabIndex = 25;
this.lblpunteggiopc.Text = "label6";
this.lblpunteggiopc.Visible = false;
//
// lblpunteggio
//
this.lblpunteggio.AutoSize = true;
this.lblpunteggio.Location = new System.Drawing.Point(107, 428);
this.lblpunteggio.Name = "lblpunteggio";
this.lblpunteggio.Size = new System.Drawing.Size(35, 13);
this.lblpunteggio.TabIndex = 26;
this.lblpunteggio.Text = "label7";
this.lblpunteggio.Visible = false;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.lblpunteggio);
this.Controls.Add(this.lblpunteggiopc);
this.Controls.Add(this.label5);
this.Controls.Add(this.btnesci);
this.Controls.Add(this.btninizia);
this.Controls.Add(this.lblscrittainiziale);
this.Controls.Add(this.pbfiches1);
this.Controls.Add(this.btnrimani);
this.Controls.Add(this.btnprendi);
this.Controls.Add(this.lblsoldi);
this.Controls.Add(this.lblsoldistatica);
this.Controls.Add(this.pb5p);
this.Controls.Add(this.pb4p);
this.Controls.Add(this.pb3p);
this.Controls.Add(this.pb2p);
this.Controls.Add(this.pb1p);
this.Controls.Add(this.pb3pc);
this.Controls.Add(this.pb2pc);
this.Controls.Add(this.pb1pc);
this.Controls.Add(this.lblgiocatorestatic);
this.Controls.Add(this.lblmazziere);
this.Controls.Add(this.lblpuntata);
this.Controls.Add(this.scrittapunteggio);
this.Controls.Add(this.pbfiches25);
this.Controls.Add(this.pbfiches5);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pbfiches1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pbfiches5)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pbfiches25)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb1pc)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb2pc)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb3pc)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb1p)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb2p)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb3p)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb4p)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb5p)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pbfiches1;
private System.Windows.Forms.PictureBox pbfiches5;
private System.Windows.Forms.PictureBox pbfiches25;
private System.Windows.Forms.Label scrittapunteggio;
private System.Windows.Forms.Label lblpuntata;
private System.Windows.Forms.Label lblmazziere;
private System.Windows.Forms.Label lblgiocatorestatic;
private System.Windows.Forms.PictureBox pb1pc;
private System.Windows.Forms.PictureBox pb2pc;
private System.Windows.Forms.PictureBox pb3pc;
private System.Windows.Forms.PictureBox pb1p;
private System.Windows.Forms.PictureBox pb2p;
private System.Windows.Forms.PictureBox pb3p;
private System.Windows.Forms.PictureBox pb4p;
private System.Windows.Forms.PictureBox pb5p;
private System.Windows.Forms.Label lblsoldistatica;
private System.Windows.Forms.Label lblsoldi;
private System.ComponentModel.BackgroundWorker backgroundWorker1;
private System.Windows.Forms.Button btnprendi;
private System.Windows.Forms.Button btnrimani;
private System.Windows.Forms.Label lblscrittainiziale;
private System.Windows.Forms.Button btninizia;
private System.Windows.Forms.Button btnesci;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label lblpunteggiopc;
private System.Windows.Forms.Label lblpunteggio;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace blackjack
{
public partial class Form1 : Form
{
public string[] carte = new string[52];
private int soldi = 1000;
private int puntata = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
AggiornaVisualizzazione();
pb1p.Visible = false;
pb2p.Visible = false;
pb3p.Visible = false;
lblmazziere.Visible = false;
lblpunteggiopc.Visible = false;
pb1p.Visible = false;
pb2p.Visible = false;
pb3p.Visible = false;
pb4p.Visible = false;
pb5p.Visible = false;
btnprendi.Visible = false;
btnrimani.Visible = false;
}
public void Generacarte(string[] carte)
{
string[] seme = { "c", "d", "s", "h" };
int j = 0;
foreach (string s in seme)
{
for (int i = 1; i < 14; i++, j++)
{
carte[j] = "_" + i + s;
}
}
}
public void Mischiacarte(string[] carte)
{
int totaleCarte = carte.Length;
Random random = new Random();
for (int k = 0; k < totaleCarte * 4; k++)
{
int i = random.Next(totaleCarte);
int j = random.Next(totaleCarte);
if (i != j)
{
string temporanea = carte[i];
carte[i] = carte[j];
carte[j] = temporanea;
}
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void pictureBox3_Click(object sender, EventArgs e)
{
if (soldi >= 25)
{
soldi -= 25;
puntata += 25;
}
else
{
allert();
}
AggiornaVisualizzazione();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
if (soldi >= 5)
{
soldi -= 5;
puntata += 5;
}
else
{
allert();
}
AggiornaVisualizzazione();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
if (soldi >= 1)
{
soldi -= 1;
puntata += 1;
}
else
{
allert();
}
AggiornaVisualizzazione();
}
public void allert()
{
MessageBox.Show("Non hai abbastanza soldi", "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
private void AggiornaVisualizzazione()
{
lblsoldi.Text = "" + soldi;
lblpuntata.Text = "" + puntata;
}
private void btninizia_Click(object sender, EventArgs e)
{
mostraelementi();
nascondifiches();
Generacarte(carte);
Mischiacarte(carte);
daicarte();
}
public void mostraelementi()
{
pb1p.Visible = true;
pb2p.Visible = true;
pb3p.Visible = true;
lblmazziere.Visible = true;
lblpunteggiopc.Visible = true;
pb1p.Visible = true;
pb2p.Visible = true;
pb3p.Visible = true;
pb4p.Visible = true;
pb5p.Visible = true;
btnprendi.Visible = true;
btnrimani.Visible = true;
lblgiocatorestatic.Visible = true;
lblpunteggio.Visible = true;
}
public void nascondifiches()
{
pbfiches1.Visible = false;
pbfiches5.Visible = false;
pbfiches25.Visible = false;
btninizia.Visible = false;
btnesci.Visible = false;
lblscrittainiziale.Visible = false;
}
public void mostrafiches()
{
pbfiches1.Visible = true;
pbfiches5.Visible = true;
pbfiches25.Visible = true;
btninizia.Visible = true;
btnesci.Visible = true;
lblscrittainiziale.Visible = true;
}
public void daicarte()
{
pb1p.Image = (Image)Properties.Resources.ResourceManager.GetObject(carte[0]);
pb2p.Image = (Image)Properties.Resources.ResourceManager.GetObject(carte[1]);
pb1pc.Image = (Image)Properties.Resources.ResourceManager.GetObject(carte[2]);
}
private void button1_Click(object sender, EventArgs e)
{
}
private void btnprendi_Click(object sender, EventArgs e)
{
pb3p.Image = (Image)Properties.Resources.ResourceManager.GetObject(carte[5]);
}
private void btnrimani_Click(object sender, EventArgs e)
{
}
}
}