-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaseball.html
170 lines (141 loc) · 3.56 KB
/
baseball.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style>
body {
background-color:green;
}
#instructions {
position:absolute;
top:20px;
left:20px;
z-index:10;
}
#bbPlayer {
background-color:blue;
font-size:12px;
position:absolute;
top:500px;
left:550px;
z-index:5;
height:20px;
width:20px;
}
#homeBase {
background-color:black;
font-size:12px;
position:absolute;
top:400px;
left:550px;
z-index:1;
height:40px;
width:40px;
}
#firstBase {
background-color:black;
font-size:12px;
position:absolute;
top:300px;
left:650px;
z-index:1;
height:40px;
width:40px;
}
#secondBase {
background-color:black;
font-size:12px;
position:absolute;
top:200px;
left:550px;
z-index:1;
height:40px;
width:40px;
}
#thirdBase {
background-color:black;
font-size:12px;
position:absolute;
top:300px;
left:450px;
z-index:1;
height:40px;
width:40px;
}
</style>
<script type="text/javascript">
function leftArrowPressed() {
var bbPlayer = document.getElementById("bbPlayer");
bbPlayer.style.left = parseInt(bbPlayer.style.left) - 5 + 'px';
}
function rightArrowPressed() {
var bbPlayer = document.getElementById("image1");
bbPlayer.style.left = parseInt(bbPlayer.style.left) + 5 + 'px';
}
function upArrowPressed() {
var bbPlayer = document.getElementById("image1");
bbPlayer.style.top = parseInt(bbPlayer.style.top) - 5 + 'px';
}
function downArrowPressed() {
var bbPlayer = document.getElementById("image1");
bbPlayer.style.top = parseInt(bbPlayer.style.top) + 5 + 'px';
}
function moveSelection(event) {
switch (event.keyCode) {
case 37:
leftArrowPressed();
break;
case 39:
rightArrowPressed();
break;
case 38:
upArrowPressed();
break;
case 40:
downArrowPressed();
break;
}
function gameLoop()
{
moveSelection();
setTimeout("gameLoop()",10);
}
};
// window.onload = function() {
// var bbPlayer = document.getElementById("bbPlayer");
// window.onkeydown = function(e) {
// e.preventDefault();
// if (!e) {
// e = window.event;
// }
// var keyCode;
// if(e.which) {
// keyCode = e.which;
// } else {
// keyCode = e.keyCode;
// }
// var step = 10;
// if (keyCode === 37) {
// bbPlayer.style.left = (parseInt(bbPlayer.style.left,10) - step) + 'px'; }
// else if (keyCode === 38) {
// bbPlayer.style.top = (parseInt(bbPlayer.style.top,10) - step) + 'px'; }
// else if (keyCode === 39) {
// bbPlayer.style.left = (parseInt(bbPlayer.style.left,10) + step) + 'px'; }
// else if (keyCode === 40) {
// bbPlayer.style.top = (parseInt(bbPlayer.style.top,10) + step) + 'px'; }
// }
// }
</script>
</head>
<body onload="gameLoop();" onkeydown="" onkeyup="moveSelection(event)">
<div id="instructions">
<h1>Lead the blue baseball player around the black bases.</h1>
<h2>Using the Arrow Keys</h2>
</div>
<div id="bbPlayer"></div>
<div id="firstBase"></div>
<div id="secondBase"></div>
<div id="thirdBase"></div>
<div id="homeBase"></div>
</body>
</html>
<!DOCTYPE html>