-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathold script.js
More file actions
433 lines (285 loc) · 10.1 KB
/
old script.js
File metadata and controls
433 lines (285 loc) · 10.1 KB
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
"use strict";
//a place for experimentation
// let options = {
// // rootMargin: '-10%',
// // threshold: 0.0
// // }
// // let observer = new IntersectionObserver(showItem, options);
// // const rpsTitle = document.getElementsByClassName('rockpaperscissors-title')[0];
// // const rpsSymbols = document.getElementsByClassName('rps-symbols-title')[0];
// // const rochambeauTitle = document.getElementsByClassName('rochambeau-title')[0];
// // console.log(rpsTitle);
// // window.onload = function(){
// // setTimeout(()=>{
// // rpsTitle.classList.remove('active')
// // setTimeout(()=>{
// // rpsSymbols.classList.add('active')
// // setTimeout(()=>{
// // rpsSymbols.classList.remove('active')
// // setTimeout(()=>{
// // rochambeauTitle.classList.add('active')
// // },200)
// // },500)
// // },200)
// // },500);
// // }
// const scrollY = window.pageYOffset;
// // what should we do when scrolling occurs
// // function hideOnScroll() {
// // const scroll = document.getElementsByClassName('scroll')[0];
// // scroll.classList.remove('active');
// // };
// // const entity = document.getElementsByClassName('visuals')[0];
// // entity.onscroll = function(){console.log('yas')};
// // window.onload = function(){
// // entity.addEventListener('scroll', () => {
// // console.log('yas')
// // hideOnScroll();
// // })
// // }
// const wrapper = document.getElementsByClassName('wrapper')[0];
// wrapper.onscroll = function() {hideOnScroll()};
// function hideOnScroll() {
// if (wrapper.scrollTop > 50 || document.documentElement.scrollTop > 50) {
// document.getElementsByClassName('scroll')[0].remove('active');
// } else {
// document.getElementsByClassName('scroll')[0].add('active');
// }
// }
function visibilityToggle(
targetDiv // String
) {
var divVis = document.getElementsByClassName(`${targetDiv}`)[0];
if (divVis.style.visibility === "hidden") {
divVis.style.visibility = "visible";
} else {
divVis.style.visibility = "hidden";
}
}
function computerPlay (computerSelection) { // get random number from 1-3
computerSelection = Math.floor(Math.random() * (4 - 1) + 1); //1 == rock, 2 == paper, 3 == scissors
return;
}
// function getClicked() {
// document.addEventListener('keydown', (event) => {
// const keyName = event.key;
// if (keyName >= 1 && keyName <= 3) {
// const playerSelection = keyName;
// return playerSelection;
// }else {
// alert('wrong key, 1 = Rock, 2 = Paper. 3 = Scissors')
// }
// })
// }
function getClicked() {
document.addEventListener('keydown', (event) => {
playerSelection = event.key;
if (playerSelection < 1 || playerSelection > 3 || playerSelection == NaN ) {
playerSelection = null;
alert('wrong key, 1 = Rock, 2 = Paper. 3 = Scissors')
}
})
}
function getSelected(number){
playerSelection = number;
}
function playerPlay(){
if (getSelected() == true) {
return getSelected();
}else if (getClicked() == true){
return getClicked();
}
}
function computerSignAssign () {
if (computerSelection === 1 ){
const computerSign = 'Rock';
return computerSign;
}else if (computerSelection === 2 ){
const computerSign = 'Paper';
return computerSign;
}else if (computerSelection ===3 ) {
const computerSign = 'Scissors';
return computerSign;
}
}
function playerSignAssign () {
if (playerPlay() === 1 ){
const playerSign = 'Rock';
return playerSign;
}else if (playerPlay() === 2 ){
const playerSign = 'Paper';
return playerSign;
}else if (playerPlay() ===3 ) {
const playerSign = 'Scissors';
return playerSign;
}
}
function score(){
playerPlay() - computerPlay();
return;
}
function game() {
if (score == 2 || score == -1){
alert('You win! :' + playerSign + 'beats' + computerSign);
}else if (score == -4 || score == 1){
alert('You lose... :' + computerSign + 'beats' + playerSign);
}else if (score == 0){
alert('draw' + computerPlay + 'ties' + playerPlay);
}
}
function beginPlay(){
visibilityToggle("play-button");
setTimeout(
() => {
computerPlay();
},
3000,
console.log(computerPlay()),
setTimeout(
() => {
visibilityToggle("player-choice");
},
2500,
setTimeout(
() => {
visibilityToggle("player-choice");
},
500,
),
),
);
}
let resultWindow = document.getElementsByClassName('result-window')[0];
let resultHeading = document.getElementsByClassName('result-heading')[0];
let resultSubheading =document.getElementsByClassName('result-subheading')[0];
strokeWeight(31);
stroke(255, 255, 0)
line(83, 116, 271, 74);
fill(255, 255, 0);
stroke(255, 255, 0)
ellipse(206,206,100*4.3,100*4.3);
ellipse(206,206,100*3,100*3);
ellipse(206,206,100*1.9,100*1.9);
ellipse(206,206,100,100);
// Winston's handsome features don't need outlines
noStroke();
var eyeSize = 40;
//position of the centre of face
var x = 200;
// face
fill(255, 255, 0);
ellipse(x, 208, 300, 300);
// eyes
fill(46, 46, 41);
//move an eye 50 px to the left of centre
ellipse(x - 50, 151, eyeSize, eyeSize);
ellipse(300, 142, eyeSize, eyeSize);
// mouth
fill(252, 65, 65);
ellipse(250, 240, 120, 136);
requestAnimationFrame((_) => {
while(GRID.firstChild) { GRID.removeChild(GRID.firstChild); }
cards.map((card) => {
GRID.appendChild(card.element);
for (let i = 0; i < cards.length; i++) {
setTimeout(
() => { cards[i].animateIn(); },
i * delayBetweenCards
);
continue;
}
return; });
return;
});
//Function to get keyboard input
// document.addEventListener('keydown', (event) => {
// const keyName = event.key;
// if (keyName >= 1 && keyName <= 3) {
// playerSelection = keyName;
// console.log(playerSelection);
// }else {
// resultHeading = 'wrong key';
// resultSubheading = 'press 1-3 on go';
// console.log(resultHeading,resultSubheading);
// }
// })
//Function to get click input
//Function to output result string
// const choiceRock = document.querySelector('#choice_rock');
// const choicePaper = document.querySelector('#choice_paper');
// const choiceScissors = document.querySelector('#choice_scissors');
// choiceRock.onclick = () => {
// playerSelection = 1;
// console.log(playerSelection);
// }
// choicePaper.onclick = () => {
// playerSelection = 2;
// }
// choiceScissors.onclick = () => {
// playerSelection = 3;
// }
// console.log(playerSelection);
//give user 0.5sec window to 'keyup' number from 1-3 on keyboard
//compare computerPlay to userPlay
//display winner
// document.getElementsByClassName("choice-one").onclick = function() {playerSelection = 1};
// document.getElementsByClassName("choice-two").onclick = function() {playerSelection = 2};
// document.getElementsByClassName("choice-three").onclick = function() {playerSelection = 3};
// class HomePage {
// constructor(
// element // HTML DOM Element
// ) {
// this._element = element; //immutability, unchangeable object. _we should not touch
// return;
// }
// get element() { return this._element; } //crash program if try to change value of _element
// static build(
// historicalContext // PlayArea
// ) { // -> Self
// const wrapper = document.createElement('div');
// wrapper.classList.add('wrapper');
// const innerWrapper = document.createElement('div');
// innerWrapper.classList.add('inner-wrapper');
// innerWrapper.classList.add('user-choice-japan');
// innerWrapper.classList.add('user-choice-china');
// innerWrapper.classList.add('user-choice-western');
// wrapper.appendChild(innerWrapper);
// const header = document.createElement('div');
// header.classList.add('header');
// innerWrapper.appendChild(header);
// const headerH1 = document.createElement('h1');
// const expandingList = document.createElement('div')
// const computerPlaySign = document.createElement('computer-play-sign');
// headerH1.innerText = pageTitle;
// headerH3.innerText = 'Last edited: ' + apiDocument.lastEditedDate;
// cardHeader.appendChild(headerH2);
// cardHeader.appendChild(headerH3);
// const cardP = document.createElement('p');
// cardP.innerText = apiDocument.description;
// card.appendChild(cardP);
// const cardFooter = document.createElement('div');
// cardFooter.classList.add('card-footer');
// card.appendChild(cardFooter);
// const footerH3 = document.createElement('h3');
// const footerP = document.createElement('p');
// // Author not yet available on RippleDocument
// footerH3.innerText = 'George Washington'
// footerP.innerText = 'Tags: ';
// cardFooter.appendChild(footerH3);
// cardFooter.appendChild(footerP);
// // Continue building card...
// card.addEventListener('click', () => {
// // const INNER = document.getElementsByClassName('inner')[0];
// const cardClick = document.createElement('div');
// cardClick.classList.add('card--fullscreen');
// card.appendChild(cardClick);
// // INNER.appendChild(cardClick);
// setTimeout(
// () => { window.location.assign('/document-editor')},
// 200
// );
// return;
// })
// return new DocumentCard(card);
// }
// }