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

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
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.


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



Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer 08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server 08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live