tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
Go Back  Xtreme Visual Basic Talk > > > tic tac toe game using arrays, strings..


Reply
 
Thread Tools Display Modes
  #1  
Old 01-10-2004, 08:07 PM
jen5533 jen5533 is offline
Newcomer
 
Join Date: Jan 2004
Location: usa
Posts: 8
Question tic tac toe game using arrays, strings..


i'm a beginner to visual basic.net and i've been having difficulties creating a tic tac toe game using arrays, strings, boolean..
i've always wanted to create a game especially something fun like a tic tac toe with two players that keeps the score of the players and the total number of games played.
but it's been difficult trying to figure out the coding for it, because i believe this game requires the use of columns and rows also.
if i won't be able to find the answer to the program coding, then i'll try with something easier. any suggestions? is there an easy game that can be created? or do u know how to create a tic tac toe?
here is what i have so far, but it is just me trying to experience what would it do.
Code:
Dim btnSquareClicked As Button = sender Static chrTTT(2, 2) As Char Static chrPlayer As Char If btnSquareClicked.Text <> Nothing Then MessageBox.Show("Impossible Move") Else btnSquareClicked.Text = chrPlayer If Me.rad1.Checked Then btnSquareClicked.Text = "+" Else btnSquareClicked.Text = "Y" End If Dim strIndex As String strIndex = btnSquareClicked.Tag Dim intX As Integer = Val(strIndex.Chars(0)) Dim intY As Integer = Val(strIndex.Chars(2)) Call StoreMove(intX, intY, chrPlayer, chrTTT) If IsWinner(chrTTT) Then MessageBox.Show("End of the Game!") Else End If End If End Sub Sub StoreMove(ByVal intX As Integer, ByVal intY As Integer, ByVal chrPlayer As Char, ByRef chrTTT(,) As Char) chrTTT(intX, intY) = chrPlayer End Sub Function IsWinner(ByRef chrTTT(,) As Char) As Boolean Dim intRow As Integer For intRow = 0 To 2 If chrTTT(intRow, 0) = chrTTT(intRow, 1) And chrTTT(intRow, 1) = chrTTT(intRow, 2) And (chrTTT(intRow, 1) = chrTTT(intRow, 0) = "0") Then Return True End If Next intRow Dim intCol As Integer For intCol = 0 To 2 If chrTTT(0, intCol) = chrTTT(1, intCol) And chrTTT(1, intCol) = chrTTT(2, intCol) And (chrTTT(0, intCol) = "X" Or chrTTT(0, intCol) = "0") Then Return True End If Next intCol If chrTTT(0, 0) = chrTTT(1, 1) And chrTTT(1, 1) = chrTTT(2, 2) And (chrTTT(0, 0) = "X" Or chrTTT(0, 0) = "0") Then Return True End If Dim blnMovesLeft As Boolean = False For intRow = 0 To 2 For intCol = 0 To 2 If chrTTT(intRow, intCol) = Nothing Then blnMovesLeft = True End If Next intCol Next intRow If Not blnMovesLeft Then Return True End If Return False End Function

Last edited by Iceplug; 01-11-2004 at 07:38 AM.
Reply With Quote
  #2  
Old 01-10-2004, 08:10 PM
jen5533 jen5533 is offline
Newcomer
 
Join Date: Jan 2004
Location: usa
Posts: 8
Question can it be converted to visual basic.net?

