Game Rules

Prevent the alien enemies from hitting your ships!

Languages: Programming, Markup, and Style Sheets

Any app, video game, software, or anything computerized that you've used is controlled by a computer program. Programs can be written in many different programming languages. A programming language is a way for human software developers to write instructions telling the computer what to do. Some popular languages that you may have heard of include:

Websites also use a different kind of language called HTML, which is a type of "markup language." A markup language tells a computer how text should look and act on the screen. For example, we can use HTML to make some text look bold or italic, or to change the text color, or create webpage elements like lists (kind of like our list of programming languages above) or checkboxes. Some common examples of markup languages include:

Websites also use a style sheet language called "Cascading Style Sheets," or "CSS." A style sheet language provides reusable rules for how different markup elements on a webpage should look. Not only are these rules reusable for different elements on different websites, but they also allow developers to separate the styling from the HTML content, which makes everything easier to work with and maintain.

Our game (and this webpage) uses a combination of JavaScript, HTML5, and CSS.

Objects and Object-Oriented Programming

In real life, we can find different examples of objects. An object is a combination of behaviors (an object does something) and information or data (we can describe the characteristics of an object). We can also think of our game (and other programs) in terms of objects. For example, here are some possible objects in the game:

One game object can have effects on other objects in the game. For example, if we defeat one of the enemies, then the score goes up, and so the screen's score text needs to be updated. In other games, if an enemy touches a player, then the player's health might decrease as a result.

Thinking of games and other software this way, in terms of objects and how they interact with each other, is called "object-oriented programming."

Can you think of other possible objects, in this game or other games you like? What are some of their characteristics and behaviors?

Variables

In a program, we use something called variables to store data or information. Each variable has a name and a value. We can choose almost any name we like (within certain restrictions, such as names must start with a letter, all variables names must be unique, and so on, depending on the programming language). You start by “declaring” the variable and then assigning it a value, which basically means you tell the computer you want to store data, and then you give the data a name and a value. From then on, you can use the variable name to access and use or change the value. The “=” sign sets the value for a variable.


So in JavaScript, if we want to create a variable called “weight” and give it a value, we’d do this:
var weight = 120;
We can change the weight to something else (note that if you have already declared the variable, you don’t have to use “var” at the beginning).
weight = 200;
We can use the variable by calling it by its name. For example:
var doubleWeight = 2 * weight;
Data Types

As in real life, we have multiple types of data. Different programming languages have different types. In JavaScript, we have: