Note that there are some explanatory texts on larger screens.

plurals
  1. POcoding a tie in tic tac toe
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/10123342/tic-tac-toe-coding-for-tie">tic tac toe coding for tie</a> </p> </blockquote> <p>I have a tic tac toe program and I've got everything working that way it should be. But, the one final problem I am having with this coding is that I can't seem to figure out when there is a tie how to code it. here is what i have so far.</p> <pre><code>Public Class Form1 Private turn As Integer = 1 Private play() As String = {"O", "X"} Private board(2, 2) As String Private Structure arrayIndex Dim x As Integer Dim y As Integer End Structure Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For x As Integer = 1 To 9 Dim b As New Button With { _ .Width = 80, _ .Height = 80, _ .Text = "", _ .Location = New Point(60 + (((x - 1) Mod 3) * 80), 60 + (((x - 1) \ 3) * 80)), _ .Tag = New arrayIndex With {.x = (x - 1) Mod 3, .y = (x - 1) \ 3}} Me.Controls.Add(b) AddHandler b.Click, AddressOf buttons_click Next Me.SetClientSizeCore(360, 360) End Sub Private Sub buttons_click(ByVal sender As System.Object, ByVal e As System.EventArgs) If DirectCast(sender, Button).Text &lt;&gt; "" Then Return DirectCast(sender, Button).Text = play(turn Mod 2) Dim index As arrayIndex = DirectCast(DirectCast(sender, Button).Tag, arrayIndex) board(index.x, index.y) = play(turn Mod 2) turn += 1 winner() End Sub Private Sub winner() Dim rows(7) As String rows(0) = board(0, 0) &amp; board(1, 0) &amp; board(2, 0) rows(1) = board(0, 1) &amp; board(1, 1) &amp; board(2, 1) rows(2) = board(0, 2) &amp; board(1, 2) &amp; board(2, 2) rows(3) = board(0, 0) &amp; board(0, 1) &amp; board(0, 2) rows(4) = board(1, 0) &amp; board(1, 1) &amp; board(1, 2) rows(5) = board(2, 0) &amp; board(2, 1) &amp; board(2, 2) rows(6) = board(0, 0) &amp; board(1, 1) &amp; board(2, 2) rows(7) = board(2, 0) &amp; board(1, 1) &amp; board(0, 2) For x As Integer = 0 To 7 If rows(x).Length = 3 AndAlso (rows(x)(0) = rows(x)(1) AndAlso rows(x)(0) = rows(x)(2)) Then If MessageBox.Show(rows(x)(0) &amp; "'s winsssss!", "We have a winner!", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = DialogResult.OK Then turn = 1 ReDim board(2, 2) For Each ctrl As Control In Controls ctrl.Text = "" Next Return Else Me.Close() End If End If Next End Sub End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload