/*
esempio classe random
scaricato da:
www.dario-avellino.it
*/
using System.Windows.Forms;
using System.Drawing;
using System;
class threecart
{
Form f1=new Form();
TextBox tulb = new TextBox();
TextBox pclb = new TextBox();
Label l1 = new Label();
Label l2 = new Label();
Label pc = new Label();
Label tu = new Label();
Button b1= new Button();
Button b2= new Button();
Button b3= new Button();
Button start= new Button();
Random r=new Random(); //definisco r come un nuovo oggetto di tipo casuale
int prob=0;
int puntipc=0;
int puntitu=0;
void crea() //tipo di metodo
{
l1.Text="IL FAMOSO GIOCO DELLE TRE CARTE!!!";
l1.Top=20;
l1.Font=new Font("Arial Black",16);
l1.ForeColor=Color.BurlyWood ;
l1.Left=(f1.Width/2)-(l1.Width/2);
l1.AutoSize=true;
l2.Text="REGOLA: L'ASSO VINCE.";
l2.Top=50;
l2.Font=new Font("Arial Black",12);
l2.ForeColor=Color.Red;
l2.Left=(f1.Width/2)+(l2.Width/2);
l2.AutoSize=true;
f1.FormBorderStyle = FormBorderStyle.Fixed3D;
f1.Text="GAME 3 CARTE AUTORE by DARIO AVELLINO";
f1.Width=680;
f1.Height=500;
f1.StartPosition=0;
f1.Location=new Point(150,150);
f1.BackColor=Color.AliceBlue;
b1.Image = Image.FromFile("retro.bmp");
b1.FlatStyle = FlatStyle.Flat;
b1.Height=180;
b1.Width=133;
b1.Top=(f1.Height/2)-(b1.Height/2)-30;
b1.Left=b1.Width-10;
b2.Image = Image.FromFile("retro.bmp");
b2.FlatStyle = FlatStyle.Flat;
b2.Height=180;
b2.Width=133;
b2.Top=(f1.Height/2)-(b1.Height/2)-30;
b2.Left=b1.Width+b2.Width;
b3.Image = Image.FromFile("retro.bmp");
b3.FlatStyle = FlatStyle.Flat;
b3.Height=180;
b3.Width=133;
b3.Top=(f1.Height/2)-(b1.Height/2)-30;
b3.Left=b1.Width+b2.Width+b3.Width+10;
start.Text=" START";
start.Font=new Font("Arial Black",12);
start.BackColor=Color.Green;
start.ForeColor=Color.White;
start.Top=b1.Height+b1.Top+40;
start.Left=(b1.Width+b2.Width+b3.Width+b1.Left)/2+(start.Width/2);
start.AutoSize=true;
start.Click+=new System.EventHandler(abilito);
b1.Click+=new System.EventHandler(caso);
b2.Click+=new System.EventHandler(caso);
b3.Click+=new System.EventHandler(caso);
f1.Closed+=new System.EventHandler(chiudoo);
b1.Enabled=false;
b2.Enabled=false;
b3.Enabled=false;
tu.Text="IL TUO PUNTEGGIO";
tu.BackColor=Color.Yellow;
tu.AutoSize=true;
tu.Left=5;
tu.Top=(f1.Height/2)-(b1.Height/2)-20;
tulb.Left=5;
tulb.Top=tu.Top+tu.Height;
tulb.Width=tu.Width;
tulb.Height+=73;
tulb.ReadOnly=true;
tulb.TextAlign = HorizontalAlignment.Right;
pc.Text="PUNTEGGIO DEL PC";
pc.BackColor=Color.Red;
pc.AutoSize=true;
pc.Left=b1.Width+b2.Width+b3.Width+b1.Left+30;
pc.Top=(f1.Height/2)-(b1.Height/2)-20;
pclb.Left=b1.Width+b2.Width+b3.Width+b1.Left+30;
pclb.Top=pc.Top+pc.Height;
pclb.Width=pc.Width;
pclb.Height+=73;
pclb.ReadOnly=true;
f1.Controls.Add(b1);
f1.Controls.Add(b2);
f1.Controls.Add(b3);
f1.Controls.Add(start);
f1.Controls.Add(l1);
f1.Controls.Add(l2);
f1.Controls.Add(tu);
f1.Controls.Add(pc);
f1.Controls.Add(tulb);
f1.Controls.Add(pclb);
Application.Run(f1);
}
//******//
void abilito(object p, System.EventArgs i)
{
b1.Text=""; b2.Text=""; b3.Text="";
b1.Image = Image.FromFile("retro.bmp");
b2.Image = Image.FromFile("retro.bmp");
b3.Image = Image.FromFile("retro.bmp");
b1.Enabled=true;
b2.Enabled=true;
b3.Enabled=true;
prob=r.Next(3); //eccolaaaaaaa genera un num casuale da 0 a (x-1) dove x è 3
}
void caso(object oravedo, System.EventArgs bu)
{
bool trovato=false;
if((oravedo==b1)&&(prob==0))
{b1.Image = Image.FromFile("asso.bmp"); trovato=true;}
if((oravedo==b2)&&(prob==1))
{b2.Image = Image.FromFile("asso.bmp"); trovato=true;}
if((oravedo==b3)&&(prob==2))
{b3.Image = Image.FromFile("asso.bmp"); trovato=true;}
b1.Enabled=false;
b2.Enabled=false;
b3.Enabled=false;
if(!trovato)
{
b1.Text="TU"; b1.Font=new Font("Arial Black",20);
b2.Text="HAI"; b2.Font=new Font("Arial Black",20);
b3.Text="PERSO"; b3.Font=new Font("Arial Black",20);
puntipc++;
pclb.Text=Convert.ToString(puntipc);
}else{Console.Beep(); puntitu++; tulb.Text=Convert.ToString(puntitu); }
}
void chiudoo(object r, System.EventArgs l)
{
if(puntipc>puntitu){MessageBox.Show("Risultato Partita: Il PC HA VINTO","Stai
Chiudendo!!!!Ciao alla prossima",MessageBoxButtons.OK,
MessageBoxIcon.Information);}
if(puntipc==puntitu){MessageBox.Show("Risultato Partita: PARITA!!!","Stai
Chiudendo!!!!Ciao alla prossima",MessageBoxButtons.OK,
MessageBoxIcon.Information);}
if(puntipc<puntitu){MessageBox.Show("Risultato Partita: HAI VINTO!!Sei un
asso!","Stai Chiudendo!!!!Ciao alla prossima",MessageBoxButtons.OK,
MessageBoxIcon.Information);}
}
public threecart(){crea();} //solito costruttore
}
class prova
{
static void Main()
{
threecart proviamo=new threecart();
}
}