11/*
22 * @Author: JIANG Yilun
33 * @Date: 2022-04-25 15:51:26
4- * @LastEditTime: 2022-05-02 12:08:15
4+ * @LastEditTime: 2022-05-02 14:32:41
55 * @LastEditors: JIANG Yilun
66 * @Description:
77 * @FilePath: /Projet_cowsay_L1S2/Tamagoshi-vache.c
2323void update () { printf ("\033[H\033[J" ); }
2424
2525/*
26+
2627* @description: Make the pointer to x, y in Terminal
2728* @param {type}: int x, int y
2829* @return: void
2930*/
3031void gotoxy (x , y ) { printf ("\033[%d;%dH" , x , y ); }
3132
32- int life = 5 ;
33+ int life = 5 ; // Define the valeur initial to 5
34+
35+ /*
3336
37+ * @description: Print the etat of the cow
38+ * @param {type}: int life
39+ * @return: void
40+ */
3441void etat (int life )
3542{
3643 if (life == 0 || life == 10 )
@@ -47,6 +54,12 @@ void etat(int life)
4754 }
4855}
4956
57+ /*
58+
59+ * @description: Print the cow
60+ * @param {type}: int *length_vache(for define the length of divise), char *message_vache(To print the message), char *eyes_vache(To print the cow's eyes(in default: "oo")), char *tongue_vache(To print the cow's tongue), int *tail_vache(To print the cow's tail(This is also the life of cow)), int time_tick_vache(To define how much time the anmie will take), int hour, int minite, int food
61+ * @return: void
62+ */
5063void affiche_vache (int * length_vache , char * message_vache , char * eyes_vache , char * tongue_vache , int * tail_vache , int time_tick_vache , int hour , int minite , int food )
5164{
5265 update ();
@@ -117,6 +130,11 @@ void affiche_vache(int *length_vache, char *message_vache, char *eyes_vache, cha
117130 }
118131}
119132
133+ /*
134+ * @description: count the time
135+ * @param {type}: int *hour, int *minite, int *food
136+ * @return: arr[hour, minite]
137+ */
120138void time_count (int time_tick , int hour , int minite , int arr [])
121139{
122140 minite += 5 ;
@@ -133,6 +151,12 @@ void time_count(int time_tick, int hour, int minite, int arr[])
133151 arr [1 ] = minite ;
134152}
135153
154+ /*
155+ * @description: check if the enter number is a prime number
156+ * @param {type}: int nombre
157+ * @return: int
158+ */
159+
136160int check_prime_number (int nombre )
137161{
138162 int i ;
@@ -146,9 +170,15 @@ int check_prime_number(int nombre)
146170 return 1 ;
147171}
148172
173+ /*
174+ * @description: Main function
175+ * @param {type}: int argc, char *argv[]
176+ * @return: int
177+ */
178+
149179int main (int argc , char * argv [])
150180{
151- // Begin the game
181+ // Begin the game, define the variables
152182 int tail = 1 ;
153183 int life = 5 ;
154184 int food = 10 ;
@@ -158,28 +188,34 @@ int main(int argc, char *argv[])
158188 int minite = 0 ;
159189 int hour = 0 ;
160190
191+ // Define the opening message
161192 char message [MAX_LENGTH ] = "Welcome to the COWSAY Game!" ;
162193 int length = strlen (message );
163194 tongue = "U " ;
164195 affiche_vache (& length , message , eyes , tongue , & tail , time_tick , hour , minite , food );
165196
197+ // Define the message of providing the name of the player
166198 strcpy (message , "Please enter your name: " );
167199 // *message = "Please enter your name: ";
168200 length = strlen (message );
169201 affiche_vache (& length , message , eyes , tongue , & tail , 2 , hour , minite , food );
170202
203+ // Define the name of the player and get the name from keyboard.
171204 char name [20 ];
172205 scanf ("%s" , name );
173206
207+ // Welcome the player
174208 strcpy (message , "Hello " );
175209 strcat (message , name );
176210 length = strlen (message );
177211 affiche_vache (& length , message , eyes , tongue , & tail , time_tick , hour , minite , food );
178212
179- strcpy (message , "Please choose the speed of the game: (1) for slow, (2) for medium (default), (3) for fast, (4) for super fast (developer mode xd)" );
213+ // Define the speed of the game, (4) for super fast (developer mode xd)
214+ strcpy (message , "Please choose the speed of the game: (1) for slow, (2) for medium (default), (3) for fast" );
180215 length = strlen (message );
181216 affiche_vache (& length , message , eyes , tongue , & tail , 1 , hour , minite , food );
182217
218+ // Define the speed of the game, and get the value from keyboard.
183219 int game_speed ;
184220 scanf ("%d" , & game_speed );
185221
@@ -219,42 +255,52 @@ int main(int argc, char *argv[])
219255 time_tick = 5 ;
220256 }
221257
222- int i = 0 ;
223- time_t seconds_of_start ;
224- seconds_of_start = time (NULL );
225- printf ("time: %ld\n" , seconds_of_start );
258+ int i = 0 ; // i is the number of the loop, not using later but just left there if needed
226259
227260 while (life > 0 && life < 10 )
228261 {
262+ // Count the time, with returning the value of the time in an array: arr[hour, minite]
229263 int arr [2 ];
230264 strcpy (message , "..." );
231- // printf("%d\n", rand() % 10);
232265 length = strlen (message );
233266 time_count (time_tick , hour , minite , arr );
234267 hour = arr [0 ];
235268 minite = arr [1 ];
236269 tail = life ;
237270 affiche_vache (& length , message , eyes , tongue , & tail , time_tick , hour , minite , food );
271+
238272 i ++ ;
239273 update ();
274+
275+ // Check if minite is equal to 60, if yes its time to play a game/
240276 if (minite == 0 )
241277 {
278+ // Define the message of playing game.
242279 strcpy (message , "It's time to think about something!" );
243280 length = strlen (message );
244281 affiche_vache (& length , message , eyes , tongue , & tail , time_tick , hour , minite , food );
282+
283+ // Define a random number between 1 to 5, to chose which kind of math problem we will use.
245284 int random_number = rand () % (4 ) + 1 ;
246- srand (time (NULL ));
247- // prime number
285+ srand (time (NULL )); // Initialize the random number generator.
286+
287+ // If random is equal to 1 then we will use the prime problem.
248288 if (random_number == 1 )
249289 {
290+ // Define the message of the prime problem, from 0 to 100.
250291 int nombre_premier = rand () % 100 ;
292+ // Initialize the message to be displayed.
251293 strcpy (message , "Is it a prime number? (1) for yes, (2) for no: " );
294+ // Make the prime number to be displayed.
252295 char str_nombre_premier [MAX_LENGTH ] = "" ;
253296 sprintf (str_nombre_premier , "%d" , nombre_premier );
297+ // Make message and prime number to be together.
254298 strcat (message , str_nombre_premier );
255299
256300 length = strlen (message );
257301 affiche_vache (& length , message , eyes , tongue , & tail , time_tick , hour , minite , food );
302+
303+ // Get the answer from keyboard.
258304 int answer = 0 ;
259305 scanf ("%d" , & answer );
260306 if (answer == 1 )
@@ -294,12 +340,15 @@ int main(int argc, char *argv[])
294340 }
295341 }
296342 }
297- // addition
343+ // If random is equal to 2 then we will use the addition problem.
298344 else if (random_number == 2 )
299345 {
346+ // Define the 2 values of the addition problem, from 0 to 100.
300347 int nombre_1 = rand () % 100 ;
301348 int nombre_2 = rand () % 100 ;
349+ // Initialize the message to be displayed.
302350 strcpy (message , "What is the sum of " );
351+ // Make the two numbers to be displayed.
303352 char str_nombre_1 [MAX_LENGTH ] = "" ;
304353 char str_nombre_2 [MAX_LENGTH ] = "" ;
305354 sprintf (str_nombre_1 , "%d" , nombre_1 );
@@ -311,6 +360,8 @@ int main(int argc, char *argv[])
311360
312361 length = strlen (message );
313362 affiche_vache (& length , message , eyes , tongue , & tail , time_tick , hour , minite , food );
363+
364+ // Get the answer from keyboard.
314365 int answer = 0 ;
315366 scanf ("%d" , & answer );
316367 if (answer == nombre_1 + nombre_2 )
@@ -467,11 +518,15 @@ int main(int argc, char *argv[])
467518 }
468519 }
469520 }
521+
522+ // If it's 6h, 12h, 18h, 24h then its time to eat, the player can choose if they want to feed the cow or not
470523 if (hour % 6 == 0 && minite == 0 )
471524 {
472525 strcpy (message , "It's time to eat! Do you want to eat? (1 for yes, food - 5, life + 2; 0 for no, life - random number)" );
473526 length = strlen (message );
474527 affiche_vache (& length , message , eyes , tongue , & tail , time_tick , hour , minite , food );
528+
529+ // Ask for the player if he wants to feed
475530 int answer = 0 ;
476531 scanf ("%d" , & answer );
477532 if (answer == 1 )
0 commit comments