and also i found this code from the old visual basic version, i believe it is just the visual basic, not visual studio.net (which i have) is it possible to translate it to visual studiol.net, because it won't understand what this means.
Code:
Dim X As Boolean Dim XNo As Integer Dim ONo As Integer Dim XGame As Integer Dim OGame As Integer Dim TGame As Integer Dim XName As String Dim OName As String Private Sub C1_Click(Index As Integer) If C1(Index).Caption = "" Then If X = True Then C1(Index).Caption = "X" Else C1(Index).Caption = "O" End If X = Not X End If Call CheckResult End Sub Private Sub cmdNG_Click() Dim C As Integer For C = 0 To 8 C1(C).Caption = "" C1(C).BackColor = &HFFC0C0 Next End Sub Public Sub CheckResult() If C1(0).Caption = "X" Then If C1(0).Caption = C1(1).Caption And C1(0).Caption = C1(2).Caption Then C1(0).BackColor = vbBlue C1(1).BackColor = vbBlue C1(2).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(0).Caption = C1(3).Caption And C1(0).Caption = C1(6).Caption Then C1(0).BackColor = vbBlue C1(3).BackColor = vbBlue C1(6).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(0).Caption = C1(4).Caption And C1(0).Caption = C1(8).Caption Then C1(0).BackColor = vbBlue C1(4).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If ElseIf C1(1).Caption = "X" Then If C1(1).Caption = C1(0).Caption And C1(1).Caption = C1(2).Caption Then C1(0).BackColor = vbBlue C1(1).BackColor = vbBlue C1(2).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(1).Caption = C1(4).Caption And C1(1).Caption = C1(7).Caption Then C1(1).BackColor = vbBlue C1(4).BackColor = vbBlue C1(7).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If ElseIf C1(2).Caption = "X" Then If C1(2).Caption = C1(1).Caption And C1(2).Caption = C1(0).Caption Then C1(0).BackColor = vbBlue C1(1).BackColor = vbBlue C1(2).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(2).Caption = C1(5).Caption And C1(2).Caption = C1(8).Caption Then C1(2).BackColor = vbBlue C1(5).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(2).Caption = C1(4).Caption And C1(2).Caption = C1(6).Caption Then C1(2).BackColor = vbBlue C1(4).BackColor = vbBlue C1(6).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If ElseIf C1(3).Caption = "X" Then If C1(3).Caption = C1(4).Caption And C1(3).Caption = C1(5).Caption Then C1(3).BackColor = vbBlue C1(4).BackColor = vbBlue C1(5).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(3).Caption = C1(1).Caption And C1(3).Caption = C1(6).Caption Then C1(1).BackColor = vbBlue C1(3).BackColor = vbBlue C1(6).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If ElseIf C1(4).Caption = "X" Then If C1(4).Caption = C1(0).Caption And C1(4).Caption = C1(8).Caption Then C1(0).BackColor = vbBlue C1(4).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(4).Caption = C1(1).Caption And C1(4).Caption = C1(7).Caption Then C1(1).BackColor = vbBlue C1(4).BackColor = vbBlue C1(7).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(4).Caption = C1(2).Caption And C1(4).Caption = C1(6).Caption Then C1(2).BackColor = vbBlue C1(4).BackColor = vbBlue C1(6).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(4).Caption = C1(3).Caption And C1(4).Caption = C1(5).Caption Then C1(3).BackColor = vbBlue C1(4).BackColor = vbBlue C1(5).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If ElseIf C1(5).Caption = "X" Then If C1(5).Caption = C1(2).Caption And C1(5).Caption = C1(8).Caption Then C1(2).BackColor = vbBlue C1(5).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(5).Caption = C1(3).Caption And C1(5).Caption = C1(4).Caption Then C1(3).BackColor = vbBlue C1(4).BackColor = vbBlue C1(5).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If ElseIf C1(6).Caption = "X" Then If C1(6).Caption = C1(0).Caption And C1(6).Caption = C1(3).Caption Then C1(0).BackColor = vbBlue C1(3).BackColor = vbBlue C1(6).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(6).Caption = C1(2).Caption And C1(6).Caption = C1(4).Caption Then C1(2).BackColor = vbBlue C1(4).BackColor = vbBlue C1(6).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(6).Caption = C1(7).Caption And C1(6).Caption = C1(8).Caption Then C1(6).BackColor = vbBlue C1(7).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If ElseIf C1(7).Caption = "X" Then If C1(7).Caption = C1(1).Caption And C1(7).Caption = C1(4).Caption Then C1(1).BackColor = vbBlue C1(4).BackColor = vbBlue C1(7).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(7).Caption = C1(6).Caption And C1(7).Caption = C1(8).Caption Then C1(6).BackColor = vbBlue C1(7).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If ElseIf C1(8).Caption = "X" Then If C1(8).Caption = C1(2).Caption And C1(8).Caption = C1(5).Caption Then C1(2).BackColor = vbBlue C1(5).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(8).Caption = C1(4).Caption And C1(8).Caption = C1(0).Caption Then C1(0).BackColor = vbBlue C1(4).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click ElseIf C1(8).Caption = C1(6).Caption And C1(8).Caption = C1(7).Caption Then C1(6).BackColor = vbBlue C1(7).BackColor = vbBlue C1(8).BackColor = vbBlue XNo = XNo + 10 XGame = XGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & XName & " is the Winner") Call cmdNG_Click End If End If

p.s. it's too long, i'll post a "continuing" of it next

Last edited by Iceplug; 01-11-2004 at 07:39 AM. Reason: vb tags
Reply With Quote
  #3  
Old 01-10-2004, 08:12 PM
jen5533 jen5533 is offline
Newcomer
 
Join Date: Jan 2004
Location: usa
Posts: 8
Default

here is the rest of the last code:
Code:
If C1(0).Caption = "O" Then If C1(0).Caption = C1(1).Caption And C1(0).Caption = C1(2).Caption Then C1(0).BackColor = vbBlue C1(1).BackColor = vbBlue C1(2).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(0).Caption = C1(3).Caption And C1(0).Caption = C1(6).Caption Then C1(0).BackColor = vbBlue C1(3).BackColor = vbBlue C1(6).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(0).Caption = C1(4).Caption And C1(0).Caption = C1(8).Caption Then C1(0).BackColor = vbBlue C1(4).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If ElseIf C1(1).Caption = "O" Then If C1(1).Caption = C1(0).Caption And C1(1).Caption = C1(2).Caption Then C1(0).BackColor = vbBlue C1(1).BackColor = vbBlue C1(2).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(1).Caption = C1(4).Caption And C1(1).Caption = C1(7).Caption Then C1(1).BackColor = vbBlue C1(4).BackColor = vbBlue C1(7).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If ElseIf C1(2).Caption = "O" Then If C1(2).Caption = C1(1).Caption And C1(2).Caption = C1(0).Caption Then C1(0).BackColor = vbBlue C1(1).BackColor = vbBlue C1(2).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(2).Caption = C1(5).Caption And C1(2).Caption = C1(8).Caption Then C1(2).BackColor = vbBlue C1(5).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(2).Caption = C1(4).Caption And C1(2).Caption = C1(6).Caption Then C1(2).BackColor = vbBlue C1(4).BackColor = vbBlue C1(6).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If ElseIf C1(3).Caption = "O" Then If C1(3).Caption = C1(4).Caption And C1(3).Caption = C1(5).Caption Then C1(3).BackColor = vbBlue C1(4).BackColor = vbBlue C1(5).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(3).Caption = C1(1).Caption And C1(3).Caption = C1(6).Caption Then C1(1).BackColor = vbBlue C1(3).BackColor = vbBlue C1(6).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If ElseIf C1(4).Caption = "O" Then If C1(4).Caption = C1(0).Caption And C1(4).Caption = C1(8).Caption Then C1(0).BackColor = vbBlue C1(4).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(4).Caption = C1(1).Caption And C1(4).Caption = C1(7).Caption Then C1(1).BackColor = vbBlue C1(4).BackColor = vbBlue C1(7).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(4).Caption = C1(2).Caption And C1(4).Caption = C1(6).Caption Then C1(2).BackColor = vbBlue C1(4).BackColor = vbBlue C1(6).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(4).Caption = C1(3).Caption And C1(4).Caption = C1(5).Caption Then C1(3).BackColor = vbBlue C1(4).BackColor = vbBlue C1(5).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If ElseIf C1(5).Caption = "O" Then If C1(5).Caption = C1(2).Caption And C1(5).Caption = C1(8).Caption Then C1(2).BackColor = vbBlue C1(5).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(5).Caption = C1(3).Caption And C1(5).Caption = C1(4).Caption Then C1(3).BackColor = vbBlue C1(4).BackColor = vbBlue C1(5).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If ElseIf C1(6).Caption = "O" Then If C1(6).Caption = C1(0).Caption And C1(6).Caption = C1(3).Caption Then C1(0).BackColor = vbBlue C1(3).BackColor = vbBlue C1(6).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(6).Caption = C1(2).Caption And C1(6).Caption = C1(4).Caption Then C1(2).BackColor = vbBlue C1(4).BackColor = vbBlue C1(6).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(6).Caption = C1(7).Caption And C1(6).Caption = C1(8).Caption Then C1(6).BackColor = vbBlue C1(7).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If ElseIf C1(7).Caption = "O" Then If C1(7).Caption = C1(1).Caption And C1(7).Caption = C1(4).Caption Then C1(1).BackColor = vbBlue C1(4).BackColor = vbBlue C1(7).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(7).Caption = C1(6).Caption And C1(7).Caption = C1(8).Caption Then C1(6).BackColor = vbBlue C1(7).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If ElseIf C1(8).Caption = "O" Then If C1(8).Caption = C1(2).Caption And C1(8).Caption = C1(5).Caption Then C1(2).BackColor = vbBlue C1(5).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(8).Caption = C1(4).Caption And C1(8).Caption = C1(0).Caption Then C1(0).BackColor = vbBlue C1(4).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click ElseIf C1(8).Caption = C1(6).Caption And C1(8).Caption = C1(7).Caption Then C1(6).BackColor = vbBlue C1(7).BackColor = vbBlue C1(8).BackColor = vbBlue ONo = ONo + 10 OGame = OGame + 1 TGame = TGame + 1 MsgBox ("Mr. " & OName & " is the Winner") Call cmdNG_Click End If End If If C1(0).Caption <> "" And C1(1).Caption <> "" And C1(2).Caption <> "" And C1(3).Caption <> "" And C1(4).Caption <> "" And C1(5).Caption <> "" And C1(6).Caption <> "" And C1(7).Caption <> "" And C1(8).Caption <> "" Then TGame = TGame + 1 MsgBox ("No one is the Winner, Draw Game") Call cmdNG_Click End If Label1.Caption = "Mr. " & OName Label2.Caption = "Mr. " & XName Label3.Caption = "Winning Game: " & XGame Label4.Caption = "Winning Game: " & OGame Label5.Caption = "Points: " & XNo Label6.Caption = "Points: " & ONo Label7.Caption = "Total Game Played: " & TGame End Sub

