USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  ASP - Active Server Page    (Miscelâneas)

Título da Dica:  Jogo da velha
Postada em 3/10/2003 por ^HEAVY-METAL^            
depois de tantos script um joguinho da velha alivia as tensões

<%

Option Explicit



Const IMGx = "x.gif"
Const IMGo = "o.gif"
Const IMGblank = "blank.jpg"


Const END_Not_Yet = 0
Const END_You_Win = 1
Const END_Computer_Win = 2
Const END_Tie = 3


Dim Gameboard
Dim wl1,wl2,wl3,wl4,wl5,wl6,wl7,wl8

If Session("GameBoard") & "" = "" OR Request("PlayAgain") = "Yes" Then
     PlayAgain
end if

GameBoard = Split(Session("GameBoard"),"_")


function GameState()

     wl1 = GameBoard(0) & GameBoard(1) & GameBoard(2)
     wl2 = GameBoard(0) & GameBoard(3) & GameBoard(6)
     wl3 = GameBoard(0) & GameBoard(4) & GameBoard(8)
     wl4 = GameBoard(1) & GameBoard(4) & GameBoard(7)
     wl5 = GameBoard(3) & GameBoard(4) & GameBoard(5)
     wl6 = GameBoard(6) & GameBoard(7) & GameBoard(8)
     wl7 = GameBoard(2) & GameBoard(5) & GameBoard(8)
     wl8 = GameBoard(6) & GameBoard(4) & GameBoard(2)

     if wl1="XXX" or wl2="XXX" or wl3="XXX" or wl4="XXX" or wl5="XXX" or wl6="XXX" or wl7="XXX" or wl8="XXX" Then
          GameState = END_You_Win
     elseif wl1="OOO" or wl2="OOO" or wl3="OOO" or wl4="OOO" or wl5="OOO" or wl6="OOO" or wl7="OOO" or wl8="OOO" Then
          GameState = END_Computer_Win
     elseif Instr ( wl1 & wl5 & wl6 ,"B" ) = 0 then
          GameState = END_Tie
     else
          GameState = END_Not_Yet
     end if

end function


Function Suggest()

     If wl1 = "XXB" or wl1 = "OOB" Then
          Suggest = 2
     elseif wl1 = "XBX" or wl1 = "OBO" Then
          Suggest = 1
     elseif wl1 = "BXX" or wl1 = "BOO" Then
          Suggest = 0
     elseif wl2 = "XXB" or wl2 = "OOB" Then
          Suggest = 6
     elseif wl2 = "XBX" or wl2 = "OBO" Then
          Suggest = 3
     elseif wl2 = "BXX" or wl2 = "BOO" Then
          Suggest = 0
     elseif wl3 = "XXB" or wl3 = "OOB" Then
          Suggest = 8
     elseif wl3 = "XBX" or wl3 = "OBO" Then
          Suggest = 4
     elseif wl3 = "BXX" or wl3 = "BOO" Then
          Suggest = 0
     elseif wl4 = "XXB" or wl4 = "OOB" Then
          Suggest = 7
     elseif wl4 = "XBX" or wl4 = "OBO" Then
          Suggest = 4
     elseif wl4 = "BXX" or wl4 = "BOO" Then
          Suggest = 1
     elseif wl5 = "XXB" or wl5 = "OOB" Then
          Suggest = 5
     elseif wl5 = "XBX" or wl5 = "OBO" Then
          Suggest = 4
     elseif wl5 = "BXX" or wl5 = "BOO" Then
          Suggest = 3
     elseif wl6 = "XXB" or wl6 = "OOB" Then
          Suggest = 8
     elseif wl6 = "XBX" or wl6 = "OBO" Then
          Suggest = 7
     elseif wl6 = "BXX" or wl6 = "BOO" Then
          Suggest = 6
     elseif wl7 = "XXB" or wl7 = "OOB" Then
          Suggest = 8
     elseif wl7 = "XBX" or wl7 = "OBO" Then
          Suggest = 5
     elseif wl7 = "BXX" or wl7 = "BOO" Then
          Suggest = 2
     elseif wl8 = "XXB" or wl8 = "OOB" Then
          Suggest = 2
     elseif wl8 = "XBX" or wl8 = "OBO" Then
          Suggest = 4
     elseif wl8 = "BXX" or wl8 = "BOO" Then
          Suggest = 6
     else
          Suggest = -1
     end if

end function


sub yourChoice(Position)

     if Session("State") = "Dead" Then
          ReportEnded
     Else
          If GameBoard(Position) <> "B" Then
               ReportTaken
          else
               GameBoard(Position) = "X"
          end if
        end if
end sub


sub ReportTaken()
     Response.Write "<H2>POSIÇÃO OCUPADA, ESCOLHA OUTRA.</H2>"
end sub

sub ReportEnded()
     Response.Write "<center><H2>O JOGO JÁ FOI FINALIZADO.</H2></center>"
end sub



sub myChoice()
     Dim NewMove

     NewMove = Suggest()

     While NewMove = -1
          Randomize
          NewMove=int(rnd*9)
          If GameBoard(NewMove) <> "B" Then
               NewMove = -1
          End If
     wend

     GameBoard(NewMove) = "O"
end sub




sub ProcessBoard()

     If Session("State") = "Alive" Then

          Select Case GameState()
               Case END_You_Win
                    Response.Write "<H2>VOCÊ VENCEU, PARABÉNS!<H2>"
                    Session("you") = Session("you") + 1
                    Session("State") = "Dead"

               Case END_Computer_Win
                    Response.Write "<H2>COMPUTADOR VENCEU, TENTE NOVAMENTE.</H2>"
                    Session("computer") = Session("computer") + 1
                    Session("State") = "Dead"

               Case END_Tie
                    Response.Write "<H2>JOGO EMPATADO.</H2>"
                    Session("ties") = Session("ties") + 1
                    Session("State") = "Dead"

          end Select

     End If

end sub


sub playAgain()
     Session("GameBoard") = "B_B_B_B_B_B_B_B_B"
     Session("State") = "Alive"
end sub


sub Display(CellNum)

     If GameBoard(CellNum) = "B" Then
          Response.Write "<form action=velha.asp method=post>"
          Response.Write "<input type=hidden name=pressed value=" & CellNum & ">"
          Response.Write "<input type=image src=" & IMGblank & " border=0 height=100 width=100>"
          Response.Write "</form>"
     elseif GameBoard(CellNum) = "O" Then
          Response.Write "<img src=" & IMGo & " border=0 height=100 width=100>"
     elseif GameBoard(CellNum) = "X" Then
          Response.Write "<img src=" & IMGx & " border=0 height=100 width=100>"
     end if

end sub



If Request("Pressed") & "" <> "" Then

     YourChoice(Request("Pressed"))

     ProcessBoard
     If GameState() = END_Not_Yet Then
          myChoice
     End If
     ProcessBoard


     Session("GameBoard") = Join(GameBoard,"_")

End If
%>

<HTML>
<HEAD>
</HEAD>


<BODY>
<table width="62%"  border="0" align="center">
  <tr>
    <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JOGO
      DA VELHA </strong></font></td>
  </tr>
  <tr>
    <td><center>
        <font size="1" face="Verdana, Arial, Helvetica, sans-serif">
        <form name=game action=velha.asp>
          <table border=0>
            <tr>
              <td> <table border=1 bordercolor="#D7D7D7">
                  <tr height=80>
                    <td>
                      <% Display(0) %>
                      <div align="center"></div></td>
                    <td>
                      <% Display(1) %>
                      <div align="center"></div></td>
                    <td>
                      <% Display(2) %>
                      <div align="center"></div></td>
                  </tr>
                  <tr height=80>
                    <td>
                      <% Display(3) %>
                      <div align="center"></div></td>
                    <td>
                      <% Display(4) %>
                      <div align="center"></div></td>
                    <td>
                      <% Display(5) %>
                      <div align="center"></div></td>
                  </tr>
                  <tr height=80>
                    <td height="22">
                      <% Display(6) %>
                      <div align="center"></div></td>
                    <td>
                      <% Display(7) %>
                      <div align="center"></div></td>
                    <td>
                      <% Display(8) %>
                      <div align="center"></div></td>
                  </tr>
                </table></td>
              <td> <table>
                  <tr>
                    <td width="114" valign="bottom"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;
                      </font></td>
                  </tr>
                  <tr>
                    <td valign="bottom"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Placar</strong></font></td>
                  </tr>
                  <tr>
                    <td valign="bottom"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Voc&ecirc;</font><br>
                      <font size="1" face="Verdana, Arial, Helvetica, sans-serif">
                      <input type=text size=5 name=you style="border: 1px solid red; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 9px; background-color: #ffffff; border-color: #B4B4B4; color: #858585;" value=<%=Session("you")%>>
                      </font></td>
                  </tr>
                  <tr>
                    <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
                      Computador<br>
                      <input type=text size=5 name=computer style="border: 1px solid red; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 9px; background-color: #ffffff; border-color: #B4B4B4; color: #858585;" value=<%=Session("computer")%>>
                      </font></td>
                  </tr>
                  <tr>
                    <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
                      Empates<br>
                      <input type=text size=5 name=ties style="border: 1px solid red; font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 9px; background-color: #ffffff; border-color: #B4B4B4; color: #858585;" value=<%=Session("ties")%>>
                      </font></td>
                  </tr>
                </table></td>
            </tr>
          </table>
        </form>
        <form action=velha.asp>
          <input type=hidden name=PlayAgain value=Yes>
          <input name="submit" type=submit style="border: none; font-family:Tahoma; font-size:13; color: white; background-color:gray; width: 150 height: 50"  value="Jogar Novamente">
        </form>
        </font></center>


</td>
  </tr>
</table>
</BODY>
</HTML>

T+,
 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página