Ajout limite de temps
This commit is contained in:
parent
2361771f21
commit
818c6db53d
27
pendu.c
27
pendu.c
@ -42,6 +42,7 @@ int main() {
|
|||||||
char guessed[word_length];
|
char guessed[word_length];
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
int guessed_correctly = 0;
|
int guessed_correctly = 0;
|
||||||
|
int score = 100;/*Score initial*/
|
||||||
|
|
||||||
for (int i = 0; i < word_length; i++) {
|
for (int i = 0; i < word_length; i++) {
|
||||||
guessed[i] = '_';
|
guessed[i] = '_';
|
||||||
@ -51,16 +52,30 @@ int main() {
|
|||||||
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);
|
||||||
|
|
||||||
|
time_t start_time = time(NULL);/*Demarer le chronomètre*/
|
||||||
char guess;
|
char guess;
|
||||||
printf("Entrez une lettre : ");
|
printf("Entrez une lettre : ");
|
||||||
scanf(" %c", &guess);
|
scanf(" %c", &guess);
|
||||||
|
|
||||||
|
time_t end_time = timr(NULL); /*terminer le chronomètre*/
|
||||||
|
double time_taken = difftime(end_time, start_time);
|
||||||
|
|
||||||
|
/*Vérification du temps écoulé*/
|
||||||
|
|
||||||
|
if (time_taken > TIME_LIMIT) {
|
||||||
|
printf("Temps écoulé ! Vous avez mis plus de %d secondes.\n", TIME_LIMIT);
|
||||||
|
printf("Désolé, vous avez perdu. Le mot était : %s\n", word);
|
||||||
|
display_hangman(MAX_TRIES);
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < word_length; i++) {
|
for (int i = 0; i < word_length; i++) {
|
||||||
if (word[i] == guess) {
|
if (word[i] == guess) {
|
||||||
if (guessed[i] == '_') {
|
if (guessed[i] == '_') {
|
||||||
guessed[i] = guess;
|
guessed[i] = guess;
|
||||||
guessed_correctly++;
|
guessed_correctly++;
|
||||||
|
score += 10 /*Bonus de points pour chaque lettre trouvée*/
|
||||||
}
|
}
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
@ -68,11 +83,21 @@ int main() {
|
|||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
tries++;
|
tries++;
|
||||||
|
score -= 5;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
printf("Temps écoulé pour cette tentative : %.2f secondes\n", time_taken");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (guessed_correctly == word_length) {
|
if (guessed_correctly == word_length) {
|
||||||
printf("Félicitations ! Vous avez deviné le mot : %s\n", word);
|
printf("Félicitations ! Vous avez deviné le mot : %s\n", word);
|
||||||
|
|
||||||
|
if (tries < 3) {
|
||||||
|
score += 20; // Bonus si le mot est deviné en moins de 3 essais
|
||||||
|
printf("Bravo, vous avez trouvé le mot en moins de 3 essais ! Bonus de points ajouté.\n");
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printf("Désolé, vous avez perdu. Le mot était : %s\n", word);
|
printf("Désolé, vous avez perdu. Le mot était : %s\n", word);
|
||||||
display_hangman(MAX_TRIES);
|
display_hangman(MAX_TRIES);
|
||||||
|
Loading…
Reference in New Issue
Block a user