-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman.html
176 lines (173 loc) · 4.94 KB
/
hangman.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
<html>
<head>
<title></title>
<script src = "js/jQuery.js"></script>
<style type = "text/css">
#images {position: relative;margin-left: 40%;}
img {width: 350px;height: 350px;}
#guesses {position:relative;margin-left:41%;border:2px solid #1E5799;width:300px;height:200px;text-align:center;font-family:Courier;background: #1e5799; /* Old browsers */
background: -moz-linear-gradient(top, #1e5799 0%, #7db9e8 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* IE10+ */
background: linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
border-radius:5px;
}
#guessed {border: 2px solid #1E5799;width:300px;height:200px;position:absolute;text-align:center;background: #1e5799; /* Old browsers */
background: -moz-linear-gradient(top, #1e5799 0%, #7db9e8 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* IE10+ */
background: linear-gradient(top, #1e5799 0%,#7db9e8 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0 ); /* IE6-9 */
border-radius:5px;
}
input {
border: 2px solid
black;
padding-left: 5px;
width: 150px;
line-height: 25px;
border-radius: 4px;
}
</style>
<script type = "text/javascript">
var words = ['cloud','mixer','flute','taxi','samurai','tough','rough','javascript','hyperspeed','futuristic','donohoo','fluff','lunchbox','peanut butter','pulp','phlegm'];
var randomnumber=Math.floor(Math.random()*words.length);
var answer = {};
var positions = {};
var found = false;
var wrong = 0;
var alreadyguessed = "";
var foundguessed = false;
var subfound = false;
$(document).ready(function() {correct("",0);})
function correct(letter,position) {
if(answer[position]!=letter)
{
answer[position] = letter;
var word = "";
for(var i = 0;i<words[randomnumber].length;i++)
{
if(answer[i] == null||answer[i] == "")
{
word+="_";
word+=" ";
}
else
{
word+=answer[i];
}
}
$('#guesschance').html('<h2>'+word+'</h2>');
$('#guesschance').addClass("underline");
}
else
{
}
if(word == words[randomnumber])
{
alert("You Win!!");
window.location = "marbles.html";
}
}
function incorrect() {
if(wrong>=8)
window.location = "hangman.html";
switch(wrong) {
case 1: $('#images').html('<img src = "images/gallow1.jpg"/>');
break;
case 2: $('#images').html('<img src = "images/gallow2.jpg"/>');
break;
case 3: $('#images').html('<img src = "images/gallow3.jpg"/>');
break;
case 4: $('#images').html('<img src = "images/gallow4.jpg"/>');
break;
case 5: $('#images').html('<img src = "images/gallow5.jpg"/>');
break;
case 6: $('#images').html('<img src = "images/gallow6.jpg"/>');
break;
case 7: $('#images').html('<img src = "images/gallow7.jpg"/>');
break;
}
$('#guessed').html('<h1>You have guessed these..</h1><h2>'+alreadyguessed+'</h2>');
}
function wordcheck(wordguessed) {
var wordwrong = true;
for(var i = 0;i<words[randomnumber].length;i++)
{
if(wordguessed == words[randomnumber][i])
{
found = true;
wordwrong = false;
correct(words[randomnumber][i],i);
}
}
if(wordwrong)
{
found = true;
wrong++;
alreadyguessed+=wordguessed;
incorrect();
}
}
function guesscheck(wordguessed) {
for(var i = 0;i<alreadyguessed.length;i++)
if($('input').val() == alreadyguessed[i])
{
found = true;
foundguessed = true;
}
}
function guess() {
if($('input').val()!="")
{
found = false;
foundguessed = false;
subfound = false;
if($('input').val().length==1)
{
guesscheck($('input').val());
}
else
{
for(var i = 0;i<$('input').val().length;i++)
{
guesscheck($('input').val()[i]);
}
}
if(!found)
{
if($('input').val().length==1)
{
wordcheck($('input').val());
}
else
{
for(var i = 0;i<$('input').val().length;i++)
{
wordcheck($('input').val()[i]);
}
}
}
}
$('input').val("")
}
</script>
</head>
<body>
<div id = "guessed"><h3>Already guessed letter box</h3>
</div>
<div id = "images">
<img src = "images/gallow.jpg"/>
</div>
<div id = "guesses">
<h3>Welcome to HANGMAN!</h3>
<input onKeyPress="if(event.keyCode==13) guess();" placeholder="and your guess is..."/>
<div id = "guesschance"><h2></h2></div>
</div>
</body>
</html>