Created
February 11, 2017 14:59
-
-
Save Alynva/305b3621dc663dc76cd01c3bc9f1d469 to your computer and use it in GitHub Desktop.
Jogo da Forca em CGI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <ctype.h> | |
#include <string.h> | |
int main() { | |
int i; | |
char *dados = NULL; | |
char theWord[50] = {'\n'}; | |
dados = getenv("QUERY_STRING"); | |
FILE *lf; | |
if (sscanf(dados, "theWord=%s", theWord) == 1) { | |
for (i = 0; i < strlen(theWord); i++) { | |
theWord[i] = tolower(theWord[i]); | |
} | |
lf = fopen("jogo-da-forca.txt", "w+"); | |
fprintf(lf, "%s ", theWord); | |
for (i = 0; i < strlen(theWord); i++) { | |
fprintf(lf, "%c", '_'); | |
} | |
fclose(lf); | |
} | |
printf("%s%c%c\n","Content-Type:text/html;charset=UTF-8",13,10); | |
printf("<html>"); | |
printf("<head>"); | |
printf("<meta http-equiv=\"refresh\" content=\" 0 ;url=jogo-da-forca.cgi\">"); | |
printf("<meta charset=\"utf-8\">"); | |
printf("<title>Jogo da forca - CGI + Arquivos</title>"); | |
printf("</head>"); | |
printf("<body>"); | |
printf("</body>"); | |
printf("</html>"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define CHANCES 9 | |
int main() { | |
int i, j, len, cont; | |
char *dados = NULL; | |
char theWord[50] = {'\n'}; | |
char myWord[50] = {'\n'}; | |
char temp[50] = {'\n'}; | |
char theErred; | |
char erred[50]; | |
char copy[50]; | |
char classe[20]; | |
dados = getenv("QUERY_STRING"); | |
FILE *lf; | |
if (sscanf(dados, "myWord=%s", myWord) == 1) { | |
for (i = 0; i < strlen(myWord); i++) { | |
myWord[i] = tolower(myWord[i]); | |
} | |
lf = fopen("jogo-da-forca.txt", "r+"); | |
fscanf(lf, "%s %s %s", theWord, temp, erred); | |
for (j = 0; j < strlen(myWord); j++) { | |
cont = 0; | |
for (i = 0; i < strlen(theWord); i++) { | |
if (theWord[i] == myWord[j]) { | |
temp[i] = theWord[i]; | |
cont++; | |
} | |
} | |
if (!cont) { | |
cont = 0; | |
for (i = 0; i < strlen(erred); i++) { | |
if (myWord[j] == erred[i]) { | |
cont++; | |
} | |
} | |
if (!cont) { | |
strcpy(copy, erred); | |
snprintf(erred, sizeof erred, "%s%c", copy, myWord[j]); | |
} | |
} | |
} | |
rewind(lf); | |
fprintf(lf, "%s %s %s", theWord, temp, erred); | |
fclose(lf); | |
} | |
lf = fopen("jogo-da-forca.txt", "r+"); | |
rewind(lf); | |
fscanf(lf, "%s %s %s", theWord, myWord, erred); | |
j = strlen(erred); | |
for (i = j - 1; i < CHANCES; i++) { | |
strcpy(copy, erred); | |
snprintf(erred, sizeof erred, "%s%c", copy, '-'); | |
} | |
printf("%s%c%c\n","Content-Type:text/html;charset=UTF-8",13,10); | |
printf("<html>"); | |
printf("<head>"); | |
printf("<meta charset=\"utf-8\">"); | |
printf("<meta name=\"author\" content=\"Alisson Nunes\">"); | |
printf("<meta name=\"reply-to\" content=\"[email protected]\">"); | |
printf("<meta name=\"generator\" content=\"Dev-C++ 5.11\">"); | |
printf("<meta http-equiv=\"content-language\" content=\"pt-br\">"); | |
printf("<meta name=\"description\" content=\"Um jogo simples, com a mecânica programada em Lingaugem C.\">"); | |
printf("<title>Jogo da forca - CGI + Arquivos</title>"); | |
printf("<link rel=\"stylesheet\" href=\"../jogo-da-forca.css\">"); | |
printf("</head>"); | |
printf("<body>"); | |
printf("<a href=\"../jogo-da-forca.html\">Voltar</a>"); | |
if (strcmp(theWord, myWord) && j <= CHANCES) { | |
printf("<form action=\"\">"); | |
printf("<input type=\"text\" name=\"myWord\" required autofocus placeholder=\"Digite uma palavra/letra\" maxlength=\"45\" autocomplete=\"off\">"); | |
printf("<input type=\"submit\" value=\"Tentar\">"); | |
printf("</form>"); | |
} else if (!strcmp(theWord, myWord)) { | |
snprintf(classe, sizeof classe, " class=\"venceu\""); | |
j = CHANCES + 1; | |
} else if (j >= CHANCES) { | |
snprintf(classe, sizeof classe, " class=\"perdeu\""); | |
} | |
printf("<br>"); | |
printf("<div id=\"game\"%s data-palavra=\"%s\" data-acertos=\"%s\" data-erros=\"%s\">", classe, theWord, myWord, erred); | |
printf("<div></div>"); | |
for (i = 0; i < j; i++) { | |
/*for (i = 0; i < 15; i++) {*/ | |
printf("<div></div>"); | |
} | |
printf("</div>"); | |
printf("</body>"); | |
printf("</html>"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
background-repeat: no-repeat; | |
} | |
body { | |
margin: 0; | |
background-color: rgba(60,80,112,1); | |
background-image: | |
radial-gradient(100% 100%, rgba(255,255,255,.7) 0%, transparent 50%); | |
background-size: | |
700px 525px; | |
background-position: | |
50% calc(50% + 20px); | |
text-align: center; | |
padding: 12px; | |
overflow: hidden; | |
} | |
body * { | |
font-family: sans-serif; | |
} | |
a { | |
position: absolute; | |
left: 16px; | |
text-decoration: none; | |
color: rgba(255,255,255,.7); | |
text-transform: uppercase; | |
background-color: rgba(0,0,0,.2); | |
padding: 6px; | |
transition: background-color .6s, color .6s; | |
} | |
a:hover { | |
color: #fff; | |
background-color: rgba(0,0,0,.5); | |
} | |
input { | |
border: 0; | |
padding: 8px; | |
margin-top: 8px; | |
box-shadow: 0 6px 10px 0 rgba(0,0,0,.14),0 1px 18px 0 rgba(0,0,0,.12),0 3px 5px -1px rgba(0,0,0,.2); | |
transition: background-color .6s, color .6s; | |
} | |
input[type="submit"]:hover { | |
cursor: pointer; | |
background-color: #666; | |
color: #ddd; | |
} | |
#game { | |
position: absolute; | |
top: calc(50% - 242.5px); | |
left: 0; | |
width: 100vw; | |
height: 525px; | |
overflow: hidden; | |
background-image: | |
linear-gradient(black, black), | |
linear-gradient(black, black), | |
linear-gradient(black, black), | |
linear-gradient(brown, brown), | |
linear-gradient(brown, brown), | |
radial-gradient(circle, transparent 45%, brown 46%, brown 54%, transparent 55%); | |
background-size: | |
30px 400px, | |
100px 30px, | |
300px 30px, | |
5px 60px, | |
15px 20px, | |
30px 30px; | |
background-position: | |
calc(50% - 100px) calc(50% - 10px), | |
calc(50% - 100px) calc(50% + 190px), | |
50% calc(50% - 170px), | |
calc(50% + 90px) calc(50% - 130px), | |
calc(50% + 90px) calc(50% - 99px), | |
calc(50% + 89px) calc(50% - 80px); | |
} | |
#game:before { | |
color: #fff; | |
content: attr(data-acertos); | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
font-size: 1.5em; | |
} | |
#game:after { | |
color: #fff; | |
content: "Erros: " attr(data-erros); | |
position: absolute; | |
bottom: 0; | |
left: 0; | |
right: 0; | |
font-size: 1.5em; | |
} | |
#game.perdeu:before { | |
content: attr(data-palavra); | |
} | |
#game:before, #game:after { | |
letter-spacing: .1em; | |
} | |
#game > div, #game > div:before, #game > div:after { | |
content: ''; | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
background-repeat: no-repeat; | |
} | |
#game[class] > div:nth-of-type(1):before { | |
position: absolute; | |
top: calc(50% - 100px); | |
z-index: -200; | |
color: rgba(255,255,255,.5); | |
font-size: 10em; | |
} | |
#game.perdeu > div:nth-of-type(1):before { | |
content: "PERDEU"; | |
} | |
#game.venceu > div:nth-of-type(1):before { | |
content: "VENCEU"; | |
} | |
#game > div:nth-of-type(2) { /* Cabeça */ | |
background-image: | |
radial-gradient(circle, darksalmon 60%, transparent 61%); | |
background-size: | |
60px 60px; | |
background-position: | |
calc(50% + 100px) calc(50% - 95px); | |
} | |
#game.venceu > div:nth-of-type(2) { /* Cabeça [VENCEU] */ | |
background-image: | |
radial-gradient(circle, darksalmon 60%, transparent 61%); | |
background-size: | |
60px 60px; | |
background-position: | |
calc(50% + 86px) calc(50% - 50px); | |
} | |
#game > div:nth-of-type(2):before { /* Pescoço */ | |
transform: rotate(-60deg); | |
background-image: | |
linear-gradient(transparent 39%, darksalmon 41%, darksalmon 59%, transparent 61%); | |
background-size: | |
25px 60px; | |
background-position: | |
calc(50% + 110px) calc(50% + 40px); | |
z-index: -10; | |
} | |
#game.venceu > div:nth-of-type(2):before { /* Pescoço [VENCEU] */ | |
transform: rotate(90deg); | |
background-position: | |
calc(50% - 25px) calc(50% - 85px); | |
} | |
#game > div:nth-of-type(2):after { /* Olhos, boca e cabelo */ | |
position: absolute; | |
left: calc(50% + 67px); | |
top: calc(50% - 128px); | |
width: 60px; | |
height: 60px; | |
background-image: | |
linear-gradient(45deg, transparent 41%, black 42%, black 58%, transparent 59%), | |
linear-gradient(-45deg, transparent 38%, black 39%, black 58%, transparent 59%), | |
linear-gradient(45deg, transparent 41%, black 42%, black 58%, transparent 59%), | |
linear-gradient(-45deg, transparent 38%, black 39%, black 58%, transparent 59%), | |
linear-gradient(transparent 38%, black 39%, black 58%, transparent 59%), | |
radial-gradient(60% 60%, darksalmon 60%, transparent 61%), | |
radial-gradient(60% 60%, darksalmon 60%, transparent 61%), | |
linear-gradient(darksalmon, darksalmon), | |
radial-gradient(circle, black 60%, transparent 61%); | |
background-size: | |
15px 15px, | |
15px 15px, | |
15px 15px, | |
15px 15px, | |
20px 15px, | |
15px 36px, | |
36px 15px, | |
35px 35px, | |
60px 60px; | |
background-position: | |
calc(50% - 5px) calc(50% - 0px), | |
calc(50% - 5px) calc(50% - 0px), | |
calc(50% + 15px) calc(50% - 0px), | |
calc(50% + 15px) calc(50% - 0px), | |
calc(50% + 10px) calc(50% + 15px), | |
calc(50% + 22px) calc(50% + 1px), | |
calc(50% + 0px) calc(50% + 22px), | |
calc(50% + 4px) calc(50% + 5px), | |
calc(50% - 0px) calc(50% + 0px); | |
} | |
#game.venceu > div:nth-of-type(2):after { /* Olhos, boca e cabelo [VENCEU] */ | |
left: calc(50% + 54px); | |
top: calc(50% - 83px); | |
background-image: | |
radial-gradient(circle, black 60%, transparent 61%), | |
radial-gradient(circle, black 60%, transparent 61%), | |
radial-gradient(70% 70%, darksalmon 60%, transparent 61%), | |
radial-gradient(70% 70%, darksalmon 60%, transparent 61%), | |
radial-gradient(circle, black 60%, transparent 61%), | |
radial-gradient(60% 60%, darksalmon 60%, transparent 61%), | |
radial-gradient(60% 60%, darksalmon 60%, transparent 61%), | |
radial-gradient(60% 60%, darksalmon 60%, transparent 61%), | |
radial-gradient(60% 60%, darksalmon 60%, transparent 61%), | |
radial-gradient(60% 60%, darksalmon 60%, transparent 61%), | |
linear-gradient(darksalmon, darksalmon), | |
radial-gradient(circle, black 60%, transparent 61%); | |
background-size: | |
12px 12px, | |
12px 12px, | |
45px 30px, | |
40px 20px, | |
40px 40px, | |
20px 16px, | |
30px 30px, | |
15px 36px, | |
15px 36px, | |
36px 15px, | |
44px 30px, | |
60px 60px; | |
background-position: | |
calc(50% - 8px) calc(50% - 0px), | |
calc(50% + 12px) calc(50% - 0px), | |
calc(50% + 2px) calc(50% + 1px), | |
calc(50% + 2px) calc(50% + 8px), | |
calc(50% + 2px) calc(50% + 7px), | |
calc(50% + 12px) calc(50% + 17px), | |
calc(50% - 12px) calc(50% + 11px), | |
calc(50% + 22px) calc(50% + 1px), | |
calc(50% - 20px) calc(50% + 0px), | |
calc(50% - 1px) calc(50% + 22px), | |
calc(50% - 0px) calc(50% + 2px), | |
calc(50% - 0px) calc(50% + 0px); | |
} | |
#game div:nth-of-type(3) { /* Tronco */ | |
background-image: | |
linear-gradient(darksalmon, darksalmon); | |
background-size: | |
30px 130px; | |
background-position: | |
calc(50% + 85px) calc(50% - 2px); | |
} | |
#game.venceu div:nth-of-type(3) { /* Tronco [VENCEU] */ | |
background-position: | |
calc(50% + 85px) calc(50% + 50px); | |
} | |
#game div:nth-of-type(4) { /* Braço esquerdo */ | |
transform: rotate(20deg); | |
background-image: | |
linear-gradient(darksalmon, darksalmon); | |
background-size: | |
15px 80px; | |
background-position: | |
calc(50% + 50px) calc(50% - 45px); | |
} | |
#game.venceu div:nth-of-type(4) { /* Braço esquerdo [VENCEU] */ | |
transform: rotate(130deg); | |
background-position: | |
calc(50% - 45px) calc(50% - 20px); | |
} | |
#game div:nth-of-type(5) { /* Braço direito */ | |
transform: rotate(-20deg); | |
background-image: | |
linear-gradient(darksalmon, darksalmon); | |
background-size: | |
15px 80px; | |
background-position: | |
calc(50% + 111px) calc(50% + 14px); | |
} | |
#game.venceu div:nth-of-type(5) { /* Braço direito [VENCEU] */ | |
transform: rotate(-130deg); | |
background-position: | |
calc(50% - 65px) calc(50% + 110px); | |
} | |
#game div:nth-of-type(6) { /* Perna esquerda */ | |
transform: rotate(10deg); | |
background-image: | |
linear-gradient(darksalmon, darksalmon); | |
background-size: | |
15px 90px; | |
background-position: | |
calc(50% + 85px) calc(50% + 80px); | |
} | |
#game.venceu div:nth-of-type(6) { /* Perna esquerda [VENCEU] */ | |
transform: rotate(20deg); | |
background-position: | |
calc(50% + 110px) calc(50% + 120px); | |
} | |
#game div:nth-of-type(7) { /* Perna direita */ | |
transform: rotate(-10deg); | |
background-image: | |
linear-gradient(darksalmon, darksalmon); | |
background-size: | |
15px 90px; | |
background-position: | |
calc(50% + 83px) calc(50% + 110px); | |
} | |
#game.venceu div:nth-of-type(7) { /* Perna direita [VENCEU] */ | |
transform: rotate(-20deg); | |
background-position: | |
calc(50% + 50px) calc(50% + 180px); | |
} | |
#game div:nth-of-type(8) { /* Blusa (tronco) */ | |
background-image: | |
linear-gradient(#64B5F6, #64B5F6); | |
background-size: | |
40px 100px; | |
background-position: | |
calc(50% + 85px) calc(50% - 17px); | |
} | |
#game.venceu div:nth-of-type(8) { /* Blusa (tronco) [VENCEU] */ | |
background-size: | |
40px 110px; | |
background-position: | |
calc(50% + 85px) calc(50% + 35px); | |
} | |
#game div:nth-of-type(8):before { /* Blusa (manga esquerda) */ | |
transform: rotate(20deg); | |
background-image: | |
linear-gradient(#64B5F6, #64B5F6); | |
background-size: | |
15px 20px; | |
background-position: | |
calc(50% + 50px) calc(50% - 65px); | |
} | |
#game.venceu div:nth-of-type(8):before { /* Blusa (manga esquerda) [VENCEU] */ | |
transform: rotate(130deg); | |
background-position: | |
calc(50% - 45px) calc(50% - 45px); | |
} | |
#game div:nth-of-type(8):after { /* Blusa (manga direita) */ | |
transform: rotate(-20deg); | |
background-image: | |
linear-gradient(#64B5F6, #64B5F6); | |
background-size: | |
15px 20px; | |
background-position: | |
calc(50% + 111px) calc(50% - 8px); | |
} | |
#game.venceu div:nth-of-type(8):after { /* Blusa (manga direita) [VENCEU] */ | |
transform: rotate(-130deg); | |
background-position: | |
calc(50% - 65px) calc(50% + 88px); | |
} | |
#game div:nth-of-type(9) { /* Calça (cintura) */ | |
background-image: | |
linear-gradient(darkblue, darkblue); | |
background-size: | |
40px 30px; | |
background-position: | |
calc(50% + 85px) calc(50% + 48px); | |
} | |
#game.venceu div:nth-of-type(9) { /* Calça (cintura) [VENCEU] */ | |
background-position: | |
calc(50% + 85px) calc(50% + 100px); | |
} | |
#game div:nth-of-type(9):before { /* Calça (perna esquerda) */ | |
transform: rotate(10deg); | |
background-image: | |
linear-gradient(darkblue, darkblue); | |
background-size: | |
15px 70px; | |
background-position: | |
calc(50% + 85px) calc(50% + 80px); | |
} | |
#game.venceu div:nth-of-type(9):before { /* Calça (perna esquerda) [VENCEU] */ | |
transform: rotate(20deg); | |
background-position: | |
calc(50% + 110px) calc(50% + 110px); | |
} | |
#game div:nth-of-type(9):after { /* Calça (perna direita) */ | |
transform: rotate(-10deg); | |
background-image: | |
linear-gradient(darkblue, darkblue); | |
background-size: | |
15px 70px; | |
background-position: | |
calc(50% + 83px) calc(50% + 110px); | |
} | |
#game.venceu div:nth-of-type(9):after { /* Calça (perna direita) [VENCEU] */ | |
transform: rotate(-20deg); | |
background-position: | |
calc(50% + 50px) calc(50% + 170px); | |
} | |
#game div:nth-of-type(10) { /* Sapato (esquerdo) */ | |
background-image: | |
radial-gradient(black 50%, transparent 51%); | |
background-size: | |
40px 25px; | |
background-position: | |
calc(50% + 58px) calc(50% + 133px); | |
} | |
#game.venceu div:nth-of-type(10) { /* Sapato (esquerdo) [VENCEU] */ | |
background-position: | |
calc(50% + 44px) calc(50% + 190px); | |
} | |
#game div:nth-of-type(11) { /* Sapato (direito) */ | |
background-image: | |
radial-gradient(black 50%, transparent 51%); | |
background-size: | |
40px 25px; | |
background-position: | |
calc(50% + 112px) calc(50% + 133px); | |
} | |
#game.venceu div:nth-of-type(11) { /* Sapato (direito) [VENCEU] */ | |
background-position: | |
calc(50% + 128px) calc(50% + 190px); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="author" content="Alisson Nunes"> | |
<meta name="reply-to" content="[email protected]"> | |
<meta name="generator" content="Sublime Text 2"> | |
<meta http-equiv="content-language" content="pt-br"> | |
<meta name="description" content="Um jogo simples, com a mecânica programada em Lingaugem C."> | |
<title>Jogo da forca</title> | |
<link rel="stylesheet" type="text/css" href="jogo-da-forca.css"> | |
</head> | |
<body> | |
<form action="cgi-bin/jogo-da-forca-theWord.cgi" method="get"> | |
<input type="text" name="theWord" required autofocus placeholder="Digite a palavra secreta"><input type="submit"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment