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: - 'Project: Tic Tac Toe
-
'Programmer: Paige Mims
-
'Date: 04/20/2007
-
'Description: This project plays Tic Tac Toe.
-
-
Public Class Tictactoe
-
-
Private Sub Random()
-
-
Randomize()
-
Dim RandomClass As New Random() 'Declare RandomClass.Next(0, 17) 'Generates the random number between a range: 0 to 17
-
Dim RandomNumber As Integer
-
'RandomNumber = RandomClass.Next'
-
Randomize()
-
RandomNumber = CInt(Int(Rnd() * 16 + 1))
-
'Seed Random number generator
-
'Initialize the random # generator
-
Dim Board(4, 4) As String
-
-
End Sub
-
Private Sub SetPiece(ByVal Row As Integer, ByVal Column As Integer, ByVal pic As PictureBox)
-
If Board(Row, Column) = Red Or Board(Row, Column) = Blue Then
-
' Do nothing if Red or Blue already in square
-
-
If IsBlue Then
-
Board(Row, Column) = color.blue
-
Me.Text = "Player:" & red
-
Else
-
Board(Row, Column) = color.red
-
Me.Text = "Player:" & blue
-
End If
-
End If
-
End Sub
-
Private Sub Button1_Click(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, Button10.Click, _
-
Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click
-
-
-
sender.Backcolor = Color.Blue
-
-
'Turns a square blue
-
-
If sender.BackColor = Color.Blue Then
-
-
Do
-
-
Select Case sender.backcolor
-
-
Case Is = 1 And Button1.BackColor = Color.Red
-
Button1.BackColor = Color.Blue
-
-
Case Is = 2 And Button2.BackColor = Color.Red
-
Button2.BackColor = Color.Blue
-
-
Case Is = 3 And Button3.BackColor = Color.Red
-
Button3.BackColor = Color.Blue
-
-
Case Is = 4 And Button4.BackColor = Color.Red
-
Button4.BackColor = Color.Blue
-
-
Case Is = 5 And Button5.BackColor = Color.Red
-
Button5.BackColor = Color.Blue
-
-
Case Is = 6 And Button6.BackColor = Color.Red
-
Button6.BackColor = Color.Blue
-
-
Case Is = 7 And Button7.BackColor = Color.Red
-
Button7.BackColor = Color.Blue
-
-
Case Is = 8 And Button8.BackColor = Color.Red
-
Button8.BackColor = Color.Blue
-
-
Case Is = 9 And Button9.BackColor = Color.Red
-
Button9.BackColor = Color.Blue
-
-
Case Is = 10 And Button10.BackColor = Color.Red
-
Button10.BackColor = Color.Blue
-
-
Case Is = 11 And Button11.BackColor = Color.Red
-
Button11.BackColor = Color.Blue
-
-
Case Is = 12 And Button12.BackColor = Color.Red
-
Button12.BackColor = Color.Blue
-
-
Case Is = 13 And Button13.BackColor = Color.Red
-
Button13.BackColor = Color.Blue
-
-
Case Is = 14 And Button14.BackColor = Color.Red
-
Button14.BackColor = Color.Blue
-
-
Case Is = 15 And Button15.BackColor = Color.Red
-
Button15.BackColor = Color.Blue
-
-
Case Is = 16 And Button16.BackColor = Color.Red
-
Button16.BackColor = Color.Blue
-
-
End Select
-
-
Loop Until True
-
-
End If
-
-
End Sub
-
-
-
Private Sub btnReset_Click(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, Button10.Click, _
-
Button11.Click, Button12.Click, Button13.Click, Button14.Click, Button15.Click, Button16.Click
-
-
Button1.BackColor = Color.Gray
-
Button2.BackColor = Color.Gray
-
Button3.BackColor = Color.Gray
-
Button4.BackColor = Color.Gray
-
Button5.BackColor = Color.Gray
-
Button6.BackColor = Color.Gray
-
Button7.BackColor = Color.Gray
-
Button8.BackColor = Color.Gray
-
Button9.BackColor = Color.Gray
-
Button10.BackColor = Color.Gray
-
Button11.BackColor = Color.Gray
-
Button12.BackColor = Color.Gray
-
Button13.BackColor = Color.Gray
-
Button14.BackColor = Color.Gray
-
Button15.BackColor = Color.Gray
-
Button16.BackColor = Color.Gray
-
-
-
-
End Sub
-
End Class
Where have I gone wrong????
3 2788
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?
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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)...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |