Skip to content
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
38 changes: 38 additions & 0 deletions memory game/game.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
body{
background-color: #33FF33;
}
#maintable td{
width: 100px;
text-align: center;
height: 50px;
background-color: gray;
}
img{
visibility: hidden;
height: 50px;
width: 50px;
}
#maintable div{
background-color: #E8E8E8;
width: 100px;
height: 50px;
}
#maintable{
position: relative;
margin:auto;
}
h1{
text-align: center;
color: brown;
}
#instructions{
color: #330000;
}
#follow{
background-color: black;
color: white;
text-align: center;
}
#below{
margin-left: 550px;
}
67 changes: 67 additions & 0 deletions memory game/game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<html>
<head>
<title>Memory Game</title>
<link rel="stylesheet" type="text/css" href="game.css">
<script type="text/javascript" src="game.js"></script>
</head>
<body>
<h1>Welcome to Memory Game</h1>
<p id="instructions">The aim of the game is to match the hide picture pairs.When clicking on a box, it shows the hidden picture. When the next card is matching you have found a pair. That pair stays uncovered. If two cards are not matching, it is being covered up agian. The game is fininshed if you uncover all the pairs. Try to do it with as little tries as possible.</p>
<p id="follow">Please click on <strong>Start</strong> to play the game</p>
<table id="mainTable">
<tr>
<td><div class="img_tite" id="tdid0"><img src="images\image_0.jpg" id="imgid0"></div></td>
<td ><div class="img_tite" id="tdid1" ><img src="images\image_1.jpg" id="imgid1"></div></td>
<td ><div class="img_tite" id="tdid2" ><img src="images\image_2.jpg" id="imgid2"></div></td>
<td ><div class="img_tite" id="tdid3"><img src="images\image_3.jpg" id="imgid3"></div></td>
<td ><div class="img_tite" id="tdid4" ><img src="images\image_4.jpg" id="imgid4"></div></td>
<td ><div class="img_tite" id="tdid5" ><img src="images\image_5.jpg" id="imgid5"></div></td>
</tr>
<tr>
<td ><div class="img_tite" id="tdid6" ><img src="images\image_6.jpg" id="imgid6"></div></td>
<td ><div class="img_tite" id="tdid7" ><img src="images\image_7.jpg" id="imgid7"></div></td>
<td ><div class="img_tite" id="tdid8" ><img src="images\image_8.jpg" id="imgid8"></div></td>
<td ><div class="img_tite" id="tdid9" ><img src="images\image_9.jpg" id="imgid9"></div></td>
<td ><div class="img_tite" id="tdid10" ><img src="images\image_10.jpg" id="imgid10"></div></td>
<td ><div class="img_tite" id="tdid11" ><img src="images\image_11.jpg" id="imgid11"></div></td>
</tr>
<tr>
<td ><div class="img_tite" id="tdid12" ><img src="images\image_12.jpg" id="imgid12"></div></td>
<td ><div class="img_tite" id="tdid13" ><img src="images\image_13.jpg" id="imgid13"></div></td>
<td ><div class="img_tite" id="tdid14" ><img src="images\image_14.jpg" id="imgid14"></div></td>
<td ><div class="img_tite" id="tdid15" ><img src="images\image_15.jpg" id="imgid15"></div></td>
<td ><div class="img_tite" id="tdid16" ><img src="images\image_16.jpg" id="imgid16"></div></td>
<td ><div class="img_tite" id="tdid17" ><img src="images\image_17.jpg" id="imgid17"></div></td>
</tr>
<tr>
<td ><div class="img_tite" id="tdid18" ><img src="images\image_0.jpg" id="imgid18"></div></td>
<td ><div class="img_tite" id="tdid19" ><img src="images\image_1.jpg" id="imgid19"></div></td>
<td ><div class="img_tite" id="tdid20" ><img src="images\image_2.jpg" id="imgid20"></div></td>
<td ><div class="img_tite" id="tdid21" ><img src="images\image_3.jpg" id="imgid21"></div></td>
<td ><div class="img_tite" id="tdid22" ><img src="images\image_4.jpg" id="imgid22"></div></td>
<td ><div class="img_tite" id="tdid23" ><img src="images\image_5.jpg" id="imgid23"></div></td>
</tr>
<tr>
<td ><div class="img_tite" id="tdid24" ><img src="images\image_6.jpg" id="imgid24"></div></td>
<td ><div class="img_tite" id="tdid25" ><img src="images\image_7.jpg" id="imgid25"></div></td>
<td ><div class="img_tite" id="tdid26" ><img src="images\image_8.jpg" id="imgid26"></div></td>
<td ><div class="img_tite" id="tdid27" ><img src="images\image_9.jpg" id="imgid27"></div></td>
<td ><div class="img_tite" id="tdid28" ><img src="images\image_10.jpg" id="imgid28"></div></td>
<td ><div class="img_tite" id="tdid29" ><img src="images\image_11.jpg" id="imgid29"></div></td>
</tr>
<tr>
<td ><div class="img_tite" id="tdid30" ><img src="images\image_12.jpg" id="imgid30"></div></td>
<td ><div class="img_tite" id="tdid31" ><img src="images\image_13.jpg" id="imgid31"></div></td>
<td ><div class="img_tite" id="tdid32" ><img src="images\image_14.jpg" id="imgid32"></div></td>
<td ><div class="img_tite" id="tdid33" ><img src="images\image_15.jpg" id="imgid33"></div></td>
<td ><div class="img_tite" id="tdid34" ><img src="images\image_16.jpg" id="imgid34"></div></td>
<td id="tdid35"><div class="img_tite" id="tdid35" ><img src="images\image_17.jpg" id="imgid35"></div></td>
</tr>
</table>
<div id="below">
<label id="minutes">00</label>:<label id="seconds">00</label>
Clicks:<span id="clickSpan">0</span>
<button onclick="startGame();" id="start">Start</button>
</div>
</body>
</html>
178 changes: 178 additions & 0 deletions memory game/game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
var count = 0;
var prevDiv;
var countTile = 0;
var clicks = 0;
var totalSeconds = 0;
var flag = 0;
var arrHide = [];
var complete = 0;

