chrono
This commit is contained in:
parent
2361771f21
commit
8309e24cc7
11
pendu.c
11
pendu.c
@ -2,6 +2,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#define MAX_WORDS 14
|
#define MAX_WORDS 14
|
||||||
#define MAX_TRIES 6
|
#define MAX_TRIES 6
|
||||||
@ -35,6 +37,11 @@ void display_hangman(int tries) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void alarm_handler(int sig) {
|
||||||
|
printf("\nTrop tard ! Vous avez dépassé les 30 secondes.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
const char *word = words[rand() % MAX_WORDS];
|
const char *word = words[rand() % MAX_WORDS];
|
||||||
@ -48,12 +55,16 @@ int main() {
|
|||||||
}
|
}
|
||||||
guessed[word_length] = '\0';
|
guessed[word_length] = '\0';
|
||||||
|
|
||||||
|
signal(SIGALRM, alarm_handler);
|
||||||
|
|
||||||
while (tries < MAX_TRIES && guessed_correctly < word_length) {
|
while (tries < MAX_TRIES && guessed_correctly < word_length) {
|
||||||
printf("\nMot à deviner : %s\n", guessed);
|
printf("\nMot à deviner : %s\n", guessed);
|
||||||
display_hangman(tries);
|
display_hangman(tries);
|
||||||
char guess;
|
char guess;
|
||||||
|
alarm(30);
|
||||||
printf("Entrez une lettre : ");
|
printf("Entrez une lettre : ");
|
||||||
scanf(" %c", &guess);
|
scanf(" %c", &guess);
|
||||||
|
alarm(0);
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
for (int i = 0; i < word_length; i++) {
|
for (int i = 0; i < word_length; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user