User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 455,982 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,776 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 746 | Replies: 2 | Solved
Reply
Join Date: Nov 2007
Posts: 8
Reputation: kidjl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kidjl kidjl is offline Offline
Newbie Poster

Help [urgent] Need Help on my VB6 game

  #1  
Nov 30th, 2007
would some one please help me with this?? i 've got an assigment from my professor which is in a University level (p.s i am still in college, and this class suppose to be the"introduction of programmng") However, in the game we suppose to create a "BlackOut Game", which we have to assign nine game buttons at runtime but not at design-time. I was able to figure out how to display the nine buttons at the runtime, but i could not figure out how to randomize the nine button. i tried to create a random generator(rndGenerator) in the program but i have no idea how to use it so i can randomize all the buttons. could someone give me some ideas?

[code]

Public Class Form1
Const ROWSIZE As Integer = 5
Const COLSIZE As Integer = 5
Dim gameButtons(,) As Button = New Button(ROWSIZE, COLSIZE) {}
Dim mintMoves As Integer = 0
Dim rndGenerator As New Random(System.DateTime.Now.Millisecond)
Dim myRnd As Integer


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim row As Integer
Dim col As Integer
Dim btnWidth As Integer = 70
Dim btnHeight As Integer = 70

'instantiate all the array buttons
For row = 0 To ROWSIZE - 1
For col = 0 To COLSIZE - 1
gameButtons(col, row) = New Button()
'use the Addhandler keyboard to book an event handler
'to an event for each array button
AddHandler gameButtons(col, row).Click, AddressOf ClickHandler
If row >= 1 And row <= 3 And col >= 1 And col <= 3 Then
Me.Controls.Add(gameButtons(col, row))
gameButtons(col, row).Size() = New Size(New Point(btnWidth, btnHeight))
gameButtons(col, row).Location() = New Point((col - 0.8) * btnWidth, (row - 0.8) * btnHeight)
gameButtons(col, row).Name = "btn" + Convert.ToString(col) + "_" + Convert.ToString(row)
gameButtons(col, row).Text = "btn" + Convert.ToString(col) + "_" + Convert.ToString(row)
gameButtons(col, row).BackColor() = Color.Red

End If
Next
Next
End Sub

Public Sub ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
Dim row As Integer
Dim col As Integer
Dim str As String

str = sender.Name
row = str.Substring(3, 1)
col = str.Substring(5, 1)
swapColor(gameButtons(row, col)) 'swap the color of the button
swapColor(gameButtons(row + 1, col)) 'swap the color above
swapColor(gameButtons(row - 1, col)) 'swap the color below
swapColor(gameButtons(row, col + 1)) 'swap the color to the right
swapColor(gameButtons(row, col - 1)) 'swap the color to the left






End Sub
Private Sub swapColor(ByRef button1 As Button)
If button1.BackColor = Color.Red Then
button1.BackColor = Color.White
Else
button1.BackColor = Color.Red
End If
End Sub
End Class
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Posts: 8
Reputation: kidjl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kidjl kidjl is offline Offline
Newbie Poster

Help Re: [urgent] Need Help on my VB6 game

  #2  
Nov 30th, 2007
i am sorry...maybe i didn't not explain my problems very well....so from the diagram below its the diagram for what i created on the vb6 fom1 under the Private form1_load . All of them are at runtime.

0 1 2 3 4
l l l l
----l------l------l------l------
1 l 1 - 1l 2 - 1l 3 - 1l------
----l------l------l------l-----
2 l 1 - 2l 2- 2 l 3- 2 l-----
----l------l------l------l-----
3 l 1- 3 l 2 - 3l 3 - 3l-----
-----l------l------l------l-----
4 l l l l

so the game is basically called "Blackout game"
.In the game when player press a button , then the button that is pressed,and the buttons next to them will swap color. For example, if i all of them have the same BackColor.Red then when i press the button(3-1) then button (3-1), (2-1), and (3-2) swap their backColor to white. And if at the same time i press the button (2-2) then it will result in color swaps on button(2-2)=white , (2-1)=Red ,and (3-2)=Red. Vice versa.

However, i created the statement "Dim rndGenerator As New Random (System. Datetime.Now.Millisecond)" I only know how to swap Integers like below:

[code]
Dim rndNum1 As Integer
Dim rndNum2 As Integer
Dim rndGenerator As new Random(System.Datetime.Now.Millisecond)

rndNum1 = rndGenerator .Next (1, 11)
rndNum2 = rndGenerator . Next (1, 11)
Dim temp as Integer

temp = rndNum1
rndNum1 = rndNum2
rndNum2 = temp

If i want to use this statement in the game i am doing right now, then how should i change it so i can randomize all the BackColors?? Someone please give me some hint~"~
Last edited by kidjl : Nov 30th, 2007 at 10:45 pm. Reason: the scale does not display properly
Reply With Quote  
Join Date: Nov 2007
Posts: 8
Reputation: kidjl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kidjl kidjl is offline Offline
Newbie Poster

Help Re: [urgent] Need Help on my VB6 game

  #3  
Nov 30th, 2007
I am sorry...maybe i didn't not explain my problems very well....so from the diagram below its the diagram for what i created on the vb6 fom1 under the Private form1_load . All of them are at runtime.

0--l--(1)-l--(2)-l--(3)-l--(4)
(0)--l
----l------l------l------l------
(1)--l 1 - 1l 2 - 1l 3 - 1l------
----l------l------l------l-----
(2)--l 1 - 2l 2- 2 l 3- 2 l-----
----l------l------l------l-----
(3)--l 1- 3 l 2 - 3l 3 - 3l-----
-----l------l------l------l-----
(4)--l

so the game is basically called "Blackout game"
.In the game when player press a button , then the button that is pressed,and the buttons next to them will swap color. For example, if i all of them have the same BackColor.Red then when i press the button(3-1) then button (3-1), (2-1), and (3-2) swap their backColor to white. And if at the same time i press the button (2-2) then it will result in color swaps on button(2-2)=white , (2-1)=Red ,and (3-2)=Red. Vice versa.

However, i created the statement "Dim rndGenerator As New Random (System. Datetime.Now.Millisecond)" I only know how to swap Integers like below:

[/code]
Dim rndNum1 As Integer
Dim rndNum2 As Integer
Dim rndGenerator As new Random(System.Datetime.Now.Millisecond)

rndNum1 = rndGenerator .Next (1, 11)
rndNum2 = rndGenerator . Next (1, 11)
Dim temp as Integer

temp = rndNum1
rndNum1 = rndNum2
rndNum2 = temp

If i want to use this statement in the game i am doing right now, then how should i change it so i can randomize all the BackColors?? Someone please give me some hint~"~ sorry to waste the space of replying but #2's diagram is not clear ....hope someone could undersatnd this one..AND IF YOU CAN'T UNDERSTAND I WOULD TRY MY BEST TO EXPLAIN IT TO YOU...SO PLEASE SOMEONE HELP ME!!
Last edited by kidjl : Nov 30th, 2007 at 11:16 pm. Reason: the #2 reply is in the wrong form
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 9:21 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC