-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
199 lines (166 loc) · 7.25 KB
/
game.js
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
var gameTitles = [
"Birth → Youth: Do you hatch?",
"Youth → Adulthood: Do you cross the road?",
"Adulthood → Parent: Do you mate?",
"Death: How do you die?",
"Now, here is your life"
];
var questions = [
[
"Your parents guarded you (as an egg) like a hawk. [HATCH and spoiled]",
"Your parents half-assed guarding you but you were hidden very well so nobody saw you. [HATCH]",
"Your parents guarded you until you were born and then got captured and gassed by USDA Wildlife Services [HATCH without parents] ",
"Your parent ingested rat poison and you hatch with severe birth defects, unable to fly. [HATCH but sterile] ",
"A seagull found you and ate you. [ELIMINATED]",
"Your egg was oiled by USDA Wildlife Services and you could not hatch. [ELIMINATED]"
],
[
"No, you did not follow your mother goose across and just barely missed getting run over by a car. [LIVE]",
"You couldn’t decide, so your mother ran back and got run over by a car. [LIVE without parents]",
"Yes, but were hit by a car and lost one of your legs. [LIVE with one leg]",
"You got distracted by fresh grass and got adopted by a human family. [LIVE but won’t mate]",
"Yes, and you got run over by a car. [ELIMINATED]",
"No, you stayed back and got picked off by a stray cat. [ELIMINATED]"
],
[
"Yes! You were the prettiest goose in the whole flock and easily found a mate. [EGG]",
"Even though you were no alpha David Beckgoose, you somehow managed it! [EGG]",
"Yes, the runt of the flock took pity on you and your genes will be passed on. [EGG]",
"No, but you did find a nest with a few eggs with no one guarding them, so you adopted them. [EGG]",
"Nope. :( Whether you grew up alone, without parents, or simply without ri zz you didn’t manage to mate. [ELIMINATED]",
"Wow, bad luck! In the process of attempting to mate, you are caught by USDA Wildlife Services and killed secretly. [ELIMINATED]"
],
[
"You die peacefully with an entire flock of grandchildren. ",
"You go insane from city noise, decide to migrate South, and die happily alone on a beach in Mexico.",
"YOU GOT SUCKED INTO AIRPLANE ENGINE. Don’t worry, the humans survived. (see: Miracle on the Hudson2)",
"You’re bagged and gassed like your parents — circle of life everybody.",
"You die fighting for food and territory with another flock, remembered as a hero.",
"You were chased down by a dog and never to be seen again…… the dog owner was charged a small fee though……"
]
];
document.body.classList.add('purple-bg');
var currentStageIndex = 0;
var playerName = "";
var allAnswers = [];
var babystate = true;
function startNextQuestion() {
playerName = document.getElementById('player-name').value;
var button = document.querySelector('.cute-orange-button');
button.textContent = "Roll Dice";
button.onclick = rollDice;
var gameTitleElement = document.getElementById("game-title");
gameTitleElement.textContent = gameTitles[currentStageIndex];
document.getElementById('game-section').style.display = 'block';
document.getElementById('name-form').style.display = 'none';
document.getElementById('result').style.display = 'none';
if (currentStageIndex === 0) {
document.getElementById('Image').src = 'end.gif';
} else if (currentStageIndex === 1) {
document.getElementById('Image').src = 'dis.gif';
} else if (currentStageIndex === 2) {
document.getElementById('Image').src = 'cross.gif';
} else if (currentStageIndex === 3) {
document.getElementById('Image').src = 'fist.gif';
} else if (currentStageIndex === 4) {
document.getElementById('Image').src = 'dis.gif';
} else {
document.getElementById('Image').src = 'giphy.gif';
}
var buttonContainer = document.getElementById("button-container");
buttonContainer.innerHTML = "";
if (currentStageIndex === gameTitles.length - 1) {
showAllAnswers();
}
}
var nextButton;
function playAudio() {
// Create an audio element
var audio = new Audio('1.mp3');
// Play the audio
audio.play();
}
var playButton = document.getElementById('playButton');
document.addEventListener('keydown', function(event) {
// Check if the pressed key is the spacebar (key code 32)
if (event.key === ' ') {
// Prevent the default behavior of the spacebar (e.g., scrolling the page)
event.preventDefault();
// Play the audio
playAudio();
}
});
function rollDice() {
playAudio();
const diceResult = Math.floor(Math.random() * 6) + 1;
if (diceResult == 4) {
babystate = false
}
var resultDisplay = document.getElementById('result')
resultDisplay.style.display = 'block';
var currentQuestionArray = questions[currentStageIndex];
if (currentStageIndex == 2 && babystate == false) {
resultDisplay.innerHTML = `${playerName}, Good effort but your genes were never going to enter the gene pool.`;
} else {
resultDisplay.innerHTML = `${playerName}, you rolled a ${diceResult}.<br>${currentQuestionArray[diceResult - 1]}`;
allAnswers[currentStageIndex] = currentQuestionArray[diceResult - 1];
if (diceResult == 4) {
babystate = false
document.body.classList.remove('purple-bg');
document.body.classList.remove('gray-bg');
document.body.classList.add('green-bg');
} else if (diceResult > 4) {
babystate = true
document.body.classList.remove('purple-bg');
document.body.classList.remove('green-bg');
document.body.classList.add('gray-bg');
} else if (diceResult < 4 && currentStageIndex < gameTitles.length - 1) {
babystate = true
document.body.classList.remove('gray-bg');
document.body.classList.remove('green-bg');
document.body.classList.add('purple-bg');
}
}
var buttonContainer = document.getElementById("button-container");
nextButton = document.createElement("button");
nextButton.className = "cute-orange-button";
nextButton.textContent = "Next";
nextButton.type = "button";
nextButton.onclick = function() {
if (currentStageIndex < gameTitles.length - 2 && diceResult < 5) {
currentStageIndex++;
startNextQuestion();
}
else {
showAllAnswers();
}
};
buttonContainer.appendChild(nextButton);
}
function showAllAnswers() {
babystate = true;
var gameTitleElement = document.getElementById("game-title");
gameTitleElement.textContent = gameTitles[gameTitles.length - 1];
var resultDisplay = document.getElementById('result');
resultDisplay.innerHTML = `<div style="text-align: center;">${allAnswers.join('<br>')}</div>`;
nextButton.textContent = "Read More";
nextButton.style.backgroundColor = 'white';
nextButton.style.color = 'black';
nextButton.onclick = function() {
window.location.href = 'https://www.goosewatchnyc.com/news';
};
// 创建 replayButton
var replayButton = document.createElement("button");
replayButton.className = "cute-orange-button";
replayButton.textContent = "Next Life";
replayButton.type = "button";
replayButton.className = "cute-orange-button replay-button";
replayButton.onclick = function() {
currentStageIndex = 0;
allAnswers = [];
startNextQuestion();
};
// 获取 buttonContainer 并将 replayButton 添加到其中
var buttonContainer = document.getElementById("button-container");
buttonContainer.appendChild(replayButton);
}