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

Reset do jogo e parabéns no final #1

Merged
merged 1 commit into from Apr 21, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added memory/.index.html.swp
Binary file not shown.
218 changes: 111 additions & 107 deletions memory/index.html
@@ -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>