Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:41:28+00:00 2026-06-01T23:41:28+00:00

I have a tic tac toe program and I’ve got everything working that way

  • 0

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.

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 <> "" 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) & board(1, 0) & board(2, 0)
    rows(1) = board(0, 1) & board(1, 1) & board(2, 1)
    rows(2) = board(0, 2) & board(1, 2) & board(2, 2)
    rows(3) = board(0, 0) & board(0, 1) & board(0, 2)
    rows(4) = board(1, 0) & board(1, 1) & board(1, 2)
    rows(5) = board(2, 0) & board(2, 1) & board(2, 2)
    rows(6) = board(0, 0) & board(1, 1) & board(2, 2)
    rows(7) = board(2, 0) & board(1, 1) & 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) & "'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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:41:29+00:00Added an answer on June 1, 2026 at 11:41 pm

    One way is that if all of the spaces are full and there is no winner, then there’s a tie.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have been working on a 2 player Tic-Tac-Toe game in java that
I have an assignment to make a Tic-Tac-Toe consol game, but I'm a little
I'm writing a tic tac toe program and i have the board set up,
I'm trying to solve tic-tac-toe with a simple minimax algorithm. Simple, but should cover
I have implemented tic tac toe game as it is from api samples.from that
I am making a complex tic tac toe program that has a variable grid
This is basically a tic tac toe game, and I have another form called
I have read a book and am trying to make a game of tic-tac-toe
I have a tic tac toe game I made, I am not done yet,
I am writing a tic-tac-toe game in Java. I have a 2D array representing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.