var createAddFunc = function(i){
document.getElementById("tdid" + i).onclick = function(){unhide(String(i));};
};

var createRemovefunc = function(i){
document.getElementById("tdid" + i).setAttribute("onclick"," ");
};

var addClickEvent = function(){
for (var i = 0; i < 36; i++) {
if(arrHide.indexOf(String(i)) >= 0){
createRemovefunc(i);
}
else{
createAddFunc(i);
}
}
};

var removeClickEvent = function(){
for (var i = 0; i < 36; i++) {
createRemovefunc(i);
}
};

var setTime = function(){
var minutesLabel = document.getElementById("minutes");
var secondsLabel = document.getElementById("seconds");
totalSeconds++;
secondsLabel.innerHTML = pad(totalSeconds % 60);
minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
};

var pad = function(val){
var valString = val + "";
if(valString.length < 2){
return "0" + valString;
}
else{
return valString;
}
};

var startTimer = function(){
xInt = setInterval(setTime, 1000);
};

var initializeImg = function(){
var ar = new Array();
for (var i = 0; i < 36; i++) {
ar[i] = i;
};
ar.sort(function(){return Math.random() - 0.5;});
for (var i = 0; i < 36; i++) {
if (ar[i] > 17) {
tmp = ar[i] - 18;
}
else{
tmp = ar[i];
}
document.getElementsByTagName('img')[i].style.visibility = "hidden";
document.getElementsByTagName('img')[i].src = "images\\image_" + tmp + ".jpg";
}
};

var stopTimer = function(){
if (complete != 1) {
alert("You did not complete the game!!Please come again!!");
}
else
complete = 0;
document.getElementById('start').style.display = "initial";
clearInterval(xInt);
document.getElementById("minutes").innerHTML = "00";
document.getElementById("seconds").innerHTML = "00";
totalSeconds = 0;
belowDiv.removeChild(stopButton);
belowDiv.removeChild(resButton);
flag = 0;
click = 0;
removeClickEvent();
initializeImg();
document.getElementById("clickSpan").innerHTML = "0";
arrHide = [];
};

var pauseTimer = function(){
if(stop != "yes"){
clearInterval(xInt);
resButton.innerHTML = "Resume";
stop = "yes";
removeClickEvent();
}
else{
startTimer();
stop = "no";
resButton.innerHTML = "Pause";
addClickEvent();
}
};

var startGame = function(){
document.getElementById('start').style.display = "none";
initializeImg();
addClickEvent();
if(flag != 1){
flag = 1;
stopButton = document.createElement("Button");
text = document.createTextNode("Stop");
stopButton.appendChild(text);
belowDiv = document.getElementById('below');
belowDiv.appendChild(stopButton);
resButton = document.createElement("Button");
text = document.createTextNode("Pause");
resButton.appendChild(text);
belowDiv = document.getElementById('below');
belowDiv.appendChild(resButton);
}
startTimer();
stopButton.onclick = function(){
stopTimer();
};
resButton.onclick = function(){
pauseTimer();
};
};

var unhide = function(divid){
currId = divid;
clicks++;
document.getElementById("clickSpan").innerHTML = clicks;
var currDiv = "imgid" + divid;
createRemovefunc(currId);
document.getElementById(currDiv).style.visibility = "visible";
if(count === 0){
prevDiv = currDiv;
prevId = currId;
count++;
}
else if(count === 1){
removeClickEvent();
count = 0;
src1 = document.getElementById(currDiv).src;
src2 = document.getElementById(prevDiv).src;
if (src1 != src2) {
setTimeout(function(){
document.getElementById(currDiv).style.visibility = "hidden";
document.getElementById(prevDiv).style.visibility = "hidden";
addClickEvent();
},500);
}
else{
arrHide.push(currId);
arrHide.push(prevId);
addClickEvent();
countTile++;
if (countTile == 18) {
alert("WoooHooo You Won!!!\n Your Time : " + document.getElementById('minutes').innerHTML + ":" + document.getElementById('seconds').innerHTML);
countTile = 0;
complete = 1;
stopTimer();
}
}
}
};

window.onload = function(){
initializeImg();
};
Binary file added memory game/images/image_0.jpg
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 memory game/images/image_1.jpg
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 memory game/images/image_10.jpg
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 memory game/images/image_11.jpg
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 memory game/images/image_12.jpg
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 memory game/images/image_13.jpg
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 memory game/images/image_14.jpg
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 memory game/images/image_15.jpg
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 memory game/images/image_16.jpg
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 memory game/images/image_17.jpg
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 memory game/images/image_2.jpg
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 memory game/images/image_3.jpg
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 memory game/images/image_4.jpg
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 memory game/images/image_5.jpg
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 memory game/images/image_6.jpg
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 memory game/images/image_7.jpg
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 memory game/images/image_8.jpg
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 memory game/images/image_9.jpg
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 memory game/memory_game.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.