Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dá parabéns quando jogo acaba e possui botão para recomeçar.
Agora o usuário fica mais feliz e tem a chance de começar de novo =)
- Loading branch information
Wanderley Caloni
committed
Apr 20, 2013
1 parent
3e54584
commit c6c9e4c
Showing
2 changed files
with
111 additions
and
107 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,107 +1,111 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<title>JOGO DA MEMORIA</title> | ||
<center><h>JOGO DA MEMORIA</h></center> | ||
<script> | ||
// Fisher-Yates shuffling algorithm | ||
// Taken at http://sedition.com/perl/javascript-fy.html | ||
function randomize_it (this_array) { | ||
var i = this_array.length; | ||
if (i == 0) return false; | ||
while (--i) | ||
{ | ||
var j = Math.floor(Math.random() * ( i + 1 )); | ||
var tempi = this_array[i]; | ||
var tempj = this_array[j]; | ||
this_array[i] = tempj; | ||
this_array[j] = tempi; | ||
} | ||
} | ||
|
||
function already_clicked_this(id) | ||
{ | ||
for (i = 0; i < ids_used.length; i++) | ||
{ | ||
if (ids_used[i] == id) return true; | ||
} | ||
return false; | ||
} | ||
|
||
var old_address = []; | ||
|
||
function analyze_that(id) | ||
{ | ||
if (already_clicked_this(id) == true) | ||
return; | ||
|
||
quadro = document.getElementById("pos_"+id); | ||
quadro.src = image_mapping[id]; | ||
|
||
if (old_address != "") | ||
{ | ||
ad_1 = document.getElementById("pos_"+old_address[0]); | ||
ad_2 = document.getElementById("pos_"+old_address[1]); | ||
ad_1.src = "11.png"; | ||
ad_2.src = "11.png"; | ||
old_address = []; | ||
} | ||
|
||
if (current_address == "") { | ||
current_address[0] = image_mapping[id]; | ||
current_address[1] = id; | ||
} | ||
else if (current_address[1] != id) | ||
{ | ||
if (current_address[0] != image_mapping[id]) | ||
{ | ||
old_address[1] = current_address[1]; | ||
old_address[0] = id; | ||
current_address = []; | ||
} | ||
else | ||
{ | ||
ids_used.push(current_address[1]); | ||
ids_used.push(id); | ||
current_address = []; | ||
} | ||
} | ||
} | ||
|
||
function write_a_table(image_mapping) | ||
{ | ||
document.write("<table align=\"center\">"); | ||
counter = 0; | ||
for (i = 0; i < 4; i++) | ||
{ | ||
document.write("<tr>"); | ||
for (y = 0; y < 5; y++) { | ||
document.write("<td><div><img id=\"pos_"+counter+"\" src=\"11.png\" onclick=\"analyze_that('" + counter + "');\" /></div></td>"); | ||
counter++; | ||
} | ||
document.write("</tr>"); | ||
} | ||
document.write("</table>"); | ||
} | ||
|
||
var current_address = []; | ||
var image_mapping = Array(); | ||
var ids_used = Array(); | ||
for (i = 0; i < 10; i++) | ||
{ | ||
image_mapping[i] = (i+1) + ".png"; | ||
} | ||
for (i = 0; i < 10; i++) | ||
{ | ||
image_mapping[i+10] = (i+1) + ".png"; | ||
} | ||
|
||
randomize_it(image_mapping); | ||
|
||
write_a_table(image_mapping); | ||
|
||
</script> | ||
</body> | ||
</html> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<title>JOGO DA MEMORIA</title> | ||
<center><h>JOGO DA MEMORIA</h></center> | ||
<script> | ||
// Fisher-Yates shuffling algorithm | ||
// Taken at http://sedition.com/perl/javascript-fy.html | ||
function randomize_it (this_array) { | ||
var i = this_array.length; | ||
if (i == 0) return false; | ||
while (--i) | ||
{ | ||
var j = Math.floor(Math.random() * ( i + 1 )); | ||
var tempi = this_array[i]; | ||
var tempj = this_array[j]; | ||
this_array[i] = tempj; | ||
this_array[j] = tempi; | ||
} | ||
} | ||
|
||
function already_clicked_this(id) | ||
{ | ||
for (i = 0; i < ids_used.length; i++) | ||
{ | ||
if (ids_used[i] == id) return true; | ||
} | ||
return false; | ||
} | ||
|
||
var old_address = []; | ||
|
||
function analyze_that(id) | ||
{ | ||
if (already_clicked_this(id) == true) | ||
return; | ||
|
||
quadro = document.getElementById("pos_"+id); | ||
quadro.src = image_mapping[id]; | ||
|
||
if (old_address != "") | ||
{ | ||
ad_1 = document.getElementById("pos_"+old_address[0]); | ||
ad_2 = document.getElementById("pos_"+old_address[1]); | ||
ad_1.src = "11.png"; | ||
ad_2.src = "11.png"; | ||
old_address = []; | ||
} | ||
|
||
if (current_address == "") { | ||
current_address[0] = image_mapping[id]; | ||
current_address[1] = id; | ||
} | ||
else if (current_address[1] != id) | ||
{ | ||
if (current_address[0] != image_mapping[id]) | ||
{ | ||
old_address[1] = current_address[1]; | ||
old_address[0] = id; | ||
current_address = []; | ||
} | ||
else | ||
{ | ||
ids_used.push(current_address[1]); | ||
ids_used.push(id); | ||
current_address = []; | ||
} | ||
} | ||
|
||
if( ids_used.length == 20 ) | ||
alert('Parabéns! Você ganhou!'); | ||
} | ||
|
||
function write_a_table(image_mapping) | ||
{ | ||
document.write("<table align=\"center\">"); | ||
counter = 0; | ||
for (i = 0; i < 4; i++) | ||
{ | ||
document.write("<tr>"); | ||
for (y = 0; y < 5; y++) { | ||
document.write("<td><div><img id=\"pos_"+counter+"\" src=\"11.png\" onclick=\"analyze_that('" + counter + "');\" /></div></td>"); | ||
counter++; | ||
} | ||
document.write("</tr>"); | ||
} | ||
document.write("</table>"); | ||
} | ||
|
||
var current_address = []; | ||
var image_mapping = Array(); | ||
var ids_used = Array(); | ||
for (i = 0; i < 10; i++) | ||
{ | ||
image_mapping[i] = (i+1) + ".png"; | ||
} | ||
for (i = 0; i < 10; i++) | ||
{ | ||
image_mapping[i+10] = (i+1) + ".png"; | ||
} | ||
|
||
randomize_it(image_mapping); | ||
|
||
write_a_table(image_mapping); | ||
|
||
</script> | ||
<p align="center"><button type="button" onclick="location.reload()">Recomeçar!</button></p> | ||
</body> | ||
</html> |