 |

01-08-2004, 11:26 AM
|
Newcomer
|
|
Join Date: Jan 2004
Posts: 11
|
|
tick tack toe game
Im makeing a tic tac toe game for fun each spot where u make ur mark is a frame with 2 cmd butons one is x and the other is o then there is lable that when u clikc the command button u click will have th appropriate mark come up. what i want to know is should i use the lbl or sum thin else(what?) and i dotnt know what kind of code i should use to make each command button activate a diff pic.Any and all suggestions are worth while
plz help
Ps what is the code for refreshing a form to its origonal state?

|
|

01-08-2004, 12:51 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
|
|
"the command button "
are you using VB6 or VB.NET?
I would suppose that you can just declare a Boolean variable in your Form class and, in the label's Click event, if this Boolean variable is True, then make an X, otherwise make an O.
Then, invert the Boolean value with the Not operator.
For refreshing a form, just create a new instance of it. 
|
|

01-09-2004, 10:17 AM
|
Newcomer
|
|
Join Date: Jan 2004
Posts: 11
|
|
im using vb 6.0
what do i do to have the 2 differant marks come up and fill the same space?
|
|

01-09-2004, 11:12 AM
|
Junior Contributor
|
|
Join Date: Nov 2003
Posts: 373
|
|
Quote: Originally Posted by zeroflightless1 im using vb 6.0
what do i do to have the 2 differant marks come up and fill the same space?
*confused*
two marks fill up the same space?
like two lines on a circle?
Code:
'if you are using buttons then
private sub command1_click()
if command1.caption="" then
if x then
command1.caption="x"
else
command1.caption="o"
end if
end if
end sub
|
|

01-09-2004, 12:52 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,031
|
|
My personal opinion is that it is better to learn Visual Basic to write a
game, than to write a game to learn Visual Basic.
Start with any of the basic controls and learn what it does and how you
might use it. You can write a simple Tic-Tac-Toe game just using
command buttons, but you may prefer picture boxes, or just drawing
on the form directly.
So start with the basics.
What does a label control do?
What does a picture control do?
What does a command button do?
What methods are available to draw with?
Investigate the Line method, and the Circle method.
How does the MouseDown event handler work, and what can I do with it?
Etc…
Once you know some of the tools, the fun comes in deciding how to
apply them to solve your task.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|

01-09-2004, 03:45 PM
|
Junior Contributor
|
|
Join Date: Nov 2003
Posts: 373
|
|
My personal opinion is that it is better to learn Visual Basic and write programs at the same time, when you have a problem, just ask or search, it's fast, you learn all the practical things, and fun too.
I learned vb like that, and i didn't even have a decent tutorial, but i found a good tutorial recently
http://graphicsmagician.com/vbcourse/index.htm
|
|

01-09-2004, 04:47 PM
|
 |
Junior Contributor
|
|
Join Date: Dec 2003
Location: Surrey, UK
Posts: 309
|
|
Quote: Originally Posted by CAlex My personal opinion is that it is better to learn Visual Basic and write programs at the same time, when you have a problem, just ask or search, it's fast, you learn all the practical things, and fun too.
I learned vb like that, and i didn't even have a decent tutorial, but i found a good tutorial recently
http://graphicsmagician.com/vbcourse/index.htm
I don't think passel was suggesting you didn't write programs while learning if that's that what you were suggesting, just that you didn't write games as even simple games are likely to require a solid understanding of the principles of programming and a good understanding of the language you are writing the game in.
I think the idea is to write programs (otherwise you cannot learn) but keep them simple until you understand the language/control etc that you are using fully.
|
__________________
D'oh
|

03-11-2004, 04:02 AM
|
Newcomer
|
|
Join Date: Mar 2004
Posts: 11
|
|
what luck. I know I'm 4 months late, but I'm sure there will still be beginners reading this now. I was bored too and made a Tic Tac Toe game a couple of nights ago. On the form I have 9 "command buttons", and three labels for keeping track of who's winning. The top three buttons are tagged 00,01,02. Middle Row is 10,11,12. Last Row is 20,21,22. (Row means horizontal for the braindead people out there) Note: this is in Visual Basic .Net. Shouldnt be too much of a problem, but just a warning. Heres the code:
Code:
Windows Form Designer Blah Blah Goes Here
Dim ttt(2, 2) As Char 'this is a global vari
Sub button_handling(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click
Dim temp As Button = sender 'basically creates a copy of the button clicked
Static chrplayer As Char = "x"
If temp.Text <> Nothing Then 'if button has already been selected
Exit Sub
End If
temp.Text = chrplayer
Dim index As String
index = temp.Tag 'gets which button was clicked. Remember, First Row First Button
'is 00, First Row Second Button is 01, so this is an effective way to get which
'button was clicked in a numerical form.
Dim intx As Integer = Val(index.Chars(0))
Dim inty As Integer = Val(index.Chars(1))
storemove(intx, inty, chrplayer, ttt)
If iswinner(ttt) = "x" Then
MessageBox.Show("Winner!")
lblx.Text = lblx.Text + 1
newgame()
Exit Sub
ElseIf iswinner(ttt) = "o" Then
MessageBox.Show("Winner!")
lblo.Text = lblo.Text + 1
newgame()
Exit Sub
Else
isfull(ttt)
If chrplayer = "x" Then
chrplayer = "o"
Else
chrplayer = "x"
End If
End If
End Sub
Sub storemove(ByVal intX As Integer, ByVal intY As Integer, ByVal chrPlayer As Char, ByRef ttt(,) As Char)
ttt(intX, intY) = chrPlayer
End Sub
Function isfull(ByVal ttt(,) As Char) As Boolean
If ttt(0, 0) <> Nothing And ttt(0, 1) <> Nothing And ttt(0, 2) <> Nothing And ttt(1, 0) <> Nothing And ttt(1, 1) <> Nothing And ttt(1, 2) <> Nothing And ttt(2, 0) <> Nothing And ttt(2, 1) <> Nothing And ttt(2, 2) <> Nothing Then
'probably inefficent, but it works.
MsgBox("Tie!")
lblcat.Text = lblcat.Text + 1
newgame()
End If
End Function
Sub newgame()
Button1.Text = Nothing
Button2.Text = Nothing
Button3.Text = Nothing
Button4.Text = Nothing
Button5.Text = Nothing
Button6.Text = Nothing
Button7.Text = Nothing
Button8.Text = Nothing
Button9.Text = Nothing
Dim a As Integer
For a = 0 To 2
ttt(a, 0) = ""
ttt(a, 1) = ""
ttt(a, 2) = ""
Next a
End Sub
Function iswinner(ByRef ttt(,) As Char) As Char
If ttt(0, 0) = "x" And ttt(1, 1) = "x" And ttt(2, 2) = "x" Then
Return "x"
End If
If ttt(0, 0) = "o" And ttt(1, 1) = "o" And ttt(2, 2) = "o" Then
Return "o"
End If
If ttt(0, 0) = "x" And ttt(0, 1) = "x" And ttt(0, 2) = "x" Then
Return "x"
End If
If ttt(0, 0) = "o" And ttt(0, 1) = "o" And ttt(0, 2) = "o" Then
Return "o"
End If
If ttt(1, 0) = "x" And ttt(1, 1) = "x" And ttt(1, 2) = "x" Then
Return "x"
End If
If ttt(1, 0) = "o" And ttt(1, 1) = "o" And ttt(1, 2) = "o" Then
Return "o"
End If
If ttt(2, 0) = "x" And ttt(2, 1) = "x" And ttt(2, 2) = "x" Then
Return "x"
End If
If ttt(2, 0) = "o" And ttt(2, 1) = "o" And ttt(2, 2) = "o" Then
Return "o"
End If
If ttt(2, 0) = "x" And ttt(1, 1) = "x" And ttt(0, 2) = "x" Then
Return "x"
End If
If ttt(2, 0) = "o" And ttt(1, 1) = "o" And ttt(0, 2) = "o" Then
Return "o"
End If
If ttt(0, 0) = "x" And ttt(1, 0) = "x" And ttt(2, 0) = "x" Then
Return "x"
End If
If ttt(0, 0) = "o" And ttt(1, 0) = "o" And ttt(2, 0) = "o" Then
Return "o"
End If
If ttt(0, 1) = "x" And ttt(1, 1) = "x" And ttt(2, 1) = "x" Then
Return "x"
End If
If ttt(0, 1) = "o" And ttt(1, 1) = "o" And ttt(2, 1) = "o" Then
Return "o"
End If
If ttt(0, 2) = "x" And ttt(1, 2) = "x" And ttt(2, 2) = "x" Then
Return "x"
End If
If ttt(0, 2) = "o" And ttt(1, 2) = "o" And ttt(2, 2) = "o" Then
Return "o"
End If
End Function
I know this is probably the most inefficient, bad programming styled, uncommented thing you have ever seen, but hey, its better than nothing right?
|
Last edited by abcdefghijkl; 03-11-2004 at 04:35 AM.
|

03-11-2004, 12:53 PM
|
Newcomer
|
|
Join Date: Feb 2004
Posts: 23
|
|
Well I'm doing the same thing in my visual basic class i'm making it so you drag and drop the X's and O's in desired box dont know if thats what you did but i'll post the code when i finish
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|