Lesson 1: Setting Up a Game Window

1. Create a folder on your computer for your game.

2. Using your chosen text editor, create a new page and save it inside the folder as index.html

Why index.html?

Using index.html for the main page will allow the URL to not require the filename. For instance, instead of www.myurl.com/index.html users can just use www.myurl.com.

3. Type in all the basic tags for your webpage. If you are using Sublime Text, type html and press tab and these tags will all magically appear!

4. Add a title, add some CSS to make the backround color silver, and throw in some text into the body.

5. Open the index.html file in various web-browsers (Chrome, Firefox, Internet Explorer, Safari, etc..)

If your page does not appear correctly, look over the code carefully. Common errors include misspelling HTML or CSS keywords; missing quotation marks, angle brackets, or close tags; and mixing up () with {} symbols or the : and ; symbols.
The sytax highlighting (coloring of the code) will often help you find the errors you make.
In 1993, Mosaic (the first Web Browser) was released and popularized the World Wide Web.

6. Add a div for the game window. Style the div as you please.



Is the px after the width and height values important?

Very. The 'px' (for pixels) is the unit of measurement. If no unit of measure is given, then the CSS will not work as expected in all browsers.

7. Keep your page open in a web-browser. When you make changes just refresh the page so it updates.

What happened to the "This is my first game!" text?

The text is still there. You just can't see it because the font color is the same as the background color.
Keep the page open in a web-browser so you can refresh the page (instead of re-opening it) each time you update code.

Indent your code!

Proper indentation will ensure that your code is organized, which becomes very important as your code gets larger and more complex.

Use tabs to indent your code, not spaces.
You will also learn that proper indentation of code will greatly reduce the number of errors you make and help you find the mistakes when you make them.

You can indent entire portions of your page by selecting all the code you want to indent and pressing tab. This shifts the entire selection to the right. You can also shift an entire section to the left by using command+shift on a MAC or control+shift on a PC. If your text-editor is not set to allow this, check in the preferences to set it to do so.

Follow these rules for indentation.

If you indent correctly, the end tag should always have the same horizontal alignment as the start tag. For example, the <body> and </body> are both indented one tab.

Use Shortcuts

You will be much more efficient if you use the following shortcut commands:

On a PC, use the Ctrl key instead of Command key. You can also click and drag a selected portion of text to move it to a different location.

Do I have to use shortcuts to Save, Copy, and Paste items?

No. You can Cut, Copy, and Paste using using the menu. However, using shortcuts for these common tasks will save ALOT of time.
In most text editors, you can also move text in your code by highlighting it and then clicking on the highlighted area and dragging it to a new location.


Test Yourself!

1. What CSS property sets the color of the background?
color
bgColor
background-color
backgroundColor
2. What CSS property sets the color of the font?
color
fontColor
font-color
fontColor
3. Which of the following is the shortcut command for Cut?
Command or Ctrl-C
Command or Ctrl-P
Command or Ctrl-Q
Command or Ctrl-X
4. To properly indent code, use which of the following?
Tab
Space Bar
Shift
Return or Enter
5. Which of the following is an HTML element?
gameWindow
div
margin
id
6. Which of the following is an HTML attribute?
gameWindow
div
margin
id
7. Which of the following is a CSS property?
gameWindow
div
margin
id
8. Hyper Text Markup Language (HTML) is primarily for what?
Changing the appearance of webpages
Providing the content of webpages
Providing the functionality of webpages
9. Cascading Style Sheets (CSS) are primarily for what?
Changing the appearance of webpages
Providing the content of webpages
Providing the functionality of webpages
10. JavaScript is primarily for what?
Changing the appearance of webpages
Providing the content of webpages
Providing the functionality of webpages