Code Question
Code Question
Code Question
Code Question
Code Question
Code Question Code Question Code Question Code Question Code Question Code Question Code Question Code Question
Code Question Code Question
Code Question
Go Back  Xtreme Visual Basic Talk > > > Code Question


Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2005, 09:37 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Question Code Question


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!
Reply With Quote
  #2  
Old 08-09-2005, 10:03 PM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

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.
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #3  
Old 08-10-2005, 12:01 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Angry

Quote:
Originally Posted by John
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.
Reply With Quote
  #4  
Old 08-10-2005, 12:43 PM
lebb's Avatar
lebbCode Question lebb is offline
Disillusioned Code Poet

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Tennessee, USA
Posts: 12,808
Default

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.
__________________
Laura

Ita erat quando hic adveni.
Reply With Quote
  #5  
Old 08-10-2005, 02:47 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Unhappy

Quote:
Originally Posted by lebb
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.
Reply With Quote
  #6  
Old 08-10-2005, 04:05 PM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 336
Default

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

__________________
The Pho·net·ic Programmer
Reply With Quote
  #7  
Old 08-10-2005, 05:34 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Default

*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.)
Reply With Quote
  #8  
Old 08-10-2005, 06:16 PM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 336
Default

these people here will give you professional help,

...and then there is my advice (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.
__________________
The Pho·net·ic Programmer
Reply With Quote
  #9  
Old 08-10-2005, 06:45 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Talking

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.

Quote:
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.
Reply With Quote
  #10  
Old 08-10-2005, 08:53 PM
dan_e6's Avatar
dan_e6 dan_e6 is offline
Contributor
 
Join Date: Mar 2004
Posts: 552
Default

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.
Reply With Quote
  #11  
Old 08-10-2005, 09:15 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Default

That's great! I'll try out some things and see if they work. Be right back.
Reply With Quote
  #12  
Old 08-10-2005, 09:25 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Default

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

Last edited by Dilbert0014; 08-10-2005 at 11:44 PM.
Reply With Quote
  #13  
Old 08-10-2005, 11:49 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Default

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?
Reply With Quote
  #14  
Old 08-11-2005, 09:25 AM
Iceplug's Avatar
IceplugCode Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

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.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #15  
Old 08-11-2005, 03:09 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Default

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"
Reply With Quote
  #16  
Old 08-12-2005, 08:39 AM
Iceplug's Avatar
IceplugCode Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

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.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #17  
Old 08-12-2005, 01:55 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Talking Thank You!!!

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.

Reply With Quote
  #18  
Old 08-12-2005, 11:10 PM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Lightbulb

Quote:
Originally Posted by Dilbert0014
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
Reply With Quote
  #19  
Old 08-13-2005, 03:29 PM
Iceplug's Avatar
IceplugCode Question Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

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.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #20  
Old 08-14-2005, 09:58 AM
Dilbert0014 Dilbert0014 is offline
Freshman
 
Join Date: Aug 2005
Posts: 27
Default

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?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Code Question
Code Question
Code Question Code Question
Code Question
Code Question
Code Question Code Question Code Question Code Question Code Question Code Question Code Question
Code Question
Code Question
 
Code Question
Code Question
 
-->