Results 1 to 13 of 13

Thread: i, n00b

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Location
    Up ur azz
    Posts
    3

    Lightbulb 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

    =)

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,


    VB Code:
    1. Dim iNum As Integer
    2.  
    3. Public Sub SelectedNumber(strTemp As String)
    4.      CallByName(Me, strTemp, CallType.Method)
    5. End Sub
    6.  
    7.  
    8.  Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    9.         CheckBox1.BackColor = System.Drawing.Color.Blue
    10.         (call randomise sub and store number in iNum)
    11.         SelectedNumbers("sub" & cstr(iNum))
    12.  End Sub
    13.  
    14. Public Sub Sub1()
    15.         CheckBox1.ForeColor=System.Drawing.Color.Red
    16.         CheckResult
    17. End Sub
    18.  
    19. (Repeat this last sub for all 9 numbers.)
    20.  
    21.  
    22. Private Sub CheckResult()
    23.   Select Case True
    24.     Case CheckBox1.ForeColor =System.Drawing.Color.Red
    25.        Select Case True
    26.           Case CheckBox2.ForeColor=System.Drawing.Color.Red
    27.               Select Case True
    28.                 Case CheckBox3.ForeColor =System.Drawing.Color.Red
    29.                    MessageBox.Show("A Winner")
    30.           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.

  3. #3
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    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

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    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...

  5. #5
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    i did not know that about tic tac toe. neat.

  6. #6
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    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.

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    ok you obviously missed my point where i said if whoever goes first plays the OUTER CORNERS... I didn't say anything about playing the center... sure there are plenty of ways to NOT WIN. I said for whatever player goes first there is a guaranteed way for them to win

  8. #8
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    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.

  9. #9
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    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.

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    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

  11. #11
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Taxes, you should change your name to CallByName. That seems to be your answer to every question.

  12. #12
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Originally posted by salvelinus
    Taxes, you should change your name to CallByName. That seems to be your answer to every question.
    lol

  13. #13
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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
  •  



Click Here to Expand Forum to Full Width