ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash




Script Output:


         




ASP HTML Download            FAQ

Now this is a sample! We let you play games and give you source code. What more could you possibly want. What...what was that from the back? You want a description of how it works. You guys are never satisfied. Okay, here's a quick run down of the highlights:

The first step is we need a way to store the information from page to page (without the player being able to see it!). So we decided to use Session variables. Unfortunately, they're not the fastest thing around, so we read them into variables at the beginning of the page and write them back out at the end. Everywhere in between we use standard page-scoped variables. Next, we're actually using some functions in this sample. We've got some tight loops to do and wanted a little more abstraction than usual since the code is longer and a little less clear than our average sample page. The functions are declared at the top of the page. I know this is a little bit of a touchy subject with some asp scripters. Many like functions at the bottom, others say they should be put in include files for reuse. Well I've always said, you don't use a function till after you've defined it, so at the top they go. (The include file point is a good one, but for a sample, ASP 101's framework wouldn't let you see the code if I did that, so naturally we don't.)

The game logic goes something like this:
1. If you don't pass the page a letter, it assumes you want a new game.
2. A new game gets a random word from the file, resets the variables, and generates an empty guess.
3. When the player chooses a letter, it's checked against the secret word and the appropriate changes are made to the players guess word.
4. If the letter is not in the secret word, we add one to the deadness variable.
5. We check to see if the players dead yet.
6. If they're not, then we check their guess word against the secret word.
7. If they match, the player wins.
8. If they make it to this step, let them guess another letter and go back to step 3.

Besides the functions there are basically 6 logical sections to the code in the page:
1. Declare and retrieve the variables from the Session Object and QueryString.
2. Based on if a letter is given, either set up a new game or check for the guessed letter.
3. Display the gallows based on death level.
4. Display the current guess word.
5. Check to see if dead or if the word is right, and output proper message.
6. Place important variable back into the Session Object.

As always, if you want a better idea of what's going on, check out the code!

Update: Someone suggested we should provide a link to a zip of all the images. So here it is. To download a 25kb zip file containing the images click here.

Samples

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers