Can someone give some advice on this Tic tac toe game i'm trying to make with vb, it would be greatly appreciated. I am a total newb, and I know this code is probably terrible, I'm just trying to do what I know and see if I can make some decent progress. Here's what I have, but I haven't come that far :\
I can't really figure out how to display the coordinates that the user inputs, into the grid. I want to be able to display the grid, have the user enter a coordinate, display a new grid with that coordinate, have the computer generate a coordinate in a new grid with the users coordinate displayed too and repeat until a win or tie.

Any advice would be greatly appreciated.

Module Module1
Dim r As Integer
Dim c As Integer
Dim score(2, 2) As Integer
Sub Main()
Dim UserNum(2, 2) As Integer
Dim CompNum(2, 2) As Integer

Console.WriteLine("Tic-Tac-Toe")
displayGrid(UserNum, CompNum)
End Sub



Sub displayGrid(ByRef UserNum(,) As Integer, ByRef CompNum(,) As Integer)
Dim win As Boolean
Dim check As Boolean
Dim computer As Boolean
Console.WriteLine(" | | ")
Console.WriteLine("-------")
Console.WriteLine(" | | ")
Console.WriteLine("-------")
Console.WriteLine(" | | ")
Do
Do
UserNum(2, 2) = inputUser(UserNum)
Console.WriteLine(" " & UserNum(0, 0) & " | " & UserNum(0, 1) & " | ")
Console.WriteLine("-------")
Console.WriteLine(" | | ")
Console.WriteLine("-------")
Console.WriteLine(" | | ")
Console.ReadKey()
CompNum(2, 2) = inputComputer(CompNum)
check = alreadyTaken(UserNum, CompNum)
If check = False Then
Console.WriteLine("Section aready used. Try again")
End If
Loop Until check = True
If win = True Then
Console.WriteLine("You have won!")
Else
Console.WriteLine("You lost")
End If


For i = 0 To 2
If UserNum(i, 0) = UserNum(i, 1) And UserNum(i, 0) = UserNum(i, 0) Then
win = True
End If
Next
For j = 0 To 2
If UserNum(0, j) = UserNum(1, j) And UserNum(0, j) = UserNum(2, j) Then
win = True
End If
Next
If UserNum(0, 0) = UserNum(1, 1) And UserNum(1, 1) = UserNum(2, 2) Then
win = True
End If
If UserNum(0, 2) = UserNum(1, 1) And UserNum(1, 1) = UserNum(2, 0) Then
win = True
End If

For i = 0 To 2
If CompNum(i, 0) = CompNum(i, 1) And CompNum(i, 0) = CompNum(i, 0) Then
computer = True
End If
Next
For j = 0 To 2
If UserNum(0, j) = CompNum(1, j) And CompNum(0, j) = CompNum(2, j) Then
computer = True
End If
Next
If CompNum(0, 0) = CompNum(1, 1) And CompNum(1, 1) = CompNum(2, 2) Then
computer = True
End If
If CompNum(0, 2) = CompNum(1, 1) And CompNum(1, 1) = CompNum(2, 0) Then
computer = True
End If

Loop Until win = True Or computer = True


End Sub

Function inputUser(ByRef UserNum(,) As Integer)
Dim r As Integer
Dim c As Integer
Console.Write("Row:")
UserNum(r, 0) = Console.ReadLine()
Console.Write("Column:")
UserNum(0, c) = Console.ReadLine()
Return UserNum(c, r)
End Function


Function inputComputer(ByRef CompNum(,) As Integer)
Dim r As Integer
Dim c As Integer
Dim high As Integer = 10
Dim low As Integer = 1
Dim rand As Integer
r = rand = Int((high - low + 1) * Rnd()) + low
CompNum(0, r) = 2
c = rand = Int((high - low + 1) * Rnd()) + low
CompNum(c, 0) = 2
Return CompNum(c, r)
End Function

Function alreadyTaken(ByRef CompNum(,) As Integer, ByRef UserNum(,) As Integer)
Dim check As Boolean
If CompNum(r, c) = UserNum(r, c) Then
check = False
Else
check = True
End If
Return check
End Function
End Module

For doing console-style applications, VB is probably not your best choice. Perhaps one of the legacy BASIC implementations (such as QuickBASIC) or FreeBasic would be better suited for what you are trying to do.

However, if you are looking to learn VB (instead of having your heart set on a particular programming project like TicTacToe) you might consider one of the many tutorial sites out there (google it...there are hundreds) or perhaps get a beginners book. That will give you a better feel for what the language is good at. Then when you've got a better idea of VB's strengths you can try a different approach to implement your game (I can think of a couple of ideas using forms and textboxes, or some of the graphics shapes, or grids, there are lots of possibilities).

Good searching! I hope you find some useful stuff.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.