messageSpan.addDiv function
This commit is contained in:
		
							
								
								
									
										75
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										75
									
								
								app.js
									
									
									
									
									
								
							| @ -445,10 +445,7 @@ class Stats { | |||||||
|             this.lockDelay = 500 * Math.pow(0.9, level - 15) |             this.lockDelay = 500 * Math.pow(0.9, level - 15) | ||||||
|         levelInput.value = level |         levelInput.value = level | ||||||
|         levelCell.innerText = level |         levelCell.innerText = level | ||||||
|         let div = document.createElement("div") |         messagesSpan.addDiv({ className: "show-level-animation", innerHTML: `<h1>LEVEL<br/>${this.level}</h1>` }) | ||||||
|         div.className = "show-level-animation" |  | ||||||
|         div.innerHTML = `<h1>LEVEL<br/>${this.level}</h1>` |  | ||||||
|         messagesSpan.appendChild(div) |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     get level() { |     get level() { | ||||||
| @ -476,24 +473,20 @@ class Stats { | |||||||
|     lockDown(nbClearedLines, tSpin) { |     lockDown(nbClearedLines, tSpin) { | ||||||
|         // Cleared lines & T-Spin |         // Cleared lines & T-Spin | ||||||
|         let patternScore = SCORES[tSpin][nbClearedLines] * this.level |         let patternScore = SCORES[tSpin][nbClearedLines] * this.level | ||||||
|         if (tSpin) { |         if (tSpin) messagesSpan.addDiv({ | ||||||
|             let div = document.createElement("div") |             className: "rotate-in-animation", | ||||||
|             div.className = "rotate-in-animation" |             innerHTML: tSpin | ||||||
|             div.innerHTML = tSpin |         }) | ||||||
|             messagesSpan.appendChild(div) |         if (nbClearedLines) messagesSpan.addDiv({ | ||||||
|         } |             className: "zoom-in-animation", | ||||||
|         if (nbClearedLines) { |             innerHTML: CLEARED_LINES_NAMES[nbClearedLines] | ||||||
|             let div = document.createElement("div") |         }) | ||||||
|             div.className = "zoom-in-animation" |  | ||||||
|             div.innerHTML = CLEARED_LINES_NAMES[nbClearedLines] |  | ||||||
|             messagesSpan.appendChild(div) |  | ||||||
|         } |  | ||||||
|         if (patternScore) { |         if (patternScore) { | ||||||
|             let div = document.createElement("div") |             messagesSpan.addDiv({ | ||||||
|             div.className = "zoom-in-animation" |                 className: "zoom-in-animation", | ||||||
|             div.style = "animation-delay: .2s" |                 style: "animation-delay: .2s", | ||||||
|             div.innerHTML = patternScore |                 innerHTML: patternScore | ||||||
|             messagesSpan.appendChild(div) |             }) | ||||||
|             this.score += patternScore |             this.score += patternScore | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @ -502,11 +495,11 @@ class Stats { | |||||||
|             this.combo++ |             this.combo++ | ||||||
|             if (this.combo >= 1) { |             if (this.combo >= 1) { | ||||||
|                 let comboScore = (nbClearedLines == 1 ? 20 : 50) * this.combo * this.level |                 let comboScore = (nbClearedLines == 1 ? 20 : 50) * this.combo * this.level | ||||||
|                 let div = document.createElement("div") |                 messagesSpan.addDiv({ | ||||||
|                 div.className = "zoom-in-animation" |                     className: "zoom-in-animation", | ||||||
|                 div.style = "animation-delay: .4s" |                     style: "animation-delay: .4s", | ||||||
|                 div.innerHTML = `COMBO x${this.combo}<br/>${comboScore}` |                     innerHTML: `COMBO x${this.combo}<br/>${comboScore}` | ||||||
|                 messagesSpan.appendChild(div) |                 }) | ||||||
|                 this.score += comboScore |                 this.score += comboScore | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
| @ -518,14 +511,14 @@ class Stats { | |||||||
|             this.b2b++ |             this.b2b++ | ||||||
|             if (this.b2b >= 1) { |             if (this.b2b >= 1) { | ||||||
|                 let b2bScore = patternScore / 2 |                 let b2bScore = patternScore / 2 | ||||||
|                 let div = document.createElement("div") |                 messagesSpan.addDiv({ | ||||||
|                 div.className = "zoom-in-animation" |                     className: "zoom-in-animation", | ||||||
|                 div.style = "animation-delay: .4s" |                     style: "animation-delay: .4s", | ||||||
|                 div.innerHTML = `BACK TO BACK x${this.b2b}<br/>${b2bScore}` |                     innerHTML: `BACK TO BACK x${this.b2b}<br/>${b2bScore}` | ||||||
|                 messagesSpan.appendChild(div) |                 }) | ||||||
|                 this.score += b2bScore |                 this.score += b2bScore | ||||||
|             } |             } | ||||||
|         } else if ((0 < nbClearedLines) && (nbClearedLines < 4) && !tSpin) { |         } else if (nbClearedLines && !tSpin ) { | ||||||
|             this.b2b = -1 |             this.b2b = -1 | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @ -549,6 +542,14 @@ messagesSpan.onanimationend = function(event) { | |||||||
|     event.target.remove()  |     event.target.remove()  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | messagesSpan.addDiv = function(attributes) { | ||||||
|  |     let div = document.createElement("div") | ||||||
|  |     for (key in attributes) { | ||||||
|  |         div[key] = attributes[key] | ||||||
|  |     } | ||||||
|  |     messagesSpan.appendChild(div) | ||||||
|  | } | ||||||
|  |  | ||||||
| let scheduler = new Scheduler() | let scheduler = new Scheduler() | ||||||
| let settings = new Settings() | let settings = new Settings() | ||||||
| let stats = new Stats() | let stats = new Stats() | ||||||
| @ -767,10 +768,12 @@ function gameOver() { | |||||||
|      |      | ||||||
|     scheduler.clearInterval(clock) |     scheduler.clearInterval(clock) | ||||||
|  |  | ||||||
|     let div = document.createElement("div") |     messagesSpan.onanimationend = null | ||||||
|     div.className = "show-level-animation" |     messagesSpan.addDiv({ | ||||||
|     div.innerHTML = "<h1>GAME<br/>OVER</h1>" |         className: "game-over-animation", | ||||||
|     messagesSpan.appendChild(div) |         style: "opacity: 100%", | ||||||
|  |         innerHTML: "<h1>GAME<br/>OVER</h1>" | ||||||
|  |     }) | ||||||
| } | } | ||||||
|  |  | ||||||
| window.onbeforeunload = function(event) { | window.onbeforeunload = function(event) { | ||||||
|  | |||||||
| @ -117,11 +117,10 @@ span { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| div.show-level-animation { | #messagesSpan div.show-level-animation { | ||||||
|     animation: show-level-animation; |     animation: show-level-animation; | ||||||
|     animation-timing-function: (0.4, 0, 0.6, 1); |     animation-timing-function: (0.4, 0, 0.6, 1); | ||||||
|     animation-duration: 2s; |     animation-duration: 2s; | ||||||
|     animation-delay: 1s; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| @keyframes zoom-in-animation { | @keyframes zoom-in-animation { | ||||||
| @ -182,3 +181,21 @@ div.show-level-animation { | |||||||
|     transform-origin:center; |     transform-origin:center; | ||||||
|     animation-duration: 1s; |     animation-duration: 1s; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @keyframes game-over-animation { | ||||||
|  |     from { | ||||||
|  |         opacity: 0; | ||||||
|  |         transform: translateY(200%); | ||||||
|  |     } | ||||||
|  |     to { | ||||||
|  |         opacity: 100%; | ||||||
|  |         transform: translateY(0) scaleY(1); | ||||||
|  |         line-height: var(--bs-body-line-height); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #messagesSpan div.game-over-animation { | ||||||
|  |     animation: game-over-animation; | ||||||
|  |     animation-timing-function: (0.4, 0, 0.6, 1); | ||||||
|  |     animation-duration: 2s; | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user