Sams Teach Yourself JavaScript in 24 Hours Free Open Book

Sams Teach Yourself JavaScript in 24 Hours

Previous Page
Next Page

Creating the HTML Document

The HTML document for the game is straightforward. In keeping with the unobtrusive scripting strategies you've learned in previous hours, it contains no JavaScriptjust a <script> tag that imports a script that will handle the game. Similarly, a separate CSS file will be used for styles. Listing 22.1 shows the HTML document.

Listing 22.1. The HTML Document for the Poker Solitaire Game

<html>
<head>
<title>Poker Solitaire</title>
<script language="JavaScript" type="text/javascript"
   src="pokersol.js">
</script>
<link rel="stylesheet" type="text/css" href="pokersol.css">
</head>
<body>
<table>
<tr>
  <td colspan="2"><h1>Poker Solitaire</h1></td>
  <td> <img id="card1" src="blank.gif" height="68" width="53"> </td>
  <td> <img id="card2" src="blank.gif" height="68" width="53"> </td>
  <td> <img id="card3" src="blank.gif" height="68" width="53"> </td>
  <td> <img id="card4" src="blank.gif" height="68" width="53"> </td>
  <td> <img id="card5" src="blank.gif" height="68" width="53"></td>
  <td class="score" id="row0"> </td>
</tr>
<tr>
  <td> <img id="dcard" border="0"
   src="blank.gif" height="68" width="53"></td>
  <td> </td>
  <td> <img id="card6" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card7" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card8" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card9" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card10" src="blank.gif" height="68" width="53"></td>
  <td class="score" id="row1"> </td>
</tr>
<tr>
  <td valign="top" id="status"> Next Card</td>
  <td> </td>
  <td> <img id="card11" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card12" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card13" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card14" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card15" src="blank.gif" height="68" width="53"></td>
  <td class="score" id="row2"> </td>
</tr>
<tr>
  <td id="total"> <b>Total Score:</b>
     <div id="totalscore">0</div></td>
  <td> </td>
  <td> <img id="card16" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card17" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card18" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card19" src="blank.gif" height="68" width="53"></td>
  <td> <img id="card20" src="blank.gif" height="68" width="53"></td>
  <td class="score" id="row3"> </td>
</tr>
<tr>
  <td> <a id="newgame" href="#"><b>Start Over</b></a></td>
  <td> </td>
  <td> <img id="card21" border=0 src="blank.gif" height=68 width=53></td>
  <td> <img id="card22" border=0 src="blank.gif" height=68 width=53></td>
  <td> <img id="card23" border=0 src="blank.gif" height=68 width=53></td>
  <td> <img id="card24" border=0 src="blank.gif" height=68 width=53></td>
  <td> <img id="card25" border=0 src="blank.gif" height=68 width=53></td>
  <td class="score" id="row4"> </td>
</tr>
<tr>
  <td> </td>
  <td class="score" id="diag1"> </td>
  <td class="score" id="col0"> </td>
  <td class="score" id="col1"> </td>
  <td class="score" id="col2"> </td>
  <td class="score" id="col3"> </td>
  <td class="score" id="col4"> </td>
  <td class="score" id="diag2"> </td>
</table>
</body>
</html>

The game board is laid out using an HTML table. Although the game board is five by five squares, the table contains eight columns and six rows. The leftmost column will be used for displaying the next card and the score, as well as a Start Over link. The remaining columns and rows will be used to display the score for each column and row as they are filled with cards.

The 25 spaces on the board are given unique id values, card1 tHRough card25. These will be used by the script to determine which card the user clicks on, and also to replace the appropriate image when a card is placed. The table cells for displaying scores are given the id values row0-4, col0-4, diag1, and diag2.

Save the HTML document in a folder, or download it from this book's website. You can load it into a browser to see the game layout, as shown in Figure 22.2. The game won't be playable until you add the script you'll develop in the next section.

Figure 22.2. The Poker Solitaire game layout.


Previous Page
Next Page
Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][K][L][M][N][O][P][Q][R][S][T][U][V][W][X][Y]


     Main Menu
Sams Teach Yourself JavaScript in 24 Hours
Table of Contents
Copyright
About the Author
Acknowledgments
Part I: Introducing the Concept of Web scripting and the JavaScript Language
Part II: Learning JavaScript Basics
Part III: Learning More About the DOM
Part IV: Working with Advanced JavaScript Features
Part V: Building Multimedia Applications with JavaScript
Part VI: Creating Complex Scripts
Hour 21. Building JavaScript Drop-Down Menus
Hour 22. Creating a JavaScript Game
About the Game
Creating the HTML Document
Creating the Script
Adding Style with CSS
Summary
Q&A
Quiz Questions
Quiz Answers
Exercises
Hour 23. Creating JavaScript Applications
Hour 24. Your Future with JavaScript
Part VII: Appendixes
Index


More Books
PHP Hacks
Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
The Koran (Holy Qur'an)
Macromedia Flash 8 Bible
Search Engine Optimization for Dummies
YouTube Traffic
PHP 5 for Dummies
Harry Potter and The Chamber of Secrets
Harry Potter and the Sorcerer's Stone
The Pilgrim's Progress
Wireless Hacks
Flash Hacks. 100 Industrial-Strength Tips & Tools
PayPal Hacks. 100 Industrial-Strength Tips and Tools
Amazon Hacks
Pdf Hacks
The Da Vinci Code
Google Hacks
The Holy Bible
Windows XP For Dummies
Harry Potter and the Half-Blood Prince
Seo Book
Upgrading and Repairing Networks
Macromedia Dreamweaver 8 UNLEASHED
Windows XP Annoyances
Windows XP Hacks
Microsoft Windows XP Power Toolkit
Teach Yourself MS Office In 24Hours
iPod & iTunes Missing Manual
PC Hacks 100 Industrial-Strength Tips and Tools
PC Overclocking, Optimization, and Tuning - 2th Edition
PC Hardware In A Nutshell 3rd Edition
PC Hardware in a Nutshell, 2nd Edition
Upgrading and Repairing PCs
Google for Dummies
MySQL Cookbook
Teach Yourself Macromedia Flash 8 In 24 Hours
PHP CookBook
Sams Teach Yourself JavaScript in 24 Hours
PHP5 Manual
Free Games Paper Airplanes
500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele