forked from bethrobson/Head-First-JavaScript-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobotsGame.html
More file actions
50 lines (40 loc) · 840 Bytes
/
robotsGame.html
File metadata and controls
50 lines (40 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Robots Game</title>
<script>
function Game() {
this.level = 0;
}
Game.prototype.play = function() {
// player plays game here
this.level++;
console.log("Welcome to level " + this.level);
this.unlock();
}
Game.prototype.unlock = function() {
if (this.level === 42) {
Robot.prototype.deployLaser = function () {
console.log(this.name + " is blasting you with laser beams.");
}
}
}
function Robot(name, year, owner) {
this.name = name;
this.year = year;
this.owner = owner;
}
var game = new Game();
var robby = new Robot("Robby", 1956, "Dr. Morbius");
var rosie = new Robot("Rosie", 1962, "George Jetson");
while (game.level < 42) {
game.play();
}
robby.deployLaser();
rosie.deployLaser();
</script>
</head>
<body>
</body>
</html>