Last edited by Iceplug; 01-11-2004 at 07:39 AM. Reason: vb tags
Reply With Quote
  #4  
Old 01-10-2004, 08:13 PM
CAlex CAlex is offline
Junior Contributor
 
Join Date: Nov 2003
Posts: 373
Default

Quote:
Originally Posted by jen5533

i'll post a "continuing" of it next


no, no more! (by the way, who will read that, you already scared everyone to death)
just post the project or post the part you are having problem with
and use [ vb ] [ /vb ] tags when posting code

Last edited by CAlex; 01-10-2004 at 08:21 PM.
Reply With Quote
  #5  
Old 01-11-2004, 07:44 AM
Iceplug's Avatar
Iceplugtic tac toe game using arrays, strings.. Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Perhaps if you had a specific problem, I could help you, but it looks like you just threw the whole project at me.
In Tic Tac Toe, you have to be able to give (i guess you are giving it a "+" or a "y") symbols. Then, you need to check the 8 combinations of tic tac toe placements to determine who's won the game. Since there are no control arrays in .NET, you'll have to write the code under the 9 areas that hold the + or y and then check the combinations.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #6  
Old 01-11-2004, 09:36 AM
jen5533 jen5533 is offline
Newcomer
 
Join Date: Jan 2004
Location: usa
Posts: 8
Arrow i'm sorry

i apologize for scaring u all like that. here is what my design looks like:

http://www.chasing-dogma.net/oksana/blog/game.jpg

1) it is a game with 2 players, so when u click on one button the x or o show up (given a choice by selecting who goes first, the radio button)
2) when the second time clicking on the another button, the opposite of x or o goes, so if u were x, then second time you click, the o will be on the second button and so on.
3) the score is determined by "if then" statements, so if the 3 buttons across are the same, then that player wins and ..etc. so i thought to make it as rows or arrays, u know like (3,3) 3 by 3?
4) when u "debug" the game, the input boxes show up, saying "type the first player's name, and then the second input box pop up after u type the first player, u have to type the second player. The names show up at the first two blank labels for both players.
4) the score is kept, so if x wins, it will have x has "1" game won
5) there are 10 points each time you win, so if u won 2 games, it will say 20

