-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 856855c
Showing
14 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Memory Card Game</title> | ||
<style> | ||
.placeholder{ /* ๋ํผ */ | ||
display:grid; | ||
grid-template-columns: repeat(var(--row),150px); | ||
gap: 20px; | ||
perspective: 800px; | ||
} | ||
|
||
.placeholder > .card{ /* ์นด๋ ๋ท๋ฉด */ | ||
background-image: url('./image/0.png'); | ||
background-position: center; | ||
background-size: contain; | ||
background-repeat: no-repeat; | ||
width: 140px; | ||
height: 200px; | ||
transform-style: preserve-3d; | ||
perspective: 400px; | ||
backface-visibility: hidden; | ||
transform: rotateY(180deg); | ||
text-align: center; | ||
} | ||
.placeholder > .card::before{ /* ์นด๋ ์๋ฉด */ | ||
background-image: url('./image/`{data-number}`.png'); | ||
background-position: center; | ||
background-size: contain; | ||
visibility: hidden; | ||
content: ""; | ||
position: absolute; | ||
font-size: 5em; | ||
line-height: 1.125; | ||
font-weight: bold; | ||
top: 50%; | ||
transform: rotateY(180deg) translate(50%,-50%); | ||
backface-visibility: hidden; | ||
background-color: #e8e8e8; | ||
color: #444; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="1"]::before { | ||
background-image: url('./image/1.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="2"]::before { | ||
background-image: url('./image/2.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="3"]::before { | ||
background-image: url('./image/3.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="4"]::before { | ||
background-image: url('./image/4.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="5"]::before { | ||
background-image: url('./image/5.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="6"]::before { | ||
background-image: url('./image/6.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="7"]::before { | ||
background-image: url('./image/7.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="8"]::before { | ||
background-image: url('./image/8.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="9"]::before { | ||
background-image: url('./image/9.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder > .card[data-number="10"]::before { | ||
background-image: url('./image/10.png'); | ||
background-position: center; | ||
background-size: 100%; | ||
} | ||
|
||
.placeholder .card.back{ /* ๋ท๋ฉด ํ์ */ | ||
transition: transform .5s; | ||
transform: rotateY(0deg); | ||
} | ||
.placeholder .card.front{ /* ํด๋ฆญ ํ ์๋ฉด ํ์ */ | ||
display: block; | ||
transition: transform .5s; | ||
transform: rotateY(180deg); | ||
} | ||
.placeholder .card.front::before{ | ||
visibility: visible; | ||
} | ||
.placeholder .card.matched:before{ /* ๋งค์นญ๋ ์๋ฉด ๋ฐฐ๊ฒฝ์ ๋ณ๊ฒฝ */ | ||
background-color: #673ab7; | ||
color: #fff; | ||
} | ||
.placeholder > .card.back:hover{ /* ์นด๋ ๋ง์ฐ์ค ํธ๋ฒ */ | ||
transform: scale(1.1); | ||
transition: transform 0.1s linear; | ||
box-shadow: 1px 4px 15px -3px rgba(0,0,0,0.5); | ||
} | ||
input[type=button]{ | ||
padding: 5px 20px; | ||
margin: 20px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="placeholder"></div> | ||
<input type="button" name="init" value="๋ค์ ์์" onclick="doneFinding()"> | ||
<script src="./memorycard.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
let cardCount = 20, row = 5, column = Math.floor(cardCount/5), pair = -1, pairindex = -1 // ์นด๋ ๊ฐ์, ํ์, ๋ง๋ ์ง ์นด์ดํธ์ฉ ๋ณ์ | ||
let arrDeck = [] // ์นด๋ ๋ฐฐ์ด | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
cardCount = row * column // ๊ฐ๋ก*์ธ๋ก ๊ฐ์๋ฅผ ๋ฌด์กฐ๊ฑด ๋ง์ถค | ||
document.documentElement.style.setProperty('--row', row) | ||
|
||
// UI ์์ฑ | ||
for (let i = 0; i < cardCount; i++) { | ||
let el = document.createElement('div') | ||
el.id = 'card' + i | ||
el.classList.add('card') | ||
el.classList.add('back') | ||
document.querySelector('.placeholder').appendChild(el) | ||
} | ||
|
||
// ํด๋ฆญ ์ด๋ฒคํธ ํธ๋ค๋ฌ | ||
document.querySelector('.placeholder').addEventListener('click', (e) => { | ||
if (e.target.classList.contains('card') && e.target.classList.contains('back')) { | ||
console.log('clicked'); | ||
e.target.classList.remove('back') | ||
e.target.classList.add('front') | ||
e.target.style.backgroundImage = `url("./image/${e.target.dataset.number}.png")` // ์๋ฉด ์ด๋ฏธ์ง ์ค์ | ||
} | ||
}) | ||
|
||
// ์ ๋๋ฉ์ด์ ์๋ฃ ํธ๋ค๋ฌ - ์ ๋๋ฉ์ด์ ์ข ๋ฃ ํ ๋งค์นญ ํ๋จ | ||
document.querySelector('.placeholder').addEventListener('transitionend', (e) => { | ||
if (e.target.classList.contains('card')) { | ||
console.log('transitionended'); | ||
if (e.target.classList.contains('front')) { | ||
if (pair < 0) { | ||
pair = e.target.dataset.number | ||
pairindex = e.target.dataset.index | ||
} else { | ||
if (pair == e.target.dataset.number && pairindex != e.target.dataset.index) { | ||
// ๋งค์น๋จ - ์ปฌ๋ฌ๋ง | ||
document.querySelectorAll('.placeholder .card.front').forEach((card) => { card.classList.add('matched'); }) | ||
pair = -1 | ||
pairindex = -1 | ||
if (document.querySelector('.placeholder .card:not(.matched)') == null) { | ||
// ์๋ฃ | ||
console.log('card finding end.') | ||
doneFinding() | ||
} | ||
} else if (pairindex != e.target.dataset.index) { | ||
// ๋งค์น์๋จ - ํ์ด ๋ฆฌ์ | ||
document.querySelectorAll('.placeholder .card.front:not(.matched)').forEach((card) => { | ||
card.classList.remove('front') | ||
card.classList.add('back') | ||
card.style.backgroundImage = 'url("./image/0.png")' // ๋ท๋ฉด ์ด๋ฏธ์ง๋ก ์ฌ์ค์ | ||
}) | ||
pair = -1 | ||
pairindex = -1 | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
// ๋ฐฐ์ด ์ ํ | ||
reShuffle(false) | ||
// ์ ๋ณด ์ด๊ธฐํ | ||
initCard() | ||
}) | ||
|
||
function initCard() { | ||
// ์นด๋์ ์ ํ ์ซ์ ์ง์ | ||
for (let i = 0; i < cardCount; i++) { | ||
document.querySelectorAll('.placeholder .card').forEach((card, idx) => { | ||
card.dataset.number = arrDeck[idx] | ||
card.dataset.index = idx | ||
}) | ||
} | ||
|
||
// ์ด๊ธฐํ ์ ๋๋ฉ์ด์ | ||
let init = window.setInterval(() => { | ||
let card = document.querySelector('.placeholder .card:not(.back)') | ||
if (card) { | ||
card.classList.remove('front') | ||
card.classList.remove('matched') | ||
card.classList.add('back') | ||
card.style.backgroundImage = 'url("./image/0.png")' // ๋ท๋ฉด ์ด๋ฏธ์ง๋ก ์ฌ์ค์ | ||
} else { | ||
window.clearInterval(init) | ||
} | ||
}, 50); | ||
} | ||
|
||
// ๋ฐฐ์ด ์ ํ ํธ์ถ์ฉ | ||
function reShuffle(bReInit) { | ||
if (!bReInit) { | ||
for (let i = 0; i < Math.floor(cardCount / 2); i++) { | ||
arrDeck.push(i + 1, i + 1) | ||
} | ||
} | ||
arrDeck = fyShuffler(arrDeck) | ||
} | ||
|
||
// ๋ฐฐ์ด ์ ํ ๋ฉ์ธ | ||
const fyShuffler = (arr) => { | ||
for (let i = arr.length - 1; i > 0; i--) { | ||
const j = Math.floor((i + 1) * Math.random()); | ||
[arr[i], arr[j]] = [arr[j], arr[i]]; // ๋ฐฐ์ด ๊ฐ ๊ตํ | ||
} | ||
return arr | ||
} | ||
|
||
// ๋ค ์ฐพ์ ํ ์ฌ ์คํ ์ ํ | ||
function doneFinding() { | ||
if (confirm('์ฐพ๊ธฐ ์๋ฃ! ๋ฐ์คํฌ์์ ์ํ์ ์๋ นํด ์ฃผ์ธ์')) { | ||
reShuffle(true) | ||
initCard() | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.