JavaScript-Packer
view release on metacpan or search on metacpan
t/scripts/s12.js view on Meta::CPAN
constructor(id, className, innerText, bgColor, snake, ladder, next) {
this.id = id;
this.className = className;
this.innerText = innerText;
this.bgColor = bgColor;
this.snake = snake;
this.ladder = ladder;
this.next = next;
}
}
class MemoryBlock {
constructor(id, frontImage, backImage) {
this.id = id;
this.blockCSS = "block";
this.frontImage = frontImage;
this.backImage = backImage;
this.front = false;
this.back = true;
this.frontCSS = "block-front block-face";
this.backCSS = "block-back block-face";
this.imgCSS = "block-value";
}
}
function startTimer(duration, display) {
var timer = 60 * duration, minutes, seconds;
countdown = setInterval(() => {
minutes = parseInt(timer / 60, 10);
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = `Time ${ minutes }:${ seconds }`;
if (--timer < 0) {
gameOver();
}
}, 1000);
}
class gameInfo {
constructor(totalTime, cards) {
this.cardsArray = cards;
this.totalTime = totalTime;
this.timeRemaining = totalTime;
// this.timer = document.getElementById('time-remaining');
this.flips = 0;
}
}
// for creating divs and shuffling blocks
var divblock, blockData, blockFrontImages, memoryBlockArr, blocksArray, blockFrontImagesAll, shuffledBlocks;
// for implementing flip n match logic
var currentlyFlippedArr, matchedCount, blockToMatch1, blockToMatch2;
// for implementing game info block
var flipCounter, timer, gameOn = false;
var overlays = Array.from(document.getElementsByClassName('overlay-text'));
overlays.forEach(overlay => {
overlay.addEventListener('click', () => {
overlay.classList.remove('visible');
resetGame();
init();
});
});
function startCountdown() {
return setInterval(() => {
this.timeRemaining--;
this.timer.innerText = this.timeRemaining;
if (this.timeRemaining === 0)
this.gameOver();
}, 1000);
}
function resetGame() {
var elements = document.getElementsByClassName("block");
while (elements.length > 0) {
elements[0].parentNode.removeChild(elements[0]);
}
}
function init() {
//initializing values
gameOn = true;
memoryBlockArr = new Array(18);
blocksArray = [];
blockFrontImagesAll = [];
shuffledBlocks = [];
currentlyFlippedArr = [];
matchedCount = 0;
flipCounter = 0;
var minutes = 2;
var display = document.getElementById("Timer");
blockFrontImages = ["Images/pokemon1.gif",
"Images/pokemon2.gif",
"Images/pokemon3.gif",
"Images/pokemon4.gif",
"Images/pokemon5.gif",
"Images/pokemon6.gif",
"Images/pokemon7.gif",
"Images/pokemon8.gif",
"Images/pokemon9.gif"];
// init();
startTimer(minutes, display);
blockFrontImagesAll = blockFrontImages.concat(blockFrontImages);
shuffledBlocks = shuffleBlocks(blockFrontImagesAll);
document.getElementById("Flips").innerText = `Flips: ${flipCounter}`;
createElements();
}
function createElements() {
var finalCount = shuffledBlocks.length;
for (var i = 0; i < finalCount; i++) {
var cardFront = shuffledBlocks.pop();
blockData = new MemoryBlock(i, cardFront, "Images/pokemonBack.jpg");
memoryBlockArr[i] = blockData;
( run in 0.966 second using v1.01-cache-2.11-cpan-140bd7fdf52 )