-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_states.html
144 lines (140 loc) · 4.43 KB
/
game_states.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
<!Doctype html>
<html>
<head>
<title>Name the States</title>
<script type='text/javascript'>
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon','Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia','Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];
var stateAbbreviations = ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE','FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME','MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR','PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT','VT', 'VA','WA', 'WV', 'WI', 'WY'];
var numberOfStates = 0;
var time = 300000;
var gameStarted = false;
var timer;
function focusUp(){
document.getElementById('textInput').focus();
}
function focusOnStart(){
document.getElementById('startButton').focus();
}
function checkForAnswer(){
if(gameStarted)
{
var textContent = (document.getElementById('textInput').value).trim();
document.getElementById('typing').innerHTML = textContent;
if(textContent=='')
document.getElementById('typing').innerHTML = 'Keep Going!';
index = states.indexOf(textContent);
if(index == -1)
{
for(x = 0; x<states.length; x++)
{
if(textContent.toLowerCase() == (states[x]).toLowerCase())
{
textContent = states[x];
index = states.indexOf(textContent);
}
}
}
if(index == -1)
{
index = stateAbbreviations.indexOf(textContent);
}
if(index != -1)
{
document.getElementById('textInput').value = '';
numberOfStates++;
document.getElementById('statesTextVariable').innerHTML = numberOfStates;
document.getElementById('tableOfStates').innerHTML+= "<li>"+states[index]+"</li>";
states.splice(index, 1);
stateAbbreviations.splice(index, 1);
if(numberOfStates==50)
time = -1;
}
}
}
function startClock(){
if(!gameStarted)
timing();
}
function restartClock(){
gameStarted = false;
numberOfStates = 0;
clearTimeout(timer);
time=300000;
document.getElementById('timerID').innerHTML = "5:00";
document.getElementById('statesTextVariable').innerHTML = 0;
document.getElementById('tableOfStates').innerHTML = [];
}
function timing(){
gameStarted = true
time = time - 1000;
timer = setTimeout("changeTime()", 1000);
}
function changeTime(){
if(time==-1)
{
wonGame();
}
else
{
if(time%60000/1000 < 10)
{
document.getElementById('timerID').innerHTML = Math.floor(time/60000) + ':0' + (time%60000/1000);
}
else
{
document.getElementById('timerID').innerHTML = Math.floor(time/60000) + ':' + (time%60000/1000);
}
if(time>0)
timing(time);
else
{
document.getElementById("timerID").innerHTML = '0:00';
lostGame();
}
}
}
function wonGame(){
alert("You Win!");
}
function lostGame(){
alert("Too Bad, You Lose!");
}
function endGame(){
alert("Game Restarted");
restartClock();
}
</script>
<style>
#centered {
text-align: center;
color: red;
font-family: arial;
font-size: 250%;
font-style: bold;
}
#input{
text-align: center;
}
#tableOfStates{
color: green;
position: absolute;
left: 650px;
font-size: 125%;
font-family:impact;
}
</style>
</head>
<body onLoad="focusOnStart();">
<div id = "centered">Name the 50 States</div>
<div id="input">
<input type = text align = center id = 'textInput' oninput = "checkForAnswer(); startClock();">
<button id = 'startButton' onClick = 'startClock(); focusUp();' accessKey = s><u>S</u>tart</button>
<button id = 'endButton' onclick="endGame();">End</button>
<p id = "typing">Start!</p>
<p id = "numberOfStatesText">Number of States: <span id = 'statesTextVariable'>0</span></p>
<p id = "timerID">5:00</p>
</div>
<ol id = 'tableOfStates'>
</ol>
</body>
</html>