Code Question

Dilbert0014
08-09-2005, 08:37 PM
I want to make a "Who Wants to be A Millionaire?" game in Visual Basic .NET. Now, the only real problem I have is the LifeLines. I want to allow them to be available only until the user uses them. Then, not have them return for use. Now, I obviously can't just have the LifeLines not appear after a certain page, because, what if the user wants to use them earlier? Do I need to leave out the LifeLines? Or is there some code I can write? Please, look long and hard before telling me to give up!

John
08-09-2005, 09:03 PM
This isn't terribly difficult to do. How long have you been programming?

The way I'd do it is to create a class and use shared members for each life line. Then all your forms and classes can have access to the data. There are a number of other ways as well but not being familiar with your application design this is the first one that comes to mind.

Dilbert0014
08-10-2005, 11:01 AM
This isn't terribly difficult to do. How long have you been programming?

[Enraged]If you must know, all of one week. AND, I HAVE ALREADY FINISHED THE REST OF THE GAME. A total of 3 question sets, and all of them work perfectly. AND, I have already built in timers for answering questions, to make it a bit more challenging. DO NOT MOCK A YOUNG LEARNER![\Enraged]

On the upside, thank you for helping me with my project. Best of luck on whatever you're doing now.

lebb
08-10-2005, 11:43 AM
Dilbert: Please calm down. John was in no way mocking you; he was merely trying to find out your level of expertise so that he could advise you accordingly.

Dilbert0014
08-10-2005, 01:47 PM
Dilbert: Please calm down. John was in no way mocking you; he was merely trying to find out your level of expertise so that he could advise you accordingly.

Yes. Yes, you're right. I apologize. I shouldnt let a simple question like that get me mad. I feel pretty bad. John, I really mean it. I will make it up. When I'm done with my project, I'll post my game for you guys to play. Just don't laugh at me if it's too simple. :o :o :o :o

wolfstrike
08-10-2005, 03:05 PM
making the life lines disappear should be the easy part.

the hard part would be making the questions random and never repeated.

just a simple idea to give you an added headache

:)

Dilbert0014
08-10-2005, 04:34 PM
*Groan* Yes, but I have a way around that (things are so easy when you're a newbie).

At the beginning, when I am done, I will have 5 question sets to choose from. That way, it stays new for a little while. If I could find a way to randomize what question comes next, that would be cool. (Like, the $100 question from Question Set 3, then the $200 from set 4, and the $300 from set 1, etc.)

wolfstrike
08-10-2005, 05:16 PM
these people here will give you professional help,

...and then there is my advice :D (beware)



you can control the lifelines with simple BOOLs,

randomizing questions will be the same technique as shuffling cards, PLUS added categories you wanted.

the trick is to give the questions two parameters,with arrays, such as intQuestion(num) and bolQuestionAsked(num).

then run them through loops.





if you don't understand what mean then finish your game the way you were making it, then tackle each new problem one at a time,

maybe your next program will be a text card shuffling program.

Dilbert0014
08-10-2005, 05:45 PM
All right, I'll finish the game. It's slow going, though. I decided to re-do the entire game with images as links, and during this process, my questions accidentally got deleted! I looked all over the place. Not such a big deal; It's just frustrating to re-do the whole game. Anyhow, I'll report back as I get done with the game.

maybe your next program will be a text card shuffling program.
LOL. After I finish, I'll do that, and make an online poker game for everyone.

By the way: About this lifeline control. Do I put the code for the lifelines under the "Inherits" line in the Public class (right above the Windows Form Designer Generated Code)? 'Cause if it is, I'll just go do that right now, and get an extreme confidence boost. And I'm keeping my word about posting this game.

dan_e6
08-10-2005, 07:53 PM
i made a who wants to be a millionaire game a while ago. i used boolean for the three possible lifelines and just changed them to false when the user had used them. simple stuff.

Dilbert0014
08-10-2005, 08:15 PM
That's great! I'll try out some things and see if they work. Be right back.

Dilbert0014
08-10-2005, 08:25 PM
They don't seem to work. I have the following:

Public Sub

Dim LifeLine1 As Boolean = True

End Sub

Then, later, when a button is clicked:

If LifeLine1 = True Then
[Perform action]
Lifeline1 = False

Dilbert0014
08-10-2005, 10:49 PM
Okay, it works on one page, but not others. Here is a sample of my updated code:

Public Class S1Q1
Inherits System.Windows.Forms.Form
Dim Lifeline1 As Boolean = True

[Visual Basic code]


Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
'50:50 lifeline
If Lifeline1 = True Then
LabelA.Visible = False
LabelC.Visible = False
Lifeline1 = False
End Sub

[Additional Code for other actions]

What's missing, here?

Iceplug
08-11-2005, 08:25 AM
If you have a separate class for each lifeline, then this won't work, and you need to do as John said, with making three Public Shared booleans for the lifelines.

Public Class LifeLines
Public Shared PollTheAudience, FiftyFifty, PhoneAFriend As Boolean
End Class

If Lifelines.PollTheAudience = True
stuff
Lifelines.PollTheAudience = False
End If

P.S. If statements with If SomeBoolean = True Then will work the same (or better) if you drop the = True part... but you can keep it up there if you want it. :)

