|
-
May 10th, 2007, 09:51 AM
#1
Thread Starter
New Member
vb tic tac toe
Hey guys im new to vb and im trying to make this game for my class. But im having a little trouble. This is what i have so far and im wondering if you guys could look at it.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim arrgrid(3, 3) As Integer
Dim intwhosturn As Integer
Dim intwhoswinner As Integer
Call initgrid()
Call setdifficulty(difficulty.medium)
intwhosturn = 1
For i As Integer = 0 To 2
For j As Integer = 0 To 2
arrgrid(i, j) = 0
Next
Next
Call DrawGrid()
If arrgrid(0, 0) = 1 Then
Me.lblgrid00.Text = "O"
ElseIf arrgrid(0, 0) = 2 Then
Me.lblgrid00.Text = "X"
Else
Me.lblgrid00.Text = ""
End If
Call GridClick(0, 0)
If (arrgrid(intRow, intCol) = 0) And (intwhoswinner = 0) Then
If intwhosturn = 1 Then
arrgrid(intRow, intCol) = 1
intwhosturn = 2
ElseIf intwhosturn = 2 Then
arrgrid(intRow, intCol) = 2
intwhosturn = 1
End If
Call DrawGrid()
Call CheckWinLose()
If (intwhosturn = 2) And (intwhoswinner = 0) Then
End If
If intwhoswinner = 3 Then
MessageBox.Show("It's a draw")
ElseIf intwhoswinner = 2 Then
MessageBox.Show("You Lose")
ElseIf intwhoswinner = 1 Then
MessageBox.Show("You Win")
End If
Dim intOCount As Integer = 0
Dim intXCount As Integer = 0
Dim intTotalCount As Integer = 0
For i As Integer = 0 To 2
For j As Integer = 0 To 2
If arrgrid(i, j) = 1 Then
intOCount += 1
intTotalCount += 1
End If
If arrgrid(i, j) = 2 Then
intXCount += 1
intTotalCount += 1
End If
Next
If intOCount = 3 Then
intwhoswinner = 1
ElseIf intXCount = 3 Then
intwhoswinner = 2
End If
intOCount = 0
intXCount = 0
Next
If (intTotalCount = 9) And (intwhoswinner = 0) Then
intwhoswinner = 3
Else
intTotalCount = 0
End If
If arrgrid(0, 0) = 1 And arrgrid(1, 1) = 1 And arrgrid(2, 2) = 1 Then
intwhoswinner = 1
ElseIf arrgrid(0, 0) = 2 And arrgrid(1, 1) = 2 And arrgrid(2, 2) = 2 Then
intwhoswinner = 2
ElseIf arrgrid(0, 2) = 1 And arrgrid(1, 1) = 1 And arrgrid(2, 0) = 1 Then
intwhoswinner = 1
ElseIf arrgrid(0, 2) = 2 And arrgrid(1, 1) = 2 And arrgrid(2, 0) = 2 Then
intwhoswinner = 2
End If
End If
-
May 11th, 2007, 07:47 AM
#2
Re: vb tic tac toe
Please format the code. ( using [highlight=vb][/highlight] ).
Then, zip your project up. Not only have you just slapped some code there, it doesn't really do anything. You call about 5 other functions in that part of the code.. what do they do?
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
May 14th, 2007, 02:59 AM
#3
Hyperactive Member
Re: vb tic tac toe
One more thing.... This is not VB code, this is VB.net code!
-
May 15th, 2007, 10:25 AM
#4
Thread Starter
New Member
Re: vb tic tac toe
Im sorry, this is giving me a lot of trouble. I tried to do this using a write up online and thats what I came up with and obviously ran into a bunch of problems. Any help from you guys would be greatly appreciated and do you guys have a code for a simple tic tac toe game that I can look at and try to figure this out.
-
May 16th, 2007, 02:37 AM
#5
Hyperactive Member
Re: vb tic tac toe
Yes.... but I wrote a Tic Tac Toe game about 2 years ago and my coding was terrible. I would not want you to learn from that , just look on the internet for sample code...
-
May 17th, 2007, 09:35 AM
#6
Thread Starter
New Member
Re: vb tic tac toe
Honestly, anything would help right now. As long as it works and I can look at it I would apprepicate it if you could give it to me.
-
May 17th, 2007, 02:12 PM
#7
Hyperactive Member
-
May 18th, 2007, 09:44 AM
#8
Re: vb tic tac toe
Just to get you started with, create a control array of buttons then
Code:
Option Explicit
Dim oClick As Boolean
Private Sub Command1_Click(Index As Integer)
If oClick Then
Command1(Index).Caption = "O"
oClick = False
Else
Command1(Index).Caption = "X"
oClick = True
End If
End Sub
Private Sub Form_Load()
oClick = True
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|