-
Notifications
You must be signed in to change notification settings - Fork 0
/
level8.html
200 lines (160 loc) · 4.94 KB
/
level8.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<DOCTYPE! html>
<html>
<head>
<title>Word Unscrambler</title>
<meta charset = "UTF-8">
<link rel = "stylesheet" type = "text/css" href = "level.css">
</head>
<body>
<header id = "top">
<p><span style = "font-size: 2em; position: relative; bottom: 0.18em;">8 !</span></p>
<div style = "text-align: center;">
<p id = "counter" style = "display: inline-block;"> 0 / 25 Words</p>
</div>
<p id = "lives">Lives: 5</p>
</header>
<h1 id = "output"></h1>
<div style = "text-align: center;">
<div id = "letters">
<h2 class = "alpha" onclick = "letter_clk(0);">g</h2>
<h2 class = "alpha" onclick = "letter_clk(1);">n</h2>
<h2 class = "alpha" onclick = "letter_clk(2);">s</h2>
<h2 class = "alpha" onclick = "letter_clk(3);">t</h2>
<h2 class = "alpha" onclick = "letter_clk(4);">i</h2>
</div>
<a id = "level"><input id = "level_button" value = "Next!" type = "button" style = "display: none; margin-top: 1em;" onclick = "next_level();"></input></a>
</div>
<div style = "text-align: center;">
<div id = "buttons">
<input value = "Scramble!" type = "button" onclick = "Scrambler_chck()" class = "clickers"></input>
<input type = "button" value = "Clear!" onclick = "letter_cl();" class = "clickers"></input>
<input value = "Submit!" type = "button" onclick = "word_Submit();" class = "clickers"></input>
</div>
</div>
<script>
word = "";
prev_scramble = "";
counter = 0;
lives = 5;
onhold = 5;
//change onhold to max word length
letter_list = document.getElementsByClassName("alpha");
avails = ["s", "t", "i", "n", "g"];
valid_words = ["sting", "tings", "gins", "gist", "nits", "sign", "sing", "snit", "ting", "tins", "gin", "git", "ins", "its", "nit", "sin", "sit", "tin", "tis", "in", "is", "it", "si", "ti"];
used_words = [];
function letter_clk(i){
word = word + letter_list[i].innerHTML;
letter_list[i].style.visibility = "hidden";
document.getElementById("output").innerHTML = word;
//change x to max word length
for(x = 0; x < 5; x++){
if(letter_list[i].innerHTML == avails[x]){
avails.splice(x, 1);
}
}
onhold--;
}
function letter_cl(){
document.getElementById("output").innerHTML = "";
word = "";
avails = ["s", "t", "i", "n", "g"];
onhold = 5;
//change i to max word length
for(i = 0; i < 5; i++){
letter_list[i].style.visibility = "visible";
}
}
function Scrambler_chck(){
scram_check = 1;
sw1 = 0;
x1 = 0;
while (scram_check == 1){
scram_check = 0;
scrambler = "";
//scrambles the letters
for(i = 0; i < onhold; i++){
random_num = Math.floor(Math.random() * onhold);
holder = avails[i];
avails[i] = avails[random_num];
avails[random_num] = holder;
}
//turns the avail to a word (idk if this is necessary)
for(i = 0; i < onhold; i++){
scrambler = scrambler + avails[i];
}
//checks if scrambled word is a valid word
//change i to num of valid words
for(i = 0; i < 25; i++){
if (scrambler == valid_words[i]){
scram_check = 1;
}
}
//removes duplicates
if (scrambler == prev_scramble){
scram_check = 1;
}
}
//change i to max word length
for(i = 0; i < 5; i++){
sw1 = 0;
//change a to max word length
for(a = 0; a < onhold; a++){
if(letter_list[i].innerHTML == avails[a]){
sw1 = 1;
}
}
if(sw1 == 1){
letter_list[i].innerHTML = avails[x1];
x1++;
}
}
prev_scramble = scrambled;
}
function word_Submit(){
valid_check = 0;
used_check = 0;
//change i to number of valid words
for(i = 0; i < 25; i++){
if (word == valid_words[i]){
valid_check = 1;
}
}
if (valid_check == 1){
if(counter != 0){
for(i = 0; i <= counter - 1; i++){
if (word == used_words[i]){
used_check = 1;
}
}
}
if(used_check == 0){
used_words.push(word);
counter++;
}
}
else{
lives--;
}
//change counter to number of valid words
if (counter == 25 || lives == 0){
document.getElementById("counter").innerHTML = counter + " / 25 Words";
document.getElementById("level_button").style.display = "inline-block";
//change i to max word length
for(i = 0; i < 5; i++){
letter_list[i].style.display = "none";
}
}
document.getElementById("counter").innerHTML = counter + " / 25 Words";
document.getElementById("lives").innerHTML = "Lives: " + lives;
letter_cl();
}
function next_level(){
if (counter == 25){
document.getElementById("level").href = "level8_win.html";
}
if (lives == 0){
document.getElementById("level").href = "level8_lose.html";
}
}
</script>
</body>