-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
65 lines (64 loc) · 1.42 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include "hangman.c"
int main(void){
struct player player;
srand(time(NULL));
printIntro(&player);
START: ;
int dif = 0;
int *ptrDif = &dif;
selectDifficulty(ptrDif, &player);
char secret[15];
int upper = 3;
int lower = 1;
int score = 0;
int magic = 3;
int *ptrMagic = &magic;
int wordsGuessed = 0;
int counter = 0;
int *ptrScore = &score;
int attempts = 9;
int *ptrAttempt = &attempts;
do{
get_word(secret);
//printf("%s\n", secret);
hangman(secret, ptrScore, ptrAttempt, ptrMagic, ptrDif);
if(attempts != 0){
int bonus = (int) strlen(secret) / 2;
counter++;
if(attempts <= 15){
printf("You achieved %d more attempts!\n", bonus);
attempts += bonus;
}
else{
printf("You have too many free guesses...\n");
}
//checks whether the magic will be present
if(dif != 3){
int r = rand();
if(r % 3 == 0){
int growth = (rand() % (upper - lower + 1)) + lower;
printf("You gained %d more magics!\n", growth);
magic += growth;
}
}
printf("Hmm... You won't guess the next word.\n");
wordsGuessed++;
printf("-------------\n");
}
} while(attempts > 0);
player.numGuessWords = wordsGuessed;
player.score = score * dif;
writeRecords(player);
if(ending(player) == true){
goto START;
}
return 0;
}