here is a big question: i am not sure who to make the code. i have the design but no coding. everytime i try something, it goes wrong. should i create an easier game, something that you could help me with? could you help me with creating a simple game?
i've tried everywhere online and no one really knows how to create tic tac toe on visual studio.net so i was very much hoping any one here would. i'll be waiting for reply!
Reply With Quote
  #7  
Old 01-11-2004, 09:45 AM
Iceplug's Avatar
Iceplugtic tac toe game using arrays, strings.. Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Well, how about showing us what you tried? Have you written anything in VB.NET before?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #8  
Old 01-11-2004, 10:55 AM
jen5533 jen5533 is offline
Newcomer
 
Join Date: Jan 2004
Location: usa
Posts: 8
Default

i have written a very few programs, the easy once, only with loops and a couple of text boxes with radio buttons.
here is when i debug it, it gets highlighted yellow and an error occurs. do u know what's wrong:

strIndex = btnSquareClicked.Tag

Dim intX As Integer = Val(strIndex.Chars(0))
Dim int0 As Integer = Val(strIndex.Chars(2))

the beginning of the code, i posted previously.
that is why i'm asking for help, i don't know what's wrong and i've been trying to figure out the problem for the past 2 days.
Reply With Quote
  #9  
Old 01-11-2004, 01:21 PM
jen5533 jen5533 is offline
Newcomer
 
Join Date: Jan 2004
Location: usa
Posts: 8
Default

okay, i started all over, the new code is easier, but it is long, because it repeats for every single button. i used sub for every button and there is 9 of them. otherwise.
i'm trying to figure out how to reset the score that is being kept after the pop up pops up saying who won the game. here is what i have.


Private Sub btn22_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn22.Click
If ClickedSquare(2, 2) = False Then
If PlayerTurn Mod 2 = 0 Then
btn22.Text = "X"
ClickedX(2, 2) = True
PlayerTurn += 1
ElseIf PlayerTurn Mod 2 = 1 Then
btn22.Text = "O"
ClickedO(2, 2) = True
PlayerTurn += 1
End If
ClickedSquare(2, 2) = False
End If
CheckForWinnerX()
CheckForWinnerO()
End Sub

Private Sub CheckForWinnerX()
'Vertical combinations are listed below
If ClickedX(0, 0) And ClickedX(0, 1) And ClickedX(0, 2) Then
PointsX = PointsX + 1
lbl4.Text = "Winning Game: " & PointsX
MessageBox.Show(lbl1.Text & " is the Winner")
ElseIf ClickedX(1, 0) And ClickedX(1, 1) And ClickedX(1, 2) Then
PointsX = PointsX + 1
lbl4.Text = "Winning Game: " & PointsX
MessageBox.Show(lbl1.Text & " is the Winner")
ElseIf ClickedX(2, 0) And ClickedX(2, 1) And ClickedX(2, 2) Then
PointsX = PointsX + 1
lbl4.Text = "Winning Game: " & PointsX
MessageBox.Show(lbl1.Text & " is the Winner")
End If

'u see the above message box, so i'm trying to figure out how to "Call reset" so after the player clicks "okay" on the message box, it will reset the game and the points won, please help me



'Horizontal combinations are listed below

If ClickedX(0, 2) And ClickedX(1, 2) And ClickedX(2, 2) Then
PointsX = PointsX + 1
lbl4.Text = "Winning Game: " & PointsX
MessageBox.Show(lbl1.Text & " is the Winner")
ElseIf ClickedX(0, 1) And ClickedX(1, 1) And ClickedX(2, 1) Then
PointsX = PointsX + 1
lbl4.Text = "Winning Game: " & PointsX
MessageBox.Show(lbl1.Text & " is the Winner")
ElseIf ClickedX(0, 0) And ClickedX(1, 0) And ClickedX(2, 0) Then
PointsX = PointsX + 1
lbl4.Text = "Winning Game: " & PointsX
MessageBox.Show(lbl1.Text & " is the Winner")
End If

