-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsavebuttercup.html
174 lines (137 loc) · 3.76 KB
/
savebuttercup.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
<html>
<body>
<h1> Save Buttercup!</h1>
<body style="background-color:deepskyblue;">
<button onclick="myFunction()"> How to Play</button>
<script>
function myFunction() {
prompt("You have a choice. You can choose to be Westly or Inigo. Enter here!");
alert("Buttercup was kidnapped by Humperdink! He has a game for you.");
alert("You have to enter letters to spell out the word he's thinking of.");
alert("Good luck!");
}
</script>
<br>
<br>
<input id="guess" type="text" maxlength="1" placeholder="Enter a one letter guess!"/>
<button onclick="makeGuess()">Guess!</button>
<h2 id="guesses"></h2>
<canvas id="stickman"/>
<form action="/crazyland">
<input type="submit" value="Home" />
</form>
</body>
</html>
<script type="text/javascript">
var frame1 = function() {
draw(0, 150, 150, 150);
}
var frame2 = function() {
draw(10, 0, 10, 600);
}
var frame3 = function() {
draw(0, 5, 70, 5);
}
var frame4 = function() {
draw(60, 5, 60, 15);
}
var head = function(){
stickman = document.getElementById("stickman");
context = stickman.getContext("2d");
context.beginPath();
context.arc(60, 25, 10, 0, Math.PI * 2, true);
context.stroke();
}
var torso = function() {
draw(60, 36, 60, 70);
}
var rightArm = function() {
draw(60, 46, 100, 50);
}
var leftArm = function() {
draw(60, 46, 20, 50);
}
var rightLeg = function() {
draw(60, 70, 100, 100);
}
var leftLeg = function() {
draw(60, 70, 20, 100);
}
var drawArray = [rightLeg, leftLeg, rightArm, leftArm, torso, head, frame4, frame3, frame2, frame1];
var lives = drawArray.length;
var answerArray = [];
var words = ["westly", "love", "inconceivable", "rhyme", "vizzini", "fezzik", "humperdinck", " guilder", "iocane", "montoya", "roberts", "rodents"];
var word = getRandomWord();
var remainingLetters = word.length;
function draw(pathFromX, pathFromY, pathToX, pathToY) {
stickman = document.getElementById("stickman");
context = stickman.getContext("2d");
context.moveTo(pathFromX, pathFromY);
context.lineTo(pathToX, pathToY);
context.stroke();
}
function getRandomWord() {
return words[Math.floor(Math.random() * words.length)];
}
function createAnswerArray() {
for (var i = 0; i < word.length; i++) {
answerArray[i] = "_";
}
}
function updateStickman() {
for (var l = drawArray.length - 1; l >= lives; l--) {
drawArray[l]();
}
}
function updateUI() {
// update guesses
document.getElementById("guesses").innerHTML = answerArray.join(" ");
// update stickman
updateStickman();
}
function makeGuess() {
if (remainingLetters > 0 && lives > 0) {
var guessIsCorrect = false;
var guessElement = document.getElementById("guess");
var guess = guessElement.value;
guessElement.value = "";
if (guess && guess.length == 1) {
for (var j = 0; j < word.length; j++) {
if (word[j] === guess) {
// update the answer array
answerArray[j] = guess;
// set the flag true
guessIsCorrect = true;
// update the remainingLetters
remainingLetters--;
//you win!!!
if(remainingLetters === 0){
answerArray = ["Y", "O", "U", " ", " ", "W", "I", "N", "!"]
}
}
}
// handle incorrect guess
if(!guessIsCorrect){
lives--;
//you lose
if(lives === 0){
alert("Luckily she's only mostly dead, so you can click alt and r and start over!");
}
}
}
}
updateUI();
}
//run the game
createAnswerArray();
updateUI();
document.onkeydown = function(e) {
switch (e.keyCode) {
case 82:
if(e.shiftKey) {
document.location.reload();
}
break;
}
};
</script>