Jump to content

DUVIDAS EM CRIAR O GERADOR DA CHAVE PARA MASTER MIND EM JAVASCRIPT


tiratrocos

Recommended Posts

AMIGOS, EU TENHO UM TRABALHO PARA EXAME PARA TERMINAR, QUE É O JOGO DO MASTER MIND.

JA FIZ O JOGO TODO E ATE JA INCLUI A CHAVE SECRETA MANUALMENTE E O JOGO FUNCIONA, AGORA O QUE TENHO DE FAZER É CRIAR A FUNÇAO GERAR CHAVE PARA QUE CADA VEZ QUE EU INICIO O JOGO ELE GERE A NOVA CHAVE . EU ENVIO aqui O CODIGO TODO, PARA LEREM E VEREM COMO POSSO COLOCAR O GERARDOR, TALVEZ COM A FUNÇAO RANDOM .

[censurado]

<html>
<head>
<script language="javascript">
var 	maximocores=6,
maximocolunas=4,
maximolinhas=10,
Chave = new Array(),
ACores = new Array();
ACores[-3]="preto.bmp";
ACores[-2]="brancoo.bmp";
ACores[-1]="branco.bmp";
ACores[0]="azul.bmp";
ACores[1]="red.bmp";
ACores[2]="amarelo.bmp";
ACores[3]="verde.bmp";
ACores[4]="lilas.bmp";
ACores[5]="cinza.bmp";
Chave[0] = 1;
Chave[1] = 0;
Chave[2] = 1;
Chave[3] = 3;



function setcolor(Obj){
Obj.value++;
if (Obj.value >= maximocores) Obj.value = 0;
Obj.src = ACores[Obj.value];
}

function VALIDA(F,b,c){

var 	MinhaChave = new Array(),
	ChaveAux   = new Array();

MinhaChave[0] = eval("F.form."+b+"1.value");
MinhaChave[1] = eval("F.form."+b+"2.value");
MinhaChave[2] = eval("F.form."+b+"3.value");
MinhaChave[3] = eval("F.form."+b+"4.value");
for(x=0;x<maximocolunas;x++)
	ChaveAux[x] = Chave[x];

// Verifica se tem pinos
for (x=0;x<maximocolunas;x++) 
	if (MinhaChave[x]==-1) {
		alert("Complete a Jogada por Favor");
		return;
}

// Tranca a linha de trabalho
Tranca(F.form,b,true);

// Verifica no certo no sitio certo
for(x=0;x<maximocolunas;x++) {
	if (MinhaChave[x] == ChaveAux[x]){
		MinhaChave[x]=-2;
		ChaveAux[x]=-4;
	}
}

// Verifica fora do sitio
for(x=0;x<=maximocolunas;x++)
	for(y=0;y<maximocolunas;y++)
		if (MinhaChave[x]==ChaveAux[y]) {
				MinhaChave[x] = -3 
				ChaveAux[y] = -4;
				y = maximocolunas;
		}

// Mostra o resultado
for(x=0,z=0;x<maximocolunas;x++)
	if (MinhaChave[x]==-3 || MinhaChave[x]==-2) {
		eval("F.form."+b+"R"+(z+1)+".src=ACores[MinhaChave["+x+"]]");
		z++;
	}

// Ver se tem tudo certo
for(x=0,soma=0;x<maximocolunas;x++)
	if (MinhaChave[x]==-2) soma++;
if (soma==maximocolunas) {
	Fim(F.form,true);
	return;
}

// Vai para a proxima Linha
if (c=="X") {

	Fim(F.form,false);
	return false;
}
Tranca(F.form,c,false);

}

function Fim(F,Ganhou) {

if (Ganhou) alert("Ganhou");
else alert("Perdeu");

F.PB.disabled=false;

F.X1.src = ACores[Chave[0]];
F.X2.src = ACores[Chave[1]];
F.X3.src = ACores[Chave[2]];
F.X4.src = ACores[Chave[3]];
}

function Tranca(F,Ch,Valor){

eval("F."+Ch+"1.disabled="+Valor+";");
eval("F."+Ch+"2.disabled="+Valor+";");
eval("F."+Ch+"3.disabled="+Valor+";");
eval("F."+Ch+"4.disabled="+Valor+";");
eval("F."+Ch+"R1.disabled="+Valor+";");
eval("F."+Ch+"R2.disabled="+Valor+";");
eval("F."+Ch+"R3.disabled="+Valor+";");
eval("F."+Ch+"R1.disabled="+Valor+";");
eval("F."+Ch+"V.disabled="+Valor+";");
}

function Limpa(F,ch){

eval("F."+ch+"1.value=-1;");
eval("F."+ch+"1.src=ACores[-1];");
eval("F."+ch+"2.value=-1;");
eval("F."+ch+"2.src=ACores[-1];");
eval("F."+ch+"3.value=-1;");
eval("F."+ch+"3.src=ACores[-1];");
eval("F."+ch+"4.value=-1;");
eval("F."+ch+"4.src=ACores[-1];");

eval("F."+ch+"R1.src=ACores[-1]");
eval("F."+ch+"R2.src=ACores[-1]");
eval("F."+ch+"R3.src=ACores[-1]");
eval("F."+ch+"R4.src=ACores[-1]");
}


