Created
May 15, 2010 17:02
-
-
Save rpt/402292 to your computer and use it in GitHub Desktop.
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 <cgi.h> | |
#include <stdlib.h> | |
/** | |
* Wypisuje nagłówek HTML'a. | |
*/ | |
void printHeader() { | |
printf("Content-Type: text/html; charset=UTF-8\n\n"); | |
printf("<html>\n"); | |
printf("<head>\n"); | |
printf(" <title>Yathzee</title>\n"); | |
printf("</head>\n"); | |
printf("<body>\n"); | |
} | |
/** | |
* Wypisuje stopkę HTML'a. | |
*/ | |
void printFooter() { | |
printf("</body>\n"); | |
printf("</html>\n"); | |
} | |
int main() { | |
srand(time(NULL)); // to najlepiej dać na początku w main'ie. | |
s_cgi *cgi; | |
char *check; | |
char itoa_str[10]; // potrzebne do sprintf'a | |
int i, hold[5]; | |
cgi = cgiInit(); | |
printHeader(); | |
for (i=0; i<5; i++) { | |
sprintf(itoa_str, "%d", i+1); // zamienia int'a na string'a | |
check = cgiGetValue(cgi, itoa_str); | |
if (check != NULL && strcmp (check, "on") == 0) | |
hold[i] = 1; | |
else | |
hold[i] = 0; | |
printf("%i ", hold[i]); | |
} | |
printFooter(); | |
return 0; | |
} | |
/** | |
* Losuje 5 początkowych kości. | |
*/ | |
int roll() { | |
int i, dices[5]; | |
for (i=0; i<5; i++) | |
dices[i]=rand()%6+1; | |
} | |
/** | |
* Losuje ponownie kości które mają hold = 0. | |
*/ | |
void rollAgain(int dices[], int hold[]) { | |
int j, i; | |
for (j=0; j<2; j++) | |
for (i=0; i<5; i++) | |
if (hold==0) | |
dices[i]=rand()%6+1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment