-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
101 lines (81 loc) · 2.86 KB
/
main.c
File metadata and controls
101 lines (81 loc) · 2.86 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "util.h"
#include "ihm.h"
int main ( int argc, char *argv[] )
{
static const char* database_filename = "data.db";
char *mot, *nom_joueur;
short choix, nombre_tours, numero_tour, score = 0;
short numero_mot_courant = 0;
LISTE_MOT *liste_mots;
TABLEAU_SCORE *tableau_scores_1, *tableau_scores_2, *tableau_scores_3;
db_creer_si_existepas(database_filename);
tableau_scores_1 = db_get(database_filename, 3);
tableau_scores_2 = db_get(database_filename, 5);
tableau_scores_3 = db_get(database_filename, 10);
rand_init();
// Initialiser CURSES et créer les constantes pour le placement
// des divers éléments dans la fenêtre.
curses_init();
init_fenetre();
curses_fenetre_constantes(0);
signal(SIGWINCH, curses_fenetre_constantes);
// Ici, un message d'avertissement peut apparaître.
liste_mots = curses_manage_arguments(fenetre, argc, argv);
do
{
choix = ecran_accueil(fenetre);
if (choix == 1)
{
score = 0;
if (liste_mots == NULL) {
mot = ecran_demander_mot(fenetre);
ecran_jeu(fenetre, mot);
}
else
{
nombre_tours = ecran_niveau(fenetre);
for (numero_tour = 0 ; numero_tour < nombre_tours ; numero_tour++)
{
mot = liste_mots->mots[numero_mot_courant];
numero_mot_courant++;
if (numero_mot_courant >= liste_mots->nombre)
{
// On n'a pas assez de mot: on mélange et on recommence
melanger_mots(liste_mots);
numero_mot_courant = 0;
}
score += ecran_jeu(fenetre, mot);
}
nom_joueur = ecran_resultat(fenetre, score);
switch (nombre_tours)
{
case 3:
{
ajouter_score(tableau_scores_1, score, nom_joueur);
break;
}
case 5:
{
ajouter_score(tableau_scores_2, score, nom_joueur);
break;
}
case 10:
{
ajouter_score(tableau_scores_3, score, nom_joueur);
break;
}
}
}
}
else if (choix == 2)
{
ecran_scores(fenetre, tableau_scores_1, tableau_scores_2, tableau_scores_3);
}
} while (choix != 3);
db_set(database_filename, 3, tableau_scores_1);
db_set(database_filename, 5, tableau_scores_2);
db_set(database_filename, 10, tableau_scores_3);
curses_stop();
printf("\nBye.\n");
return 0;
}