Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]: Add images to the game #81

Merged
merged 1 commit into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions MemoryGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ var turns = 0; //Number of turns taken.
const Cards = []; //Array to store the Cards.
//Setting the Cards.
for (let j = 0; j < 8; j++) {
r = Math.floor(Math.random() * (90 - 64 + 1)) + 64; //Character set from unicode.
Cards.push(String.fromCharCode(r)); //Push twice.
Cards.push(String.fromCharCode(r));
r = Math.floor(Math.random() * 17); //Random number from 1 to 16.
Cards.push(r); //Push twice.
Cards.push(r);
}
Cards.sort(() => 0.5 - Math.random()); //Random shuffling of Cards.
Cards.push(Cards[0]); //Ignore the Card at 0th positon.
Expand All @@ -23,7 +23,9 @@ for (let f = 1; f <= 16; f++) {
function Buttonclicked(a) {
//Function to be executed once button is clicked.
//a is the parameter which tells which button is clicked.
document.getElementById("button" + a).innerHTML = Cards[a]; //Flip the Card over.
document.getElementById(
"button" + a
).src = `/images/super-smash-bros/${Cards[a]}.png`; //Flip the Card over.
document.getElementById("button" + a).disabled = "disabled"; //Disable clicking the same Card.
document.getElementById("button" + a).style =
"opacity: 0.7;cursor: not-allowed;color:Blue";
Expand All @@ -45,10 +47,14 @@ function checkscore(a) {
"transition-duration: 0.8s;background-color:Tomato;color:White;";
//If invalid, then set the background background-color Orange.
window.setTimeout(function () {
document.getElementById("button" + a).innerHTML = "?";
document.getElementById(
"button" + a
).src = `/images/super-smash-bros/question.png`;
document.getElementById("button" + a).style = style;
document.getElementById("button" + temp).style = style;
document.getElementById("button" + temp).innerHTML = "?";
document.getElementById(
"button" + temp
).src = `/images/super-smash-bros/question.png`;
document.getElementById("button" + temp).disabled = "";
document.getElementById("button" + a).disabled = "";
}, 1200);
Expand Down
Binary file added images/super-smash-bros/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/super-smash-bros/question.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 111 additions & 54 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<title>Memory game</title>
<head>
<style id="style">
.button {
min-width: 120px;
min-height: 120px;
max-width: 120px;
max-height: 120px;
object-fit: contain;
}
.button:hover {
background-color: yellow;
color: black;
Expand All @@ -10,11 +17,11 @@
font-family: 'Brush Script MT', cursive;
color: red;
}
.keys {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 20px;
padding: 20px;
.row {
display: flex;
width: 100%;
justify-content: space-around;
margin-bottom: 2rem;
}
.disabled {
opacity: 0.6;
Expand All @@ -24,55 +31,105 @@
</head>
<body>
<h1 class="h1">Memory game</h1>
<div class="keys">
<button id="button1" class="button" onclick="Buttonclicked(1) ">
?
</button>
<button id="button2" class="button" onclick="Buttonclicked(2) ">
?
</button>
<button id="button3" class="button" onclick="Buttonclicked(3) ">
?
</button>
<button id="button4" class="button" onclick="Buttonclicked(4) ">
?
</button>
<button id="button5" class="button" onclick="Buttonclicked(5) ">
?
</button>
<button id="button6" class="button" onclick="Buttonclicked(6) ">
?
</button>
<button id="button7" class="button" onclick="Buttonclicked(7) ">
?
</button>
<button id="button8" class="button" onclick="Buttonclicked(8) ">
?
</button>
<button id="button9" class="button" onclick="Buttonclicked(9) ">
?
</button>
<button id="button10" class="button" onclick="Buttonclicked(10)">
?
</button>
<button id="button11" class="button" onclick="Buttonclicked(11)">
?
</button>
<button id="button12" class="button" onclick="Buttonclicked(12)">
?
</button>
<button id="button13" class="button" onclick="Buttonclicked(13)">
?
</button>
<button id="button14" class="button" onclick="Buttonclicked(14)">
?
</button>
<button id="button15" class="button" onclick="Buttonclicked(15)">
?
</button>
<button id="button16" class="button" onclick="Buttonclicked(16)">
?
</button>
<div class="row">
<img
id="button1"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(1)"
/>
<img
id="button2"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(2)"
/>
<img
id="button3"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(3)"
/>
<img
id="button4"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(4)"
/>
<img
id="button5"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(5)"
/>
<img
id="button6"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(6)"
/>
<img
id="button7"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(7)"
/>
<img
id="button8"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(8)"
/>
</div>
<div class="row">
<img
id="button9"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(9)"
/>
<img
id="button10"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(10)"
/>
<img
id="button11"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(11)"
/>
<img
id="button12"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(12)"
/>
<img
id="button13"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(13)"
/>
<img
id="button14"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(14)"
/>
<img
id="button15"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(15)"
/>
<img
id="button16"
class="button"
src="/images/super-smash-bros/question.png"
onclick="Buttonclicked(16)"
/>
</div>
<p id="score">Score=0</p>
<p id="Turns">Turns taken=0</p>
Expand Down