Estou aqui com um problema que não consigo resolver. Quando um utilizador acerta numa mina, eu quero mostrar as minas todas, mas não o estou a conseguir...
Está aqui o código, para vos ser mais preceptível, do que eu estar a explicar.
- Código: Seleccionar todos
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<style type="text/css">
body{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:20px;
text-align:center;
}
p{
text-align:center;
font-weight:bolder;
color:#333366;
}
table{
border-color:#333366;
border-collapse:collapse;
border-width:medium;
table-layout:fixed;
width:50px;
height:50px;
}
td{
width:18px;
height:18px;
font-size:10px;
text-align:center;
background-color:#505086;
}
div{
width:18px;
height:18px;
}
.game{
text-align: center;
width: 800px;
heigth: 800px;
}
</style>
<script type="text/javascript" language="javascript">
var contMinas = 0;
var minas = new Array();
function criaMinas(){
//cria as minas
do{
var i = Math.round(Math.random() * 21 + 1);
var j = Math.round(Math.random() * 21 + 1);
var mina = i + "" + j;
mina = eval(mina);
var existe = false;
for(var m = 0; m < minas.length; m++){
if(minas[m] == mina)
existe = true;
}
if(!existe){
minas[contMinas] = mina;
contMinas++;
}
}
while(contMinas < 30);
}
function oJogo(){
criaMinas();
var tabuleiro = "<table border='1'>";
//desenha o tabuleiro
for(var i = 0; i < 22; i++){
tabuleiro += "<tr>";
for(var j = 0; j < 22; j++)
tabuleiro += "<td><div id=" + (i + 1) + "" + (j + 1) +" onClick=\"verificaMina(this)\" onMouseDown=\"mudaCor(this)\">" + (i + 1) +"" + (j + 1) +"</div></td>"
tabuleiro += "</tr>";
}
tabuleiro += "</tabuleiro>";
document.write(tabuleiro);
document.write(minas.join(", "));
}
function verificaMina(oDiv){
for(var i = 0; i < minas.length; i++){
if(minas[i] == eval(oDiv.id)){
alert("Perdeste! Boa sorte para a próxima vez! :(");
oDiv.style.background = "red";
mostraJogo();
return;
}
else
oDiv.style.background = "orange";
}
}
function mudaCor(oDiv){
oDiv.style.background = "blue";
}
function mostraJogo(){
var casa = document.mina[1];
casa.style.background = "red";
}
</script>
</head>
<body>
<div id="game"><script language="javascript" type="text/javascript">oJogo();</script></div>
</body>
</html>
cps[/code]

