Friday, 25 March 2022
MARIO MATCHING GAME JAVASCRIPT
<html> <!-- https://taniarascia.github.io/memory/ --> <head> <title>Memory Game</title> <style> *, *::before, *::after { -webkit-box-sizing: border-box; box-sizing: border-box; } body { margin: 20px 0; background: #6589F9; } .grid { max-width: 960px; margin: 0 auto; display: -webkit-box; display: -ms-flexbox; display: flex; -ms-flex-wrap: wrap; flex-wrap: wrap; -webkit-box-pack: space-evenly; -ms-flex-pack: space-evenly; justify-content: space-evenly; } .card { position: relative; -webkit-transition: all .4s linear; -o-transition: all .4s linear; transition: all .4s linear; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; margin: 5px; } .card, .back, .front { height: 381px; width: 400px; } .back, .front { position: absolute; -webkit-backface-visibility: hidden; } .front { } .back { } .selected { } .match .front { background: #6589F9 !important; } .matched { background:Green; } </style> <link rel="icon" type="image/png" href="https://taniarascia.github.io/memory/img/mushroom.png"> </head> <body> <div id="game"></div> <script type='text/javascript'> 'use strict'; var cardsArray = [ { 'name': 'shell', 'img': 'https://www.pngmart.com/files/5/Balcony-PNG-File.png' }, { 'name': 'star', 'img': 'https://taniarascia.github.io/memory/img/star.png' }, ]; var gameGrid = cardsArray.concat(cardsArray).sort(function () { return 0.5 - Math.random(); }); var firstGuess = ''; var secondGuess = ''; var count = 0; var previousTarget = null; var delay = 0; var game = document.getElementById('game'); var grid = document.createElement('section'); grid.setAttribute('class', 'grid'); game.appendChild(grid); gameGrid.forEach(function (item) { var name = item.name, img = item.img; var card = document.createElement('div'); card.classList.add('card'); card.dataset.name = name; var front = document.createElement('div'); front.classList.add('front'); var back = document.createElement('div'); back.classList.add('back'); back.style.backgroundImage = 'url(' + img + ')'; grid.appendChild(card); card.appendChild(front); card.appendChild(back); }); var match = function match() { var selected = document.querySelectorAll('.selected'); selected.forEach(function (card) { card.classList.add('matched'); }); }; var resetGuesses = function resetGuesses() { firstGuess = ''; secondGuess = ''; count = 0; previousTarget = null; var selected = document.querySelectorAll('.selected'); selected.forEach(function (card) { card.classList.remove('selected'); }); }; grid.addEventListener('click', function (event) { var clicked = event.target; if (clicked.nodeName === 'SECTION' || clicked === previousTarget || clicked.parentNode.classList.contains('selected') || clicked.parentNode.classList.contains('match')) { return; } if (count < 2) { count++; if (count === 1) { firstGuess = clicked.parentNode.dataset.name; console.log(firstGuess); clicked.parentNode.classList.add('selected'); } else { secondGuess = clicked.parentNode.dataset.name; console.log(secondGuess); clicked.parentNode.classList.add('selected'); } if (firstGuess && secondGuess) { if (firstGuess === secondGuess) { setTimeout(match, delay); } setTimeout(resetGuesses, delay); } previousTarget = clicked; } }); </script> </body> </html>
<html> <head> <title>SIMPSONS MEMORY GAME</title> <link rel="shortcut icon" href="https://nimbusapp.github.io/SimpsonsMemory/images/simpsons.ico" type="image/x-icon"> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <style> body { background: rgb(172,175,38); background: linear-gradient(90deg, rgba(172,175,38,1) 0%, rgba(154,244,135,1) 49%, rgba(231,245,179,1) 100%); } .grid { margin: auto; display: flex; flex-wrap: wrap; height: 300px; width: 400px; cursor: pointer; } footer { position: fixed; padding: 10px; left: 0; bottom: 0; width: 100%; color: blue; text-align: center; font-size: 15px; font-family: 'Noto Sans JP', sans-serif; } footer a { text-decoration: none; color: inherit; font-family: inherit; } </style> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap" rel="stylesheet"> </head> <body> <div class="content mt-3"> <h2 class="text-info text-center mb-3">SIMPSONS MEMORY GAME</h2> <h4 class="text-center text-primary">Score: <span id="result">0</span></h4> <div class="grid"></div> </div> <footer> Copyright © <label id="year"></label> | Designed by <a href="https://github.com/FabianCristancho">Fabian Cristancho</a></footer> <script > document.addEventListener('DOMContentLoaded', () => {}); const cardArray = [ { name: 'homer', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/homer.png' }, { name: 'homer', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/homer.png' }, { name: 'marge', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/marge.png' }, { name: 'marge', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/marge.png' }, { name: 'maggie', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/maggie.png' }, { name: 'maggie', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/maggie.png' }, { name: 'lisa', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/lisa.png' }, { name: 'lisa', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/lisa.png' }, { name: 'bart', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/bart.png' }, { name: 'bart', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/bart.png' }, { name: 'pets', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/pets.png' }, { name: 'pets', img: 'https://nimbusapp.github.io/SimpsonsMemory/images/pets.png' } ]; cardArray.sort(() => 0.5 - Math.random()); const grid = document.querySelector('.grid'); const resultDisplay = document.querySelector('#result'); var cardsChosen = []; var cardsChosenId = []; var cardsWon = []; function createBoard(){ for (let i = 0; i < cardArray.length; i++) { let card = document.createElement('img'); card.setAttribute('src', 'https://nimbusapp.github.io/SimpsonsMemory/images/happy.png'); card.setAttribute('data-id', i); card.addEventListener('click', flipCard); grid.appendChild(card); } } function checkForMatch(){ var cards = document.querySelectorAll('img'); const optionOneId = cardsChosenId[0]; const optionTwoId = cardsChosenId[1]; if(cardsChosen[0] === cardsChosen[1]){ alert('You found a match'); cards[optionOneId].setAttribute('src', 'https://nimbusapp.github.io/SimpsonsMemory/images/white.png'); cards[optionTwoId].setAttribute('src', 'https://nimbusapp.github.io/SimpsonsMemory/images/white.png'); cardsWon.push(cardsChosen); }else{ cards[optionOneId].setAttribute('src', 'https://nimbusapp.github.io/SimpsonsMemory/images/happy.png'); cards[optionTwoId].setAttribute('src', 'https://nimbusapp.github.io/SimpsonsMemory/images/happy.png'); alert('Sorry, try again'); } cardsChosen = []; cardsChosenId = []; resultDisplay.textContent = cardsWon.length; if(cardsWon.length === cardArray.length/2){ resultDisplay.textContent = 'CONGRATULATIONS!!! SIMPSON ARE FOUND'; setTimeout(()=>location.reload(), 2000); } } function flipCard(){ let cardId = this.getAttribute('data-id'); cardsChosen.push(cardArray[cardId].name); cardsChosenId.push(cardId); this.setAttribute('src', cardArray[cardId].img) if(cardsChosen.length === 2){ setTimeout(checkForMatch, 500) } } createBoard(); document.getElementById('year').innerHTML = new Date().getFullYear(); </script> </body> </html>
---------------------------------------------------------------------------------------------------------------------READ MORE:https://codepen.io/codegrind6/pen/WNXXRKg---------------------------------------------------------------------------------------------------------------------
<!-- Download all Images- https://bit.ly/memory-game-images -->
<h2 class="heading">Memory Game using JavaScript</h2>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: grid;
place-items: center;
min-height: 100vh;
}
.heading {
text-align: center;
font-family: "Poppins", sans-serif;
font-size: 2rem;
font-weight: 500;
}
.cards {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 2em;
position: relative;
float: left;
padding: 15px;
}
.card {
height: 110px;
width: 90px;
background-color: #ffff00;
border-radius: 10px;
display: grid;
place-items: center;
cursor: pointer;
transition: 0.3s all ease;
}
.card:hover {
transform: scale(1.03);
}
.card img {
height: 110px;
width: 90px;
opacity: 100; FOR SHOW IMAGE OPACITY 100 OPACITY ZERO FOR HIDE IMAGE
}
.card.clicked {
background-color: orange;
}
.card.checked {
background-color: lightgreen;
}
.card.clicked img,
.card.checked img {
opacity: 1;
}
.card.shake {
background-color: #f15f5f;
animation: shake 0.5s;
}
</style>
</head>
<body>
<div class="cards">
<div class="card" animal="duck">
<img src="https://imgkub.com/images/2022/02/16/duck.png" alt="" />
</div>
<div class="card" animal="lion">
<img src="https://imgkub.com/images/2022/02/16/lion.png" alt="" />
</div>
<div class="card" animal="duck">
<img src="https://imgkub.com/images/2022/02/16/duck.png" alt="" />
</div>
<div class="card" animal="lion">
<img src="https://imgkub.com/images/2022/02/16/lion.png" alt="" />
</div>
</div>
<script id="rendered-js" >
let counter = 0;
let firstSelection = "";
let secondSelection = "";
var cards = document.querySelectorAll(".cards .card");
cards.forEach(card => {
card.addEventListener("click", () => {
card.classList.add("clicked");
if (counter === 0) {
firstSelection = card.getAttribute("animal");
counter++;
} else {
secondSelection = card.getAttribute("animal");
counter = 0;
if (firstSelection === secondSelection) {
var correctCards = document.querySelectorAll(
".card[animal='" + firstSelection + "']");
correctCards[0].classList.add("checked");
correctCards[0].classList.remove("clicked");
correctCards[1].classList.add("checked");
correctCards[1].classList.remove("clicked");
} else {
var incorrectCards = document.querySelectorAll(".card.clicked");
incorrectCards[0].classList.add("shake");
incorrectCards[1].classList.add("shake");
setTimeout(() => {
incorrectCards[0].classList.remove("shake");
incorrectCards[0].classList.remove("clicked");
incorrectCards[1].classList.remove("shake");
incorrectCards[1].classList.remove("clicked");
}, 800);
}
}
});
});
//# sourceURL=pen.js
</script>
</body>
---------------------------------------------------------------------------------------------------------------------MARIO MATCHING GAME WITHOUT HIDE WITHOUT FLEX DIV---------------------------------------------------------------------------------------------------------------------
<html>
<head>
<!-- https://github.com/NoraX1/Responsive-Memmory-Game -->
<title>Memmory Game</title>
<style>
.score {
margin-top: 10px;
}
.front {
position: relative;
background-color:White
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
.back {
background-color: #333;
}
img {
height: 100px;
width: 100px;
}
.CssOrangeClass {
background-color: Orange;
}
.match {
background-color:Green;
}
</style>
</head>
<body>
<div class="head">
<h2>Memmory Game</h2>
<div class="score">Score: <span>0</span></div>
</div>
<div class="container">
<div class="front" id="1">
<img src="https://www.pngmart.com/files/5/Balcony-PNG-File.png" alt="">
<div class="back"></div>
</div>
<div class="front" id="1">
<img src="https://www.pngmart.com/files/5/Balcony-PNG-File.png" alt="">
<div class="back"></div>
</div>
<div class="front" id="2">
<img src="https://taniarascia.github.io/memory/img/star.png" alt="">
<div class="back"></div>
</div>
<div class="front" id="2">
<img src="https://taniarascia.github.io/memory/img/star.png" alt="">
<div class="back"></div>
</div>
</div>
<script type='text/javascript'>
var CardArray = document.querySelectorAll('.front')
var container = document.querySelector('.container')
var score = document.querySelector('.score span')
for(let i =0; i<CardArray.length; i++){
CardArray[i].addEventListener('click' ,()=>{
CardArray[i].classList.add('CssOrangeClass')
var Css = document.querySelectorAll('.CssOrangeClass')
if(Css.length == 2){
match(Css[0] , Css[1])
}
})
}
function match(cardOne , cardTwo){
if(cardOne.id == cardTwo.id){
score.innerHTML = parseInt(score.innerHTML) + 1
cardOne.classList.remove('CssOrangeClass')
cardTwo.classList.remove('CssOrangeClass')
cardOne.classList.add('match')
cardTwo.classList.add('match')
}else{
setTimeout(() => {
cardOne.classList.remove('CssOrangeClass')
cardTwo.classList.remove('CssOrangeClass')
}, 1000);
}
}
</script>
</body>
</html>
---------------------------------------------------------------------------------------------------------------------
0 comments:
Post a Comment