Dilbert0014
08-11-2005, 02:09 PM
I did that, and now it only works on one page. So, I have:

Public Class LifeLines
Public Shared PollTheAudience, FiftyFifty, PhoneAFriend As Boolean
End Class

If Lifelines.FiftyFifty = True
Label1.Visible = False
Label4.Visible = False
Lifelines.PollTheAudience = False
'These are the available lifelines. They will reappear next time the lifelines are "activated".
L5050L.Visible = False
LPhoneL.Visible = False
LaskAudL.Visible = False
End If

It works! Great! But on the next question, it says "'Lifelines.FiftyFifty' is not declared"

Iceplug
08-12-2005, 07:39 AM
Public Class Lifelines is only accessible from the class or namespace that you declare it in. So if you declare it in S1Q1, you cannot access it from S1Q2.
However, if you take Public Class Lifelines outside of your classes, then you declare it in the namespace and you should be able to access it from all of your classes. :)

Dilbert0014
08-12-2005, 12:55 PM
IT WORKS!!! FINALLY!!! Thanks to all of you for helping a newbie like me, even after I snapped at John. (Again, my apologies, John. Please forgive me.) Anyway, after I finish the rest of the game, I'll start a new thread to ask how to randomize all 4 question sets. (Yes, I know I said 5, but I'm out of room.)

Of course, it will be slow going, because I'm using graphics that should look similar if not identical to the actual game show, and that takes time to set up. This game may be done in about 2-3 weeks as is.

:D :D :D

Dilbert0014
08-12-2005, 10:10 PM
After I finish the rest of the game, I'll start a new thread to ask how to randomize all 4 question sets.

I think I may have it. It seems to work: Let me know if there's a better way. This code is borrowed from MSDN and has been modified.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Random As Integer
Random = CInt(Int(5 * Rnd() + 2))
If Random = 2 Then
Dim Form As New Form2
Form.Show()
ElseIf Random = 3 Then
Dim Form As New Form3
Form.Show()
ElseIf Random = 4 Then
Dim Form As New Form4
Form.Show()
ElseIf Random = 5 Then
Dim Form As New Form5
Form.Show()
End If
End Sub

Iceplug
08-13-2005, 02:29 PM
You generate 5 numbers, but Random = 6 is not accounted for.
Also, if you are going to use more random numbers, then I'd advise using the System.Random class to generate random numbers.

'Declaration
Dim Ri As Random

'Initialization
Ri = New Random

'When you need a random number
Ri.Next(Lowest, LessThan)

So for a random 2, 3, 4, or 5...
the lowest is 2, and all numbers are less than 6.
Ri.Next(2, 6)

The upperbound is the number that is never generated, but all numbers less than it and higher than the lowest can be generated... typically Lowest + countofnumbers.

:)

P.S. If you had accounted for the Random = 6, then the Form.Show() line would be common in all branches of the If and, therefore, could be taken out and moved after the End If.

Dilbert0014
08-14-2005, 08:58 AM
So, you're saying that I need to raise the highest number to 6? After all, I "rolled" twos and fives all the time. I also added the randomize function just above the Random = CInt line after I posted. I haven't had any problems with it; but you are saying there's a more efficient way, it seems, and I don't get it. Can you please go into detail?

Iceplug
08-14-2005, 04:27 PM
Well, what's probably happening is that, when you roll a 6, the code runs through the procedure doing nothing and so you have to click the button again before you actually get a 2, 3, 4, or a 5. So, when you run your program, click the button and, if nothing appears to happen when you click it one time, then I told you so :p.

Better yet, a messagebox to show the value of random after you generate it might help also. :)

Dilbert0014
08-14-2005, 10:28 PM
So. I set the CInt as 2 to 5. I can roll 2,3,4,5,6. Okay, that's wierd. Does that mean with the line with 2 to 5 I can also roll a "1"?

Iceplug
08-15-2005, 06:23 AM
No, the 2 is the lowest number that you can get, and the 5 is number of unique numbers that you will get.

Or, you can say that 2 is the lowest number, and the highest number is (5 + 2 - 1) 6.
:)

http://www.xtremevbtalk.com/showthread.php?t=76270
Random Number Tutorial since you are using the legacy functions.

Dilbert0014
08-15-2005, 09:05 PM
Oh, okay. So "Low" equals lowest number, and "high" equals how many numbers. I get it. Thanks!

Iceplug
08-16-2005, 05:47 AM
No no...
Int(Howmany * Rnd + Low)
in this case, Howmany would be how many numbers and Low means lowest number.

Int((High - Low + 1) * Rnd + Low)
in this case, High is the highest number, and Low is the lowest number.

:)

Dilbert0014
08-18-2005, 03:17 PM
Bleh! I'm such a... newbie!!!

Thanks. I got it now.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum