Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda para um sistema de jogo da velha


joersbrasil

Pergunta

1 resposta a esta questão

Posts Recomendados

  • 0

Fiz uns ajustes aqui:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="pt-br">
<title>Jogo da Velha</title>
</head>
<body>
<center>
<form name="game" action="sua_pagina.php" method="post">
<table border=0>
<td>
<table border=0 style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">
<tr>
<td style="border-left-width: 1; border-right-style: solid; border-right-width: 1; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1" bordercolor="#000000"><a href="java script:yourChoice('A')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank.jpg" border=0 height=100 width=100 name=A alt="Top-Left"></a></td>
<td bordercolor="#000000"><a href="java script:yourChoice('B')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank.jpg" border=0 height=100 width=100 name=B alt="Top-Center"></a></td>
<td style="border-left-style: solid; border-left-width: 1; border-right-width: 1; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1" bordercolor="#000000"><a href="java script:yourChoice('C')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank.jpg" border=0 height=100 width=100 name=C alt="Top-Right"></a></td>
</tr>
<tr>
<td style="border-left-width: 1; border-right-style: solid; border-right-width: 1; border-top-width: 1; border-bottom-width: 1" bordercolor="#000000"><a href="java script:yourChoice('D')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank.jpg" border=0 height=100 width=100 name=D alt="Middle-Left"></a></td>
<td style="border-left-width: 1; border-right-width: 1; border-top-style: solid; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1" bordercolor="#000000"><a href="java script:yourChoice('E')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank_rua.jpg" border=0 height=100 width=100 name=E alt="Middle-Center"></a></td>
<td style="border-left-style: solid; border-left-width: 1; border-right-width: 1; border-top-width: 1; border-bottom-width: 1" bordercolor="#000000"><a href="java script:yourChoice('F')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank.jpg" border=0 height=100 width=100 name=F alt="Middle-Right"></a></td>
</tr>
<tr>
<td style="border-left-width: 1; border-right-style: solid; border-right-width: 1; border-top-style: solid; border-top-width: 1" bordercolor="#000000"><a href="java script:yourChoice('G')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank.jpg" border=0 height=100 width=100 name=G alt="Bottom-Left"></a></td>
<td><a href="java script:yourChoice('H')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank.jpg" border=0 height=100 width=100 name=H alt="Bottom-Center"></a></td>
<td style="border-left-style: solid; border-left-width: 1; border-right-width: 1; border-top-style: solid; border-top-width: 1; border-bottom-width: 1" bordercolor="#000000"><a href="java script:yourChoice('I')">
<img src="http://www.ruajava.kit.net/pages/pictures/blank.jpg" border=0 height=100 width=100 name=I alt="Bottom-Right"></a></td>
</tr>
</table>
</td>
<td>
<table>
<tr><td><input type=text size=5 name=you></td><td>
<font face="Verdana" style="font-size: 8pt">Você</font></td></tr>
<tr><td><input type=text size=5 name=computer></td><td>
<font face="Verdana" style="font-size: 8pt">Computador</font></td></tr>
<tr><td><input type=text size=5 name=ties></td><td>
<font face="Verdana" style="font-size: 8pt">Empates</font></td></tr>
</table>
</td>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p align="center">
<input type='button' id="jogar" value="Jogar Denovo" onClick="playAgain();">
<input type='button' value="Como Jogar" onClick="help();">
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</table>
<input type="hidden" id="resultado" name="resultado" />
<input type="hidden" id="placar" name="placar" />
</form>
</center>
<p><p align="center">
<script>
x="http://www.ruajava.kit.net/pages/pictures/x.jpg";
o="http://www.ruajava.kit.net/pages/pictures/o.jpg";
blank="http://www.ruajava.kit.net/pages/pictures/blank.jpg";
pause=0;
all=0;
a=0;
b=0;
c=0;
d=0;
e=0;
f=0;
g=0;
h=0;
i=0;
temp="";
ok=0;
cf=0;
choice=9;
aRandomNumber=0;
comp=0;
t=0;
wn=0;
ls=0;
ts=0;
dx=document.game;
dy=document.images;
function help(){
alert("Bem-Vindo ao jogo da velha! Você joga com o X e o computador com o 0. Escolha o espaço que você queira colocar seu X clicando nele. O primeiro que conseguir fazer uma linha de 3 é o vencedor. Boa Sorte!!")
}
function logicOne(){
if(a==1&&b==1&&c==1||a==1&&d==1&&g==1||a==1&&e==1&&i==1||b==1&&e==1&&h==1||d==1&&e==1&&f==1||g==1&&h==1&&i==1||c==1&&f==1&&i==1||g==1&&e==1&&c==1)all=1;
if(a==2&&b==2&&c==2||a==2&&d==2&&g==2||a==2&&e==2&&i==2||b==2&&e==2&&h==2||d==2&&e==2&&f==2||g==2&&h==2&&i==2||c==2&&f==2&&i==2||g==2&&e==2&&c==2)all=2;
if(a!=0&&b!=0&&c!=0&&d!=0&&e!=0&&f!=0&&g!=0&&h!=0&&i!=0&&all==0)all=3;
}
function logicTwo(v){
if(temp==""){
if(a==v&&b==v&&c==0)temp="C";
if(a==v&&b==0&&c==v)temp="B";
if(a==0&&b==v&&c==v)temp="A";
if(a==v&&d==v&&g==0)temp="G";
if(a==v&&d==0&&g==v)temp="D";
if(a==0&&d==v&&g==v)temp="A";
if(a==v&&e==v&&i==0)temp="I";
if(a==v&&e==0&&i==v)temp="E";
if(a==0&&e==v&&i==v)temp="A";
if(b==v&&e==v&&h==0)temp="H";
if(b==v&&e==0&&h==v)temp="E";
if(b==0&&e==v&&h==v)temp="B";
if(d==v&&e==v&&f==0)temp="F";
if(d==v&&e==0&&f==v)temp="E";
if(d==0&&e==v&&f==v)temp="D";
if(g==v&&h==v&&i==0)temp="I";
if(g==v&&h==0&&i==v)temp="H";
if(g==0&&h==v&&i==v)temp="G";
if(c==v&&f==v&&i==0)temp="I";
if(c==v&&f==0&&i==v)temp="F";
if(c==0&&f==v&&i==v)temp="C";
if(g==v&&e==v&&c==0)temp="C";
if(g==v&&e==0&&c==v)temp="E";
if(g==0&&e==v&&c==v)temp="G";
}
}
function clearOut(){
dx.you.value="0";
dx.computer.value="0";
dx.ties.value="0";
}
function checkSpace(){
if(temp=="A"&&a==0){
ok=1;
if(cf==0)a=1;
if(cf==1)a=2;
}
if(temp=="B"&&b==0){
ok=1;
if(cf==0)b=1;
if(cf==1)b=2;
}
if(temp=="C"&&c==0){
ok=1;
if(cf==0)c=1;
if(cf==1)c=2;
}
if(temp=="D"&&d==0){
ok=1;
if(cf==0)d=1;
if(cf==1)d=2;
}
if(temp=="E"&&e==0){
ok=1;
if(cf==0)e=1;
if(cf==1)e=2;
}
if(temp=="F"&&f==0){
ok=1
if(cf==0)f=1;
if(cf==1)f=2;
}
if(temp=="G"&&g==0){
ok=1
if(cf==0)g=1;
if(cf==1)g=2;
}
if(temp=="H"&&h==0){
ok=1;
if(cf==0)h=1;
if(cf==1) h=2;
}
if(temp=="I"&&i==0){
ok=1;
if(cf==0)i=1;
if(cf==1)i=2;
}
}
function yourChoice(chName){
pause=0;
if(all!=0)ended();
if(all==0){
cf=0;
ok=0;
temp=chName;
checkSpace();
if(ok==1){
dy[chName].src=x;
}
if(ok==0)taken();
process();
if((all==0)&&(pause==0))myChoice();
}
}
function taken(){
alert("Este espaço já está ocupado, por favor escolha outro.")
pause=1;
}
function myChoice(){
temp="";
ok=0;
cf=1;
logicTwo(2);
logicTwo(1);
checkSpace();
while(ok==0){
aRandomNumber=Math.random()
comp=Math.round((choice-1)*aRandomNumber)+1;
if(comp==1)temp="A";
if(comp==2)temp="B";
if(comp==3)temp="C";
if(comp==4)temp="D";
if(comp==5)temp="E";
if(comp==6)temp="F";
if(comp==7)temp="G";
if(comp==8)temp="H";
if(comp==9)temp="I";
checkSpace();
}
dy[temp].src=o;
process();
}
function ended(){
alert("O jogo acabou, para jogar novamente clique no botão Jogar Denovo.")
}
function process() {
logicOne();
if(all==1){alert("Você ganhou, parabéns!");wn++}
if(all==2){alert("Te peguei! Eu venci!");ls++}
if(all==3){alert("Empate não pega mal nem pra mim nem pra você. Vamos jogar denovo?");ts++}
if(all!=0){
dx.you.value=wn;
dx.computer.value=ls;
dx.ties.value=ts;
if(wn+ls==3){
    document.getElementById('jogar').disabled=true;
    document.getElementById('resultado').value=((wn>ls)?'V':'N');
    document.getElementById('placar').value=wn+":"+ls;
    alert("Aqui envia o formulario!!! Para isso descomente a linha abaixo");
    // dx.submit();
}
}
}
function playAgain(){
if(all==0){
if(confirm("Quer desistir desse jogo?"))reset();
}
if(all>0)reset();
}
function reset(){
all=0;
a=0;
b=0;
c=0;
d=0;
e=0;
f=0;
g=0;
h=0;
i=0;
temp="";
ok=0;
cf=0;
choice=9;
aRandomNumber=0;
comp=0;
dy.A.src=blank;
dy.B.src=blank;
dy.C.src=blank;
dy.D.src=blank;
dy.E.src=blank;
dy.F.src=blank;
dy.G.src=blank;
dy.H.src=blank;
dy.I.src=blank;
if(t==0){t=2;myChoice()}
t--;
}
</script>
<!-- Script Size: 4.16 KB --> 
</body>
</html>
Vamos as mudanças: Otimizei o script para diminuir o tamanho; e fiz o que você pediu em 1, 2 e 3. Quando for computado 3 jogos válidos, o botão Jogar Denovo será desativado. criei dois campos hidden para colocar os resultados: o primeiro "resultado" coloco V se ele ganhou do computador e N caso contrario. O segundo campo "placar" coloco como foram distribuidas os jogos; Tem o seguinte formato:
nv:nd
nv=Nº de vitorias nd=Nº de derrotas. Além disso, se você quiser depois ele envia o formulario automaticamente. Para isso tem que descomentar a linha:
// dx.submit();
ficando:
dx.submit();

e trocar o action do form pela pagina correta.

Em relação ao 4º item, você precisa colocar como mais ou menos será a distribuição dos logotipos.

Tipo, quantos podem, quais, como é o HTML. etc;

Acretido que isso possa ser feito com linguagem server-side tambem (PHP, ASP, etc).

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...