Advertisement
Brandan

TicTacToe WTF DID I WIN! here figure it out.

Dec 24th, 2011
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 8.72 KB | None | 0 0
  1.   Dim AiTeam = Whosup
  2.     Public Function Did_Any_Player_Win()
  3.         ' This will check all the boxes to see if theres any match
  4.  
  5.         '=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-
  6.         ' ROW SELECTION! ROW 1, ROW 2 ROW 3
  7.  
  8.         ' Row 1
  9.  
  10.         If gameboard_1_1.Text = "X" And gameboard_1_2.Text = "X" And gameboard_1_3.Text = "X" Then
  11.             ' Check if X Won on Row 1
  12.  
  13.             ' Winning text turn yellow
  14.             gameboard_1_1.ForeColor = Color.Yellow
  15.             gameboard_1_2.ForeColor = Color.Yellow
  16.             gameboard_1_3.ForeColor = Color.Yellow
  17.  
  18.             ' announce the winning of X
  19.             Return "WIN X"
  20.         ElseIf gameboard_1_1.Text = "O" And gameboard_1_2.Text = "O" And gameboard_1_3.Text = "O" Then
  21.             ' Check If O Won on row 1
  22.  
  23.             ' Winning text turn yellow
  24.             gameboard_1_1.ForeColor = Color.Yellow
  25.             gameboard_1_2.ForeColor = Color.Yellow
  26.             gameboard_1_3.ForeColor = Color.Yellow
  27.  
  28.             ' announce the winning of O
  29.             Return "WIN O"
  30.         End If
  31.  
  32.         ' Row 2
  33.  
  34.         If gameboard_2_1.Text = "X" And gameboard_2_2.Text = "X" And gameboard_2_3.Text = "X" Then
  35.             ' Check if X Won on Row 2
  36.  
  37.             ' Winning text turn yellow
  38.             gameboard_2_1.ForeColor = Color.Yellow
  39.             gameboard_2_2.ForeColor = Color.Yellow
  40.             gameboard_2_3.ForeColor = Color.Yellow
  41.  
  42.             ' announce the winning of X
  43.             Return "WIN X"
  44.         ElseIf gameboard_2_1.Text = "O" And gameboard_2_2.Text = "O" And gameboard_2_3.Text = "O" Then
  45.             ' Check If O Won on row 2
  46.  
  47.             ' Winning text turn yellow
  48.             gameboard_2_1.ForeColor = Color.Yellow
  49.             gameboard_2_2.ForeColor = Color.Yellow
  50.             gameboard_2_3.ForeColor = Color.Yellow
  51.  
  52.             ' announce the winning of O
  53.             Return "WIN O"
  54.         End If
  55.  
  56.         ' Row 3
  57.  
  58.         If gameboard_3_1.Text = "X" And gameboard_3_2.Text = "X" And gameboard_3_3.Text = "X" Then
  59.             ' Check if X Won on Row 2
  60.  
  61.             ' Winning text turn yellow
  62.             gameboard_3_1.ForeColor = Color.Yellow
  63.             gameboard_3_2.ForeColor = Color.Yellow
  64.             gameboard_3_3.ForeColor = Color.Yellow
  65.  
  66.             ' announce the winning of X
  67.             Return "WIN X"
  68.         ElseIf gameboard_3_1.Text = "O" And gameboard_3_2.Text = "O" And gameboard_3_3.Text = "O" Then
  69.             ' Check If O Won on row 2
  70.  
  71.             ' Winning text turn yellow
  72.             gameboard_3_1.ForeColor = Color.Yellow
  73.             gameboard_3_2.ForeColor = Color.Yellow
  74.             gameboard_3_3.ForeColor = Color.Yellow
  75.  
  76.             ' announce the winning of O
  77.             Return "WIN O"
  78.         End If
  79.  
  80.         ' END ROW CHECKING!
  81.         '=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-
  82.  
  83.         ' COLUM SELECTION! COLUM 1, COLUM 2 COLUM 3
  84.  
  85.         If gameboard_1_1.Text = "X" And gameboard_2_1.Text = "X" And gameboard_3_1.Text = "X" Then
  86.             ' Check if X Won on Colum 1
  87.  
  88.             ' Winning text turn yellow
  89.             gameboard_1_1.ForeColor = Color.Yellow
  90.             gameboard_2_1.ForeColor = Color.Yellow
  91.             gameboard_3_1.ForeColor = Color.Yellow
  92.  
  93.             ' announce the winning of X
  94.             Return "WIN X"
  95.         ElseIf gameboard_1_1.Text = "O" And gameboard_2_1.Text = "O" And gameboard_3_1.Text = "O" Then
  96.             ' Check If O Won on Colum 2
  97.  
  98.             ' Winning text turn yellow
  99.             gameboard_1_1.ForeColor = Color.Yellow
  100.             gameboard_2_1.ForeColor = Color.Yellow
  101.             gameboard_3_1.ForeColor = Color.Yellow
  102.  
  103.             ' announce the winning of O
  104.             Return "WIN O"
  105.         End If
  106.  
  107.         If gameboard_1_2.Text = "X" And gameboard_2_2.Text = "X" And gameboard_3_2.Text = "X" Then
  108.             ' Check if X Won on Colum 2
  109.  
  110.             ' Winning text turn yellow
  111.             gameboard_1_2.ForeColor = Color.Yellow
  112.             gameboard_2_2.ForeColor = Color.Yellow
  113.             gameboard_3_2.ForeColor = Color.Yellow
  114.  
  115.             ' announce the winning of X
  116.             Return "WIN X"
  117.         ElseIf gameboard_1_2.Text = "O" And gameboard_2_2.Text = "O" And gameboard_3_2.Text = "O" Then
  118.             ' Check If O Won on Colum 2
  119.  
  120.             ' Winning text turn yellow
  121.             gameboard_1_2.ForeColor = Color.Yellow
  122.             gameboard_2_2.ForeColor = Color.Yellow
  123.             gameboard_3_2.ForeColor = Color.Yellow
  124.  
  125.             ' announce the winning of O
  126.             Return "WIN O"
  127.         End If
  128.  
  129.         If gameboard_1_3.Text = "X" And gameboard_2_3.Text = "X" And gameboard_3_3.Text = "X" Then
  130.             ' Check if X Won on Colum 3
  131.  
  132.             ' Winning text turn yellow
  133.             gameboard_1_3.ForeColor = Color.Yellow
  134.             gameboard_2_3.ForeColor = Color.Yellow
  135.             gameboard_3_3.ForeColor = Color.Yellow
  136.  
  137.             ' announce the winning of X
  138.             Return "WIN X"
  139.         ElseIf gameboard_1_3.Text = "O" And gameboard_2_3.Text = "O" And gameboard_3_3.Text = "O" Then
  140.             ' Check If O Won on Colum 3
  141.  
  142.             ' Winning text turn yellow
  143.             gameboard_1_3.ForeColor = Color.Yellow
  144.             gameboard_2_3.ForeColor = Color.Yellow
  145.             gameboard_3_3.ForeColor = Color.Yellow
  146.  
  147.             ' announce the winning of O
  148.             Return "WIN O"
  149.         End If
  150.         ' END COLUM CHECKING!
  151.         '=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-
  152.  
  153.         ' Diagonal SELECTION! Diagonal 1, Diagonal 2
  154.  
  155.         If gameboard_1_1.Text = "X" And gameboard_2_2.Text = "X" And gameboard_3_3.Text = "X" Then
  156.             ' Check if X Won on Diagonal 1
  157.  
  158.             ' Winning text turn yellow
  159.             gameboard_1_1.ForeColor = Color.Yellow
  160.             gameboard_2_2.ForeColor = Color.Yellow
  161.             gameboard_3_3.ForeColor = Color.Yellow
  162.  
  163.             ' announce the winning of X
  164.             Return "WIN X"
  165.         ElseIf gameboard_1_1.Text = "O" And gameboard_2_2.Text = "O" And gameboard_3_3.Text = "O" Then
  166.             ' Check If O Won on Diagonal 1
  167.  
  168.             ' Winning text turn yellow
  169.             gameboard_1_1.ForeColor = Color.Yellow
  170.             gameboard_2_2.ForeColor = Color.Yellow
  171.             gameboard_3_3.ForeColor = Color.Yellow
  172.  
  173.             ' announce the winning of O
  174.             Return "WIN O"
  175.         End If
  176.  
  177.         If gameboard_1_3.Text = "X" And gameboard_2_2.Text = "X" And gameboard_3_1.Text = "X" Then
  178.             ' Check if X Won on Diagonal 2
  179.  
  180.             ' Winning text turn yellow
  181.             gameboard_1_3.ForeColor = Color.Yellow
  182.             gameboard_2_2.ForeColor = Color.Yellow
  183.             gameboard_3_1.ForeColor = Color.Yellow
  184.  
  185.             ' announce the winning of X
  186.             Return "WIN X"
  187.         ElseIf gameboard_1_3.Text = "O" And gameboard_2_2.Text = "O" And gameboard_3_1.Text = "O" Then
  188.             ' Check If O Won on Diagonal 2
  189.  
  190.             ' Winning text turn yellow
  191.             gameboard_1_3.ForeColor = Color.Yellow
  192.             gameboard_2_2.ForeColor = Color.Yellow
  193.             gameboard_3_1.ForeColor = Color.Yellow
  194.  
  195.             ' announce the winning of O
  196.             Return "WIN O"
  197.         End If
  198.  
  199.         ' END DIAGONAL CHECKING!
  200.         '=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-
  201.         ' DRAW SELECTION!
  202.  
  203.         If gameboard_1_1.Text = spaces = False Then
  204.             If gameboard_1_2.Text = spaces = False Then
  205.                 If gameboard_1_3.Text = spaces = False Then
  206.                     If gameboard_2_1.Text = spaces = False Then
  207.                         If gameboard_2_2.Text = spaces = False Then
  208.                             If gameboard_2_3.Text = spaces = False Then
  209.                                 If gameboard_3_1.Text = spaces = False Then
  210.                                     If gameboard_3_2.Text = spaces = False Then
  211.                                         If gameboard_3_3.Text = spaces = False Then
  212.                                             Return "DRAW!"
  213.                                         End If
  214.                                     End If
  215.                                 End If
  216.                             End If
  217.                         End If
  218.                     End If
  219.                 End If
  220.             End If
  221.         End If
  222.  
  223.         ' END DRAW CHECKING!
  224.         '=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-
  225.  
  226.         ' IF NO ONE HAS WON yet
  227.         Return "no one won yet"
  228.     End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement