|
-
Jul 22nd, 2004, 08:42 AM
#1
Thread Starter
New Member
i, n00b
im creating a VB.net program that is basically tic-tac-toe. what i want to do is make it so when i click a checkbox, it will change the forecolor to blue and lock it. And then generate a random number between 1-9 and change the color of that # checkbox's forecolor to red, check it, and lock that also (like the computer playing its turn). Once someone gets 3 in a row, a message box should appear that says
Code:
str_winner & "has won the game!"
this is what i have so far
Code:
CheckBox1.BackColor = System.Drawing.Color.Blue
everyone visit my website at
WWW.UGREV.COM
...or else
=)
-
Jul 22nd, 2004, 11:54 AM
#2
PowerPoster
Hi,
VB Code:
Dim iNum As Integer
Public Sub SelectedNumber(strTemp As String)
CallByName(Me, strTemp, CallType.Method)
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
CheckBox1.BackColor = System.Drawing.Color.Blue
(call randomise sub and store number in iNum)
SelectedNumbers("sub" & cstr(iNum))
End Sub
Public Sub Sub1()
CheckBox1.ForeColor=System.Drawing.Color.Red
CheckResult
End Sub
(Repeat this last sub for all 9 numbers.)
Private Sub CheckResult()
Select Case True
Case CheckBox1.ForeColor =System.Drawing.Color.Red
Select Case True
Case CheckBox2.ForeColor=System.Drawing.Color.Red
Select Case True
Case CheckBox3.ForeColor =System.Drawing.Color.Red
MessageBox.Show("A Winner")
Case CheckBox4.ForeColor =System.Drawing.Color.Red
Go on repeating the select case's for each of the 8 directions.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 22nd, 2004, 12:16 PM
#3
Frenzied Member
when you say 'locked' i guess you mean to fix the box so that it can't be checked again? you could use the Enabled property and set it to false which will grey it out. Probably not what you want.
what you SHOULD do, or at least what I would do, is upon the checkbox.click event, check for the CheckState property and if it's checked, don't allow any action. that will keep anyone from unchecking it and not grey it out.
Also, when your AI picks a random number, i'm sure you know this, be sure to NOT include the boxes already checked. there are several ways to go about that also. Such as IF Checked, try to pick again or even in the subroutine that picks the random number, omit any checked boxes.
Just my .02
-
Jul 22nd, 2004, 12:24 PM
#4
also, the AI should not simply be to pick a random number and play its turn in that square. That isn't really AI at all... it should map out the BEST move to make
tic-tac-toe is rigged if you ask me though...
whoe ever goes first will ALWAYS win as long as they play the 3 outer corners
draw a tic tac toe board and play both x and o. which ever goes first, play any 3 outter corners and you will always win...
-
Jul 22nd, 2004, 12:28 PM
#5
Frenzied Member
i did not know that about tic tac toe. neat.
-
Jul 22nd, 2004, 12:32 PM
#6
Frenzied Member
Have O's first move be to put an O in the center and that doesn't hold true.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jul 22nd, 2004, 12:46 PM
#7
-
Jul 22nd, 2004, 01:01 PM
#8
Frenzied Member
Your missing the point. Not if O plays the center, then it is stalemate, X can't win either. X plays outer corner, O plays center. No matter which corner you put an X in now, it's gonna be a stalemate unless O is really really stupid. Try it.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jul 22nd, 2004, 01:05 PM
#9
Frenzied Member
X Bottom Left
O Center
X Upper left
O Middle left
X Middle Right
O Upper Center
X Bottom Center
O Bottom right
Stalemate
X Bottom left
O Center
X Upper Right
O Upper Center
X Bottom Center
O Bottom Right
X Upper left
O Middle Left
Stalemate
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jul 22nd, 2004, 01:08 PM
#10
lol, i thought you meant if you start as first player and play the center. but yeah your right if second player plays the center it will stalemate. so its either first player wins each time, or stalemate each time
so its still a sham
-
Jul 22nd, 2004, 03:44 PM
#11
Frenzied Member
Taxes, you should change your name to CallByName. That seems to be your answer to every question.
-
Jul 22nd, 2004, 03:45 PM
#12
Frenzied Member
Originally posted by salvelinus
Taxes, you should change your name to CallByName. That seems to be your answer to every question.
lol
-
Jul 23rd, 2004, 06:47 AM
#13
PowerPoster
Originally posted by Andy
lol
It's my new toy. I've been looking for something like for that since I lost Macro Substitution in Dbase. You're going to see me use it at every opportunity.
You guys making comments on Tic Tac Toe, it is NEVER possible to guarantee to win, no matter whether you go first or not.
If the first person goes in a corner, the second person MUST go in the opposite corner or the centre. It is ALWAYS possible to force a stalemate.
This is one game at which it is impossible to beat a computer.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
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
|