function Iniciar(F){


// Tranca todas as linhas menos a primeira		;
Tranca(F,"A",false);
Tranca(F,"B",true);
Tranca(F,"C",true);
Tranca(F,"D",true);
Tranca(F,"E",true);
Tranca(F,"F",true);
Tranca(F,"G",true);
Tranca(F,"H",true);
Tranca(F,"I",true);
Tranca(F,"J",true);

// Limpa o ecran
Limpa(F,"A");
Limpa(F,"B");
Limpa(F,"C");
Limpa(F,"D");
Limpa(F,"E");
Limpa(F,"F");
Limpa(F,"G");
Limpa(F,"H");
Limpa(F,"I");
Limpa(F,"J");

// Gera a chave

/*

E aqui que devem meter o codigo

*/

// Limpa a Chave de Cima
F.X1.src = ACores[-1];
F.X2.src = ACores[-1];
F.X3.src = ACores[-1];
F.X4.src = ACores[-1];

// Disable do botao de novo jogo
F.PB.disabled=true;
}
</script>
</head>
<body onLoad="javascript:Iniciar(OLA);">
<form name=OLA method=GET>

<input type=button name=PB onclick="javascript:Iniciar(this.form)" value="Novo Jogo">
<table border=3 bordercolor=#FF0000>
<tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 name=X1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 name=X2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 name=X3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 name=X4></td>
</tr>
<tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=A1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=A2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=A3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=A4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=AR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=AR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=AR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=AR4></td>
<td><INPUT TYPE=button value="Validar" Name=AV onclick="javascrpit:return VALIDA(this, 'A', 'B')"></td>

</tr>
<tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=B1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=B2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=B3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=B4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=BR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=BR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=BR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=BR4></td>
<td><INPUT TYPE=button value="Validar" Name=BV onclick="javascrpit:return VALIDA(this, 'B', 'C')"></td>
</tr><tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=C1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=C2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=C3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=C4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=CR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=CR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=CR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=CR4></td>
<td><INPUT TYPE=button value="Validar" Name=CV onclick="javascrpit:return VALIDA(this, 'C', 'D')"></td>
</tr><tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=D1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=D2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=D3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=D4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=DR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=DR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=DR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=DR4></td>
<td><INPUT TYPE=button value="Validar" Name=DV onclick="javascrpit:return VALIDA(this, 'D', 'E')"></td>
</tr><tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=E1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=E2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=E3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=E4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=ER1>
<image src="branco.bmp" width=25 height=25 value=-1 name=ER2>
<image src="branco.bmp" width=25 height=25 value=-1 name=ER3>
<image src="branco.bmp" width=25 height=25 value=-1 name=ER4></td>
<td><INPUT TYPE=button value="Validar" Name=EV onclick="javascrpit:return VALIDA(this, 'E', 'F')"></td>
</tr><tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=F1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=F2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=F3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=F4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=FR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=FR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=FR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=FR4></td>
<td><INPUT TYPE=button value="Validar" Name=FV onclick="javascrpit:return VALIDA(this, 'F', 'G')"></td>
</tr><tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=G1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=G2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=G3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=G4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=GR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=GR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=GR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=GR4></td>
<td><INPUT TYPE=button value="Validar" Name=GV onclick="javascrpit:return VALIDA(this, 'G', 'H')"></td>
</tr><tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=H1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=H2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=H3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=H4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=HR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=HR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=HR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=HR4></td>
<td><INPUT TYPE=button value="Validar" Name=HV onclick="javascrpit:return VALIDA(this, 'H', 'I')"></td>
</tr><tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=I1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=I2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=I3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=I4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=IR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=IR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=IR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=IR4></td>
<td><INPUT TYPE=button value="Validar" Name=IV onclick="javascrpit:return VALIDA(this, 'I', 'J')"></td>
</tr><tr>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=J1></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=J2></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=J3></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=J4></td>
<td><image src="branco.bmp" width=25 height=25 value=-1 onclick="javascript:setcolor(this)" name=JR1>
<image src="branco.bmp" width=25 height=25 value=-1 name=JR2>
<image src="branco.bmp" width=25 height=25 value=-1 name=JR3>
<image src="branco.bmp" width=25 height=25 value=-1 name=JR4></td>
<td><INPUT TYPE=button value="Validar" Name=JV onclick="javascrpit:return VALIDA(this, 'J', 'X')"></td>
</tr>
</table>
</script>
</form>
</body>
</html>
Link to comment
Share on other sites

1 - Usar apenas caps é má educação.

2 - Não é por dares o teu mail que vais receber ajuda mais depressa.

3 - A não ser que queiras receber SPAM, não te aconselho a postares o teu email assim à toa.

4 - Usa o GeSHi.

5 - Posta uma dúvida em específico, fiquei sem saber o que funciona e o que não funciona.

Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.