-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
303 lines (278 loc) · 10.3 KB
/
index.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
//function to fade out title page image
function fadeOutEffect() {
var fadeTitlePage = document.getElementsByClassName("titleImage")[0];
var fadeEffect = setInterval(function () {
if (!fadeTitlePage.style.opacity) {
fadeTitlePage.style.opacity = 1;
}
if (fadeTitlePage.style.opacity > 0) {
fadeTitlePage.style.opacity -= 0.1;
} else {
clearInterval(fadeEffect);
}
}, 200);
}
//function for removal of image that just faded out (title page)
function removeImage() {
document.getElementsByClassName("titleImage")[0].remove()
}
//select text element
const textElement = document.getElementById('text')
//select option buttons
const optionButtonsElement = document.getElementById('option-buttons')
//makes sure object is empty at start of game
let state = {}
//start game function
//makes sure object is empty at start of game
//show first node
function startGame() {
state = {}
showTextNode(1)
}
//select option function
function selectOption(option) {
const nextTextNodeId = option.nextText
if (nextTextNodeId <= 0) {
return startGame()
}
//resets to state. returns new object that's set to current state
state = Object.assign(state,option.setState)
showTextNode(nextTextNodeId)
}
//display option
function showTextNode(textNodeIndex) {
const textNode = textNodes.find(textNode => textNode.id === textNodeIndex)
textElement.innerText = textNode.text
while (optionButtonsElement.firstChild) {
optionButtonsElement.removeChild(optionButtonsElement.firstChild)
}
//looping through all options
textNode.options.forEach(option => {
if (showOption(option)) {
const button = document.createElement('button')
button.innerText = option.text
button.classList.add('btn')
button.addEventListener('click', () => selectOption(option))
optionButtonsElement.appendChild(button)
}
})
}
//showing options
function showOption(option) {
return option.requiredState == null || option.requiredState(state)
}
//defining textnodes
const textNodes= [
{
id:1,
text: "This may be your last first date! You walk into the restaurant and pick a booth in the corner to await the arrival of your date. It's been 15 minutes and your date hasn't shown. Do you...",
options: [
{
text: "Text your date asking when you can expect them",
setState:{continueDate: true},
nextText: 2
},
{
text:"Leave and attempt to reschedule",
setState: {block: true},
nextText: 3
},
{
text: "Unmatch on dating app and never look back",
setState: {block: true},
nextText: 3
}
]
},
{
id:2,
text: "You've chosen to stay! Your date arrives and sits down. They apologize for their tardiness. Do you...",
options: [
{
text: "Forgive and forget. You're excited to get to know this person, after all.",
requiredState: (currentState) => currentState.continueDate,
setState: {continueDate: true},
nextText: 5
},
{
text: "'Your apologies mean nothing to me, weak human!' you snarl as you block them. It was worth staying just to see the look on their face...",
requiredState: (currentState) => currentState.continueDate,
setState: {continueDate: true},
nextText: 4
},
{
text: "Politely ask that they let you know in the future if they're running late.",
requiredState: (currentState) => currentState.continueDate,
setState: {continueDate: true},
nextText: 4
}
]
},
{
id:3,
text: "Game Over! Better luck next time in the exciting game of Love me, Block me! The game where points don't matter and you'll probably end up ghosting them anyway...",
requiredState: (currentState) => currentState.block,
setState: {block: true}
},
{
id:4,
text: "oh no! Your date storms off in a huff and throws their napkin at you on their way out! Do you...",
options: [
{
text: "Text them asking what you did wrong and plead for another chance to make it right.",
requiredState: (currentState) => currentState.continueDate,
setState: {continueDate: true},
nextText: 8
},
{
text: "Block immediately.",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
},
{
text: "Laugh it off and go about your day.",
requiredState: (currentState) => currentState.continueDate,
setState: {continueDate: true},
nextText: 3
}
]
},
{
id:5,
text: "Wow! What a great date! The conversation was flowing and things are really looking up. The date ends and they insist on escorting you home. Wait..did they say they already know where you live? Do you...",
options: [
{
text: "Pepper spray them and run!",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
},
{
text: "Stranger Danger! Block!",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
},
{
text: "Accept their offer. They do say internet stalking is the highest form of flattery.",
requiredState: (currentState) => currentState.continueDate,
setState: {continueDate:true},
nextText: 3
}
]
},
{
id: 6,
text: "Well, that's odd. Their sibling just texted asking if you were free that night. They said they were immpressed at how you handled the situation and would like to take you out to make it up to you. Do you...",
options: [
{
text: "Block",
setState: {block: true},
requiredState: (currentState) => currentState.continueDate,
nextText: 3
},
{
text: "Accept. Hey, why not keep it in the family? Plus they seemed really nice.",
requiredState: (currentState) => currentState.continueDate,
setState: {continueDate: true},
nextText: 8
},
{
text: "Politely decline.",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
}
]
},
{
id: 7,
text: "It's the next night and both siblings show up at your door! Do you...",
options: [
{
text: "Realize it may be time to uninstall the dating apps",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
},
{
text: "Sic Sansa the Border Collie on them",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
},
{
text: "Block.",
setState: {block: true},
nextText: 3
}
]
},
{
id: 8,
text: "Oh no! They're even more upset! You receive nine messages of wall to wall text. Do you...",
options: [
{
text: "Text them back trying to understand what you did wrong",
requiredState: (currentState) => currentState.continueDate,
setState: {continueDate: true},
nextText: 9
},
{
text: "Block.",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
},
{
text: "Block in the same color.",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
}
]
},
{
id: 9,
text: "They continue to text, irate. They then apologize and say you can make it up to them the next night. Do you...",
options: [
{
text: "Take screenshots for the group chat, then block.",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
},
{
text: "Block and uninstall the dating apps.",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
},
{
text: "Block.",
requiredState: (currentState) => currentState.continueDate,
setState: {block: true},
nextText: 3
}
]
},
]
//starting game
startGame()
//listen for click to reset game
document.querySelector('.reset-btn').addEventListener('click', function(){
window.location.reload();
return false;
});
//click for fadeout function
document.getElementsByClassName("titleImage")[[0]].addEventListener('click', fadeOutEffect);
//space for removal of image that just faded out (title page)
document.body.onkeyup = function(e) {
if (e.key == " " ||
e.code == "Space" ||
e.keyCode == 32
) {
removeImage()
}
}