'Diagonal combinations are listed below

If ClickedX(0, 2) And ClickedX(1, 1) And ClickedX(2, 0) Then
PointsX = PointsX + 1
lbl4.Text = "Winning Game: " & PointsX
MessageBox.Show(lbl1.Text & " is the Winner")
ElseIf ClickedX(0, 0) And ClickedX(1, 1) And ClickedX(2, 2) Then
PointsX = PointsX + 1
lbl4.Text = "Winning Game: " & PointsX
MessageBox.Show(lbl1.Text & " is the Winner")
End If
End Sub
Reply With Quote
  #10  
Old 01-11-2004, 06:14 PM
Iceplug's Avatar
Iceplugtic tac toe game using arrays, strings.. Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

I think it would be easier just to store the person who clicked in the Tic Tac Toe board, instead of a boolean that determines if a specific user clicked there.
To reset, I would think that you would just need to make a Reset subroutine, move all of those checks that you have there into one If ElseIf chain, and call reset from each block if someone has won.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #11  
Old 01-12-2004, 01:57 PM
Machaira's Avatar
Machairatic tac toe game using arrays, strings.. Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

Since I'm slightly bored, I whipped up the attached. A heck of a lot less code and easier to understand IMO. One thing that is always nice is reducing redundant code by creating functions or organizing the code in such a way as to redundant lines (use loops, arrays, etc). The use of the event handler (set up in the form's constructor) significantly reduces the number of lines of code needed to handle clicking a square. This is one way VB.NET can have control arrays.
Attached Files
File Type: zip TicTacToe.zip (9.2 KB, 56 views)
Reply With Quote
  #12  
Old 01-12-2004, 04:14 PM
jen5533 jen5533 is offline
Newcomer
 
Join Date: Jan 2004
Location: usa
Posts: 8
Default thanks!

okay, i talked to my other people about it and they suggest me to to use shorter programming in the future, it is better programming skills, otherwise the code looks a mess and harder to understand. but because i'm a new to all this, i am not capable of that just yet, but in future i'll make sure to do better programming. i learn something new every day.
unfortunetly your program wouldn't open. i downloaded the zip file and the form1.vb would not open, it says that "it does not exist, it may have been removed, renamed or deleted"

even though, i have finially figured out my own code by 9pm yesterday, which took me about a whole saturday day and sunday, 10 hours. i found the errors and learned my mistakes. i guess it takes patience and a lot of time! i'll get better with time, i'm btw getting a book on vb.net soon!

thanks for your help and understanding. i still wish to look at your game, i'm so curious and to take a look how you coded the game. it'd be nice to get some tips.
Reply With Quote
  #13  
Old 01-13-2004, 07:29 AM
Machaira's Avatar
Machairatic tac toe game using arrays, strings.. Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

Hmm, opens fine for me. You sure you unzipped all the files? Form1 is in the zip file.
Reply With Quote
  #14  
Old 01-14-2004, 04:07 PM
jen5533 jen5533 is offline
Newcomer
 
Join Date: Jan 2004
Location: usa
Posts: 8
Default

yes, i'm sure. it still wouldn't work. i tried opening it again and it has the same sign on the "form1" and the other one.
Reply With Quote
  #15  
Old 01-15-2004, 11:44 AM
Machaira's Avatar
Machairatic tac toe game using arrays, strings.. Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

Weird. What does the zip file show when you open it? If it shows all that shows in the attached screenshot you shouldn't have a problem. Does form1.vb and form1.resx show in the project folder?

Can you open the form1.vb file in Notepad?
Attached Images
File Type: jpg zip.jpg (64.1 KB, 20 views)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
* * * * them arrays of UDTs! Can't strings and doubles live in peace? drunkenmonkey Miscellaneous Languages 2 07-21-2003 12:39 PM
Game Loop Tutorial Optikal Tutors' Corner 0 03-12-2003 11:19 PM
SolarQuest game project jsharbour Game Programming 53 01-10-2003 06:21 PM
Warbirds 1944: Complete WinAPI/DirectX Game jsharbour Game Programming 21 09-10-2002 06:42 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings.. tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
 
tic tac toe game using arrays, strings..
tic tac toe game using arrays, strings..
 
-->