Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
KostasSliazas authored Dec 13, 2023
1 parent 53339fa commit 00f3f91
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 27 deletions.
12 changes: 0 additions & 12 deletions games/Memory Game3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,7 @@
<!--[if lt IE 9]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="https://vivaldi.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div class="hidden">
<script>
var images = new Array();

function preload() {
for (var i = 0; i < preload.arguments.length; i++) {
images[i] = new Image();
images[i].src = preload.arguments[i];
}
}
preload("img/01.png", "img/02.png", "img/03.png", "img/04.png", "img/05.png", "img/06.png", "img/07.png", "img/08.png", "img/09.png", "img/10.png");
</script>
</div>
<div class="wrp">
<h1>Memory Game</h1>
<div id="statistics" class="hidden">
Expand Down
57 changes: 49 additions & 8 deletions games/Memory Game3/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class MemoryGame {
}

/**
* Creates a new HTML element with specified properties.
* @param {string} tagName - The tag name of the element.
* @param {string} className - The class name of the element.
* @param {string} text - The inner HTML text of the element.
* @return {HTMLElement|null} - The created HTML element, or null.
*/
* Creates a new HTML element with specified properties.
* @param {string} tagName - The tag name of the element.
* @param {string} className - The class name of the element.
* @param {string} text - The inner HTML text of the element.
* @return {HTMLElement|null} - The created HTML element, or null.
*/
createElements(tagName, className, text) {
const element = document.createElement(tagName);
element.className = className;
Expand Down Expand Up @@ -207,10 +207,51 @@ class MemoryGame {
* Adds an event listener to initialize the game when the DOM is loaded.
*/
document.addEventListener('DOMContentLoaded', () => {

const memoryGame = new MemoryGame();
memoryGame.init();

var images = [];

/**
* Preloads images by creating new Image objects and setting their src attributes.
* @param {...string} urls - Image URLs to be preloaded.
*/
function preload(...urls) {
var images = [];
var loadedCount = 0;

function loadImage(url) {
var image = new Image();
image.onload = function () {
loadedCount++;
if (loadedCount === urls.length) {
// All images are loaded, now you can initialize the MemoryGame
memoryGame.init();
}
};
image.src = url;
images.push(image);
}

for (var i = 0; i < urls.length; i++) {
loadImage(urls[i]);
}
}

preload(
"img/01.png",
"img/02.png",
"img/03.png",
"img/04.png",
"img/05.png",
"img/06.png",
"img/07.png",
"img/08.png",
"img/09.png",
"img/10.png"
);

document.addEventListener('click', (e) => {
memoryGame.handleClick(e);
});
});
});
15 changes: 8 additions & 7 deletions games/Memory Game3/js/main.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 00f3f91

Please sign in to comment.