Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 x_si_0
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- bool rand = true; // true = X ; false = 0
- int rand_numaratoare = 0;
- private void button_click(object sender, EventArgs e)
- {
- Button b = (Button)sender;
- if (rand)
- b.Text = "X";
- else
- b.Text = "0";
- rand = !rand;
- b.Enabled = false;
- rand_numaratoare++;
- VerificaCastigator();
- }
- private void VerificaCastigator()
- {
- bool avem_un_castigator = false;
- //Verificari Orizontale;
- if ((A1.Text == A2.Text) && (A2.Text == A3.Text) && (!A1.Enabled))
- avem_un_castigator = true;
- else if ((B1.Text == B2.Text) && (B2.Text == B3.Text) && (!B1.Enabled))
- avem_un_castigator = true;
- else if ((C1.Text == C2.Text) && (C2.Text == C3.Text) && (!C1.Enabled))
- avem_un_castigator = true;
- //Verificari Oblice;
- else if ((A1.Text == B2.Text) && (B2.Text == C3.Text) && (!A1.Enabled))
- avem_un_castigator = true;
- else if ((A3.Text == B2.Text) && (B2.Text == C1.Text) && (!A3.Enabled))
- avem_un_castigator = true;
- //Verificari Verticale
- else if ((A1.Text == B1.Text) && (B1.Text == C1.Text) && (!A1.Enabled))
- avem_un_castigator = true;
- else if ((A2.Text == B2.Text) && (B2.Text == C2.Text) && (!A2.Enabled))
- avem_un_castigator = true;
- else if ((A3.Text == B3.Text) && (B3.Text == C3.Text) && (!A3.Enabled))
- avem_un_castigator = true;
- if (avem_un_castigator)
- {
- inchide_joc();
- string castigator = "";
- if (rand)
- castigator = "0";
- else
- castigator = "X";
- MessageBox.Show(castigator + " a castigat!", "Sfarsit repriza");
- }
- else
- if(rand_numaratoare == 9)
- MessageBox.Show("Egalitate!", "Muie Pasare");
- }// Sfarsitul functiei VerificaCastigator();
- private void inchide_joc()
- {
- try
- {
- foreach(Control c in Controls)
- {
- Button b = (Button)c;
- b.Enabled = false;
- }//End foreach
- }
- catch { }
- }//End inchide_joc
- private void iesiAcasToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void jocNouToolStripMenuItem_Click(object sender, EventArgs e)
- {
- rand_numaratoare = 0;
- rand = true;
- try
- {
- foreach (Control c in Controls)
- {
- Button b = (Button)c;
- b.Enabled = true;
- b.Text = "";
- }//End foreach
- }
- catch { }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement