473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Tic Tac Toe on a 4x4

I have the task of creating a tic tac toe game on a 4x4 board. It is a one player game with the computer as the opponent. The player (blue) clicks on a button and the computer (red) should automatically select a random positon on the board until there is a win lose or draw. I can't quite figure out how to setup the code for the colors or creating random number selection using this CInt(Int(Rnd() * 16 + 1)). Here is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. 'Project: Tic Tac Toe
  2. 'Programmer: Paige Mims
  3. 'Date: 04/20/2007
  4. 'Description: This project plays Tic Tac Toe.
  5.  
  6. Public Class Tictactoe
  7.  
  8.     Private Sub Random()
  9.  
  10.         Randomize()
  11.         Dim RandomClass As New Random()  'Declare RandomClass.Next(0, 17) 'Generates the random number between a range: 0 to 17 
  12.         Dim RandomNumber As Integer
  13.         'RandomNumber = RandomClass.Next'
  14.         Randomize()
  15.         RandomNumber = CInt(Int(Rnd() * 16 + 1))
  16.         'Seed Random number generator
  17.         'Initialize the random # generator
  18.         Dim Board(4, 4) As String
  19.  
  20.     End Sub
  21.     Private Sub SetPiece(ByVal Row As Integer, ByVal Column As Integer, ByVal pic As PictureBox)
  22.         If Board(Row, Column) = Red Or Board(Row, Column) = Blue Then
  23.             ' Do nothing if Red or Blue already in square
  24.  
  25.             If IsBlue Then
  26.                 Board(Row, Column) = color.blue
  27.                 Me.Text = "Player:" & red
  28.             Else
  29.                 Board(Row, Column) = color.red
  30.                 Me.Text = "Player:" & blue
  31.             End If
  32.         End If
  33.     End Sub
  34.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, _
  35.     Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, _
  36.     Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click
  37.  
  38.  
  39.         sender.Backcolor = Color.Blue
  40.  
  41.         'Turns a square blue
  42.  
  43.         If sender.BackColor = Color.Blue Then
  44.  
  45.             Do
  46.  
  47.                 Select Case sender.backcolor
  48.  
  49.                     Case Is = 1 And Button1.BackColor = Color.Red
  50.                         Button1.BackColor = Color.Blue
  51.  
  52.                     Case Is = 2 And Button2.BackColor = Color.Red
  53.                         Button2.BackColor = Color.Blue
  54.  
  55.                     Case Is = 3 And Button3.BackColor = Color.Red
  56.                         Button3.BackColor = Color.Blue
  57.  
  58.                     Case Is = 4 And Button4.BackColor = Color.Red
  59.                         Button4.BackColor = Color.Blue
  60.  
  61.                     Case Is = 5 And Button5.BackColor = Color.Red
  62.                         Button5.BackColor = Color.Blue
  63.  
  64.                     Case Is = 6 And Button6.BackColor = Color.Red
  65.                         Button6.BackColor = Color.Blue
  66.  
  67.                     Case Is = 7 And Button7.BackColor = Color.Red
  68.                         Button7.BackColor = Color.Blue
  69.  
  70.                     Case Is = 8 And Button8.BackColor = Color.Red
  71.                         Button8.BackColor = Color.Blue
  72.  
  73.                     Case Is = 9 And Button9.BackColor = Color.Red
  74.                         Button9.BackColor = Color.Blue
  75.  
  76.                     Case Is = 10 And Button10.BackColor = Color.Red
  77.                         Button10.BackColor = Color.Blue
  78.  
  79.                     Case Is = 11 And Button11.BackColor = Color.Red
  80.                         Button11.BackColor = Color.Blue
  81.  
  82.                     Case Is = 12 And Button12.BackColor = Color.Red
  83.                         Button12.BackColor = Color.Blue
  84.  
  85.                     Case Is = 13 And Button13.BackColor = Color.Red
  86.                         Button13.BackColor = Color.Blue
  87.  
  88.                     Case Is = 14 And Button14.BackColor = Color.Red
  89.                         Button14.BackColor = Color.Blue
  90.  
  91.                     Case Is = 15 And Button15.BackColor = Color.Red
  92.                         Button15.BackColor = Color.Blue
  93.  
  94.                     Case Is = 16 And Button16.BackColor = Color.Red
  95.                         Button16.BackColor = Color.Blue
  96.  
  97.                 End Select
  98.  
  99.             Loop Until True
  100.  
  101.         End If
  102.  
  103.     End Sub
  104.  
  105.  
  106.     Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, _
  107.     Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button10.Click, _
  108.     Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click
  109.  
  110.         Button1.BackColor = Color.Gray
  111.         Button2.BackColor = Color.Gray
  112.         Button3.BackColor = Color.Gray
  113.         Button4.BackColor = Color.Gray
  114.         Button5.BackColor = Color.Gray
  115.         Button6.BackColor = Color.Gray
  116.         Button7.BackColor = Color.Gray
  117.         Button8.BackColor = Color.Gray
  118.         Button9.BackColor = Color.Gray
  119.         Button10.BackColor = Color.Gray
  120.         Button11.BackColor = Color.Gray
  121.         Button12.BackColor = Color.Gray
  122.         Button13.BackColor = Color.Gray
  123.         Button14.BackColor = Color.Gray
  124.         Button15.BackColor = Color.Gray
  125.         Button16.BackColor = Color.Gray
  126.  
  127.  
  128.  
  129.     End Sub
  130. End Class
Where have I gone wrong????
Apr 20 '07 #1
3 2788
Killer42
8,435 Expert 8TB
I think you need to be more specific about what problems you have in this code. As you've probably gathered by now, not too many people are going to spend their time scouring such a long chunk of code trying to work out what's wrong without a good idea of what they're looking for.

Have you made any more progress yet? Can you give us a better idea of what is wrong? What should be happening, but isn't? Or shouldn't be happening, but is?

For that matter, what version of VB are you using?
Apr 22 '07 #2
To start I am using VB 2005. This game will use colors (red, blue) instead of x and o. When I click a button it should turn blue and then the computer should randomly select a place on the board, which should turn red. I am able to click on a button to get the blue color but I not sure of how to elicit an automatic response from the computer.
Apr 23 '07 #3
Killer42
8,435 Expert 8TB
To start I am using VB 2005. This game will use colors (red, blue) instead of x and o. When I click a button it should turn blue and then the computer should randomly select a place on the board, which should turn red. I am able to click on a button to get the blue color but I not sure of how to elicit an automatic response from the computer.
At least for a "first draft", can't you just call it at the end of the "handle the user click" routine? This will just mean that the computer responds very quickly.
Apr 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.