Tic tac toe code

2,193 views

Published on

codigo del gato

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,193
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
73
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Tic tac toe code

  1. 1. Public Class Form1Dim navegador As String = "x"Dim contadorx As Integer = 0Dim contadory As Integer = 0Dim gatitodetector As Integer = 0Public Function xoy(ByVal nav As String)If nav = "x" Thennavegador = "0"Return "x"Elsenavegador = "x"Return "0"End IfEnd FunctionPublic Sub ganarX()gatitodetector += 1If Button1.Text = "x" And Button2.Text = "x" And Button3.Text = "x" ThenMsgBox("X gana este juego.", MsgBoxStyle.Information, " X Wins. ")endofgame()ElseIf Button4.Text = "x" And Button5.Text = "x" And Button6.Text = "x"ThenMsgBox("X gana este juego.", MsgBoxStyle.Information, " X Wins. ")endofgame()ElseIf Button7.Text = "x" And Button8.Text = "x" And Button9.Text = "x"ThenMsgBox("X gana este juego.", MsgBoxStyle.Information, " X Wins. ")endofgame()ElseIf Button1.Text = "x" And Button4.Text = "x" And Button7.Text = "x"ThenMsgBox("X gana este juego.", MsgBoxStyle.Information, " X Wins. ")endofgame()ElseIf Button2.Text = "x" And Button5.Text = "x" And Button8.Text = "x"ThenMsgBox("X gana este juego.", MsgBoxStyle.Information, " X Wins. ")endofgame()ElseIf Button3.Text = "x" And Button6.Text = "x" And Button9.Text = "x"ThenMsgBox("X gana este juego.", MsgBoxStyle.Information, " X Wins. ")endofgame()ElseIf Button1.Text = "x" And Button5.Text = "x" And Button9.Text = "x"ThenMsgBox("X gana este juego.", MsgBoxStyle.Information, " X Wins. ")endofgame()ElseIf Button3.Text = "x" And Button5.Text = "x" And Button7.Text = "x"ThenMsgBox("X gana este juego.", MsgBoxStyle.Information, " X Wins. ")endofgame()End Ifganar0()End SubPublic Sub ganar0()If Button1.Text = "0" And Button2.Text = "0" And Button3.Text = "0" ThenMsgBox("0 gana este juego.", MsgBoxStyle.Information, " 0 Wins. ")endofgame2()ElseIf Button4.Text = "0" And Button5.Text = "0" And Button6.Text = "0"ThenMsgBox("0 gana este juego.", MsgBoxStyle.Information, " 0 Wins. ")endofgame2()ElseIf Button7.Text = "0" And Button8.Text = "0" And Button9.Text = "0"ThenMsgBox("0 gana este juego.", MsgBoxStyle.Information, " 0 Wins. ")endofgame2()ElseIf Button1.Text = "0" And Button4.Text = "0" And Button7.Text = "0"Then
  2. 2. MsgBox("0 gana este juego.", MsgBoxStyle.Information, " 0 Wins. ")endofgame2()ElseIf Button2.Text = "0" And Button5.Text = "0" And Button8.Text = "0"ThenMsgBox("0 gana este juego.", MsgBoxStyle.Information, " 0 Wins. ")endofgame2()ElseIf Button3.Text = "0" And Button6.Text = "0" And Button9.Text = "0"ThenMsgBox("0 gana este juego.", MsgBoxStyle.Information, " 0 Wins. ")endofgame2()ElseIf Button1.Text = "0" And Button5.Text = "0" And Button9.Text = "0"ThenMsgBox("0 gana este juego.", MsgBoxStyle.Information, " 0 Wins. ")endofgame2()ElseIf Button3.Text = "0" And Button5.Text = "0" And Button7.Text = "0"ThenMsgBox("0 gana este juego.", MsgBoxStyle.Information, " 0 Wins. ")endofgame2()ElseIf gatitodetector = 9 ThenMsgBox(" Nadie gana este juego.", MsgBoxStyle.Information, " Nadiegana")gatitodetector = 0End IfEnd SubPublic Sub endofgame()Button1.Enabled = FalseButton2.Enabled = FalseButton3.Enabled = FalseButton4.Enabled = FalseButton5.Enabled = FalseButton6.Enabled = FalseButton7.Enabled = FalseButton8.Enabled = FalseButton9.Enabled = Falsecontadorx += 1gatitodetector = 0lblContadorX.Text = contadorx.ToStringEnd SubPublic Sub endofgame2()Button1.Enabled = FalseButton2.Enabled = FalseButton3.Enabled = FalseButton4.Enabled = FalseButton5.Enabled = FalseButton6.Enabled = FalseButton7.Enabled = FalseButton8.Enabled = FalseButton9.Enabled = Falsecontadory += 1gatitodetector = 0lblContadorY.Text = contadory.ToStringEnd SubPublic Sub resetiar()Button1.Enabled = TrueButton2.Enabled = TrueButton3.Enabled = TrueButton4.Enabled = TrueButton5.Enabled = TrueButton6.Enabled = TrueButton7.Enabled = TrueButton8.Enabled = TrueButton9.Enabled = TrueButton1.Text = ""Button2.Text = ""
  3. 3. Button3.Text = ""Button4.Text = ""Button5.Text = ""Button6.Text = ""Button7.Text = ""Button8.Text = ""Button9.Text = ""End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.ClickButton1.Text = xoy(navegador)Button1.Enabled = FalseganarX()End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.ClickButton2.Text = xoy(navegador)Button2.Enabled = FalseganarX()End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button3.ClickButton3.Text = xoy(navegador)Button3.Enabled = FalseganarX()End SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button4.ClickButton4.Text = xoy(navegador)Button4.Enabled = FalseganarX()End SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button5.ClickButton5.Text = xoy(navegador)Button5.Enabled = FalseganarX()End SubPrivate Sub Button6_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button6.ClickButton6.Text = xoy(navegador)Button6.Enabled = FalseganarX()End SubPrivate Sub Button7_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button7.ClickButton7.Text = xoy(navegador)Button7.Enabled = FalseganarX()End SubPrivate Sub Button8_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button8.ClickButton8.Text = xoy(navegador)Button8.Enabled = FalseganarX()End Sub
  4. 4. Private Sub Button9_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button9.ClickButton9.Text = xoy(navegador)Button9.Enabled = FalseganarX()End SubPrivate Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVale As System.EventArgs) Handles ExitToolStripMenuItem.ClickMe.Close()End SubPrivate Sub NewGaToolStripMenuItem_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles NewGaToolStripMenuItem.Clickresetiar()gatitodetector = 0End SubEnd Class

×