Advertisement
Guest User

x si 0

a guest
Nov 26th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace x_si_0
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.         bool rand = true; // true = X  ;  false = 0
  20.         int rand_numaratoare = 0;
  21.         private void button_click(object sender, EventArgs e)
  22.         {
  23.             Button b = (Button)sender;
  24.             if (rand)
  25.                 b.Text = "X";
  26.             else
  27.                 b.Text = "0";
  28.             rand = !rand;
  29.             b.Enabled = false;
  30.             rand_numaratoare++;
  31.             VerificaCastigator();
  32.         }
  33.         private void VerificaCastigator()
  34.         {
  35.             bool avem_un_castigator = false;
  36.             //Verificari Orizontale;
  37.             if ((A1.Text == A2.Text) && (A2.Text == A3.Text) && (!A1.Enabled))
  38.                 avem_un_castigator = true;
  39.             else if ((B1.Text == B2.Text) && (B2.Text == B3.Text) && (!B1.Enabled))
  40.                 avem_un_castigator = true;
  41.             else if ((C1.Text == C2.Text) && (C2.Text == C3.Text) && (!C1.Enabled))
  42.                 avem_un_castigator = true;
  43.             //Verificari Oblice;
  44.             else if ((A1.Text == B2.Text) && (B2.Text == C3.Text) && (!A1.Enabled))
  45.                 avem_un_castigator = true;
  46.             else if ((A3.Text == B2.Text) && (B2.Text == C1.Text) && (!A3.Enabled))
  47.                 avem_un_castigator = true;
  48.             //Verificari Verticale
  49.             else if ((A1.Text == B1.Text) && (B1.Text == C1.Text) && (!A1.Enabled))
  50.                 avem_un_castigator = true;
  51.             else if ((A2.Text == B2.Text) && (B2.Text == C2.Text) && (!A2.Enabled))
  52.                 avem_un_castigator = true;
  53.             else if ((A3.Text == B3.Text) && (B3.Text == C3.Text) && (!A3.Enabled))
  54.                 avem_un_castigator = true;
  55.             if (avem_un_castigator)
  56.             {
  57.                 inchide_joc();
  58.                 string castigator = "";
  59.                 if (rand)
  60.                     castigator = "0";
  61.                 else
  62.                     castigator = "X";
  63.                 MessageBox.Show(castigator + " a castigat!", "Sfarsit repriza");
  64.             }
  65.             else
  66.                 if(rand_numaratoare == 9)
  67.                     MessageBox.Show("Egalitate!", "Muie Pasare");
  68.  
  69.         }// Sfarsitul functiei VerificaCastigator();
  70.  
  71.         private void inchide_joc()
  72.         {
  73.             try
  74.             {
  75.                 foreach(Control c in Controls)
  76.                 {
  77.                     Button b = (Button)c;
  78.                     b.Enabled = false;
  79.                 }//End foreach
  80.             }
  81.             catch { }
  82.         }//End inchide_joc
  83.  
  84.         private void iesiAcasToolStripMenuItem_Click(object sender, EventArgs e)
  85.         {
  86.             Application.Exit();
  87.         }
  88.  
  89.         private void jocNouToolStripMenuItem_Click(object sender, EventArgs e)
  90.         {
  91.             rand_numaratoare = 0;
  92.             rand = true;
  93.             try
  94.             {
  95.                 foreach (Control c in Controls)
  96.                 {
  97.                     Button b = (Button)c;
  98.                     b.Enabled = true;
  99.                     b.Text = "";
  100.  
  101.                 }//End foreach
  102.             }
  103.             catch { }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement