Categorias

Jogo da forca em ASP

Jogo da forca completo com seleção de nivel de dificuldade (facil, medio e difícil).
Bem interessante.

<%
Function NovaPalavra()
	session("chutes")=""
	If request.form("nome")="" Then
		session("jogador")= "Anônimo"
		session("nivel") =  request.form("nivel")
	Else
		session("jogador")=request.form("nome")
		session("nivel") =  request.form("nivel")
	End if
	If request.queryString("Nome")<> "" Then 
		session("jogador")=request.queryString("Nome")
		session("nivel") =  request.queryString("niv")

	End if
	arq = session("nivel") & ".txt"
	
	Randomize()
	Dim objFSO, objFile, I, iRandom, tmpalav
	Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(Server.MapPath(arq))
	qlin=0
	do while Not objFile.AtEndOfStream
		qlin=qlin+1
		objFile.SkipLine
	loop
'	response.write qlin
	iRandom = Int(qlin * Rnd + 1)
	' abre novamente no inicio
	Set objFile = objFSO.OpenTextFile(Server.MapPath(arq))
	For I = 1 to iRandom - 1
		objFile.SkipLine
	Next
	palav=Split(objFile.ReadLine,";")
	tmpalav = UCase(palav(0))
	session("signif") = palav(1)
	objFile.Close
	Set objFile = Nothing
	Set objFSO = Nothing

	NovaPalavra = tmpalav
End Function 

Function CalculateGuess(stpalav)
	Dim sRot
	Dim I
	sRot = ""
	If InStr(1, stpalav, Chr(32), 1) Or InStr(1, stpalav, Chr(45), 1) Then
		For I = 1 to Len(stpalav)
			Select Case Asc(Mid(stpalav, I, 1))
				Case 32
					sRot = sRot & " "
				Case 45
					sRot = sRot & "-"
				Case Else
					sRot = sRot & "_"
			End Select
		Next
	Else
		sRot = String(Len(stpalav), "_")
	End If
	CalculateGuess = sRot
End Function 

Function UpsRots(stpalav, sRot, scarater)
	Dim tmpalav
	tmpalav = ""
	For I = 1 to Len(stpalav)
		If Mid(stpalav, I, 1) = scarater Then
			tmpalav = tmpalav & scarater
		Else
			tmpalav = tmpalav & Mid(sRot, I, 1)
		End If
	Next	
	UpsRots = tmpalav
End Function 


Dim iStat, partidas, erros, acertos
Dim stpalav, sRot
Dim arralet
Dim scarater

Dim tmpalav, I

partidas = Session("partidas")
erros = Session("erros")
acertos = Session("acertos")
iStat = Session("iStat")
stpalav = Session("stpalav")
sRot = Session("Guess")
arralet = Session("arralet")
chutes = Session("chutes")
scarater = Request.QueryString("letter")

chutes=chutes & scarater & " "
session("chutes")=chutes

If scarater = "" or iStat > 6 Then
	stpalav = NovaPalavra()
	sRot = CalculateGuess(stpalav)
	iStat = 0
	arralet = Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
Else
	If 65 <= Asc(scarater) AND Asc(scarater) <= 90 Then
		arralet(Asc(scarater) - 65) = 1
	End If
	For n=193 To 195
		If Asc(scarater)=n Then arralet(Asc(scarater)-167)=1 'posicao 26 a 28
	Next
	If Asc(scarater)=199 Then arralet(Asc(scarater)-170)=1 'posicao 29
	If Asc(scarater)=201 Then arralet(Asc(scarater)-171)=1 'posicao 30
	If Asc(scarater)=202 Then arralet(Asc(scarater)-171)=1 'posicao 31
	If Asc(scarater)=205 Then arralet(Asc(scarater)-173)=1 'posicao 32
	If Asc(scarater)=211 Then arralet(Asc(scarater)-178)=1 'posicao 33
	If Asc(scarater)=212 Then arralet(Asc(scarater)-178)=1 'posicao 34
	If Asc(scarater)=213 Then arralet(Asc(scarater)-178)=1 'posicao 35
	If Asc(scarater)=218 Then arralet(Asc(scarater)-182)=1 'posicao 36
	

	' If letter guessed is in the secret stpalav then update guess
	' otherwise increase iStat amount by 1
	If InStr(1, stpalav, scarater, 1) Then
		sRot = UpsRots(stpalav, sRot, scarater)
	Else
		iStat = iStat + 1
	End If
End If
%>

<%
response.write "
" response.write "
" response.write "Jogador: " & session("jogador") & " - " response.write "Nível: " & session("nivel") & "
" Response.Write "

" & vbCrLf For I = 1 to Len(sRot) If LCase(Mid(sRot, I, 1)) = " " Then Response.Write " " Else Response.Write " " End If Next Response.Write "

" & vbCrLf If iStat >=5 Then Response.Write "
Significado:" & session("signif") &"
" If iStat >= 6 Then Response.Write "Que pena, voce não acertou. A palavra era: " & UCase(stpalav) & "
" ' Response.Write "
Significado: " & session("signif") &"
" Response.Write "Tentativas: " & session("chutes") Response.Write "
Jogar novamente? Sim  Não
" iStat = 7 partidas=partidas+1 erros=erros+1 Else If sRot = stpalav Then Response.Write "Parabéns, voce acertou !!!
" ' Response.Write "
Significado: " & session("signif") &"
" Response.Write "Tentativas: " & session("chutes") Response.Write "
Jogar novamente? Sim  Não
" iStat = 7 acertos=acertos+1 Else For I = 65 to 90 If arralet(I - 65) = 0 Then Response.Write "" Else Response.Write "" End If Next response.write "
" For a = 193 to 195 If arralet(a - 167) = 0 Then Response.Write "" Else Response.Write "" End If Next For e = 201 to 202 If arralet(e - 171) = 0 Then Response.Write "" Else Response.Write "" End If Next If arralet(205 - 173) = 0 Then Response.Write "" Else Response.Write "" End If For o = 211 to 213 If arralet(o - 178) = 0 Then Response.Write "" Else Response.Write "" End If Next If arralet(218 - 182) = 0 Then Response.Write "" Else Response.Write "" End If If arralet(199 - 170) = 0 Then Response.Write "" Else Response.Write "" End If Response.Write "
" & vbCrLf End If End If Session("partidas") = partidas Session("acertos") = acertos Session("erros") = erros Session("iStat") = iStat Session("stpalav") = stpalav Session("Guess") = sRot Session("arralet") = arralet If (Session("acertos"))= "" Then Session("acertos")=0 If (Session("erros"))= "" Then Session("erros")=0 If (Session("partidas"))= "" Then Session("partidas")=1 response.write "
Acertos: " & Session("acertos") & " - Erros: " & Session("erros") response.write "
Inicial" response.write "
" %>

Arquivos para Download:

forca.zip