Está en la página 1de 2

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 tre
{
public partial class Form1 : Form
{
bool turno = true;
int turno_cont = 0;
public Form1()
{
InitializeComponent();
}

private void acerDeToolStriMenuItem_Click(object sender, EventArgs e)


{
MessageBox.Show("creado por Daniel Ugarte");
}

private void salirToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void button_click(object sender, EventArgs e)


{
Button b = (Button)sender;
if (turno)
b.Text = "X";
else
b.Text = "O";
turno = !turno;
b.Enabled=false;
turno_cont++;

verGanador();
}
//el ganador final es
private void verGanador()
{
bool el_ganador = false;
//HORIZONTAL
if((A1.Text==A2.Text)&&(A2.Text==A3.Text) && (!A1.Enabled))
el_ganador = true;
else if ((B1.Text == B2.Text) && (B2.Text == B3.Text)&&(!B1.Enabled))
el_ganador = true;
else if ((C1.Text == C2.Text) && (C2.Text == C3.Text) && (!C1.Enabled))
el_ganador = true;

//VERTICAL
else if ((A1.Text == B1.Text) && (B1.Text == C1.Text) && (!A1.Enabled))
el_ganador = true;
else if ((A2.Text == B2.Text) && (B2.Text == C2.Text) && (!A2.Enabled))
el_ganador = true;
else if ((A3.Text == B3.Text) && (B3.Text == C3.Text) && (!A3.Enabled))
el_ganador = true;

//DIAGONAL
else if ((A1.Text == B2.Text) && (B2.Text == C3.Text) && (!A1.Enabled))
el_ganador = true;
else if ((A3.Text == B2.Text) && (B2.Text == C1.Text) && (!C1.Enabled))
el_ganador = true;

if (el_ganador)
{
desactivarBotones();

String ganador = "";


if (turno)
ganador = "O";
else
ganador = "X";
MessageBox.Show(ganador+"es el jugador que gana","ganastee!!!");
}
else
{
if(turno_cont==9)
MessageBox.Show("ohh!!Ninguno gana", "Jugadores!!!");
}
}
private void desactivarBotones()
{
try
{
foreach(Control c in Controls)
{
Button b = (Button)c;
b.Enabled = false;
}
}
catch { }
}
}
}

También podría gustarte