1+ #include "play.h"
2+
3+ #include "../../libs/Stack/stack.h"
4+ #include "../structs.h"
5+
6+ int playTicTacToe (const int gamesPerPlayer , char * nameOfTheLocalFile ) {
7+ tStack _ps ;
8+ Player _player ;
9+ int games = 0 ;
10+
11+ createStack (& _ps );
12+
13+ askNamesAndMixPlayers (& _ps ); // this function will return the stack with the players mixed
14+
15+ while (grabElementFromStack (& _ps , & _player , sizeof (_player )))
16+ // this function return 1 if its all ok, and 0 if the stack is empty
17+ {
18+ printf ("Hello, Player %s, the game is about to star\n" , _player .name );
19+ games = gamesPerPlayer ;
20+ while (games > 0 ) {
21+ askPlayerIfHeIsReady (& _player ); // this function will interrogate
22+ // the player if he is ready
23+ playGame (& _player );
24+
25+ games -- ;
26+ printf ("\n %s, \n Your actual points are: %d \n" , _player .name , _player .points );
27+ printf ("Next game, %d: games left\n" , games );
28+ }
29+
30+ puts ("You have finished your games" );
31+ printf ("%s, Your final points are: %d \n" , _player .name , _player .points );
32+
33+ updateLocalFile (& _player , nameOfTheLocalFile );
34+
35+ SendInformationToTheAPI (& _player );
36+ // this part of the code may change when we have the API, and how to do it
37+ // Also, im not sure if the function is void or int, so we will have to see it later
38+ }
39+ return 1 ;
40+ }
41+
42+ void playGame (Player * player ) {
43+ int result ;
44+ Player Machine ;
45+ // this function will simulate a game
46+ // will assign the player form
47+ WhoStart (& player -> Turn , & Machine .Turn ); // we want to change this
48+ // this function will assign the turn to the player and the machine
49+ // is a random, we are going to represent the turn with 1:next, and 0:have to
50+
51+ /*
52+ if the game has 9 turns
53+ turns = 9
54+ mientras - turns > 9
55+ if (machine.turn == 1) //doing this we dont lose the randomness of the game
56+ {
57+ machinePlay() Here we edit the turn to the opposite,
58+ so the player can play (ex: turn 1, now 0)
59+
60+ }
61+ else
62+ playerPlay() Here we edit the turn to the opposite,
63+ so the machine can play (ex: turn 1, now 0)
64+
65+
66+ */
67+ // will update the player remaining turns
68+ // and will update the player points
69+
70+ if (result )
71+ puts ("Game Over, your ass has been fucked by the machine ngg " );
72+ else
73+ puts ("Nice, you won, take care of your family, they may lose too" );
74+
75+ updatePlayerStatistics (player );
76+ }
77+
78+ void updateLocalFile (Player * player , char * nameOfTheLocalFile ) {
79+ /*this function opens or creates a file to save the player information,
80+ in a local way.
81+ Doesnt matter the order, but its important to search the player (to update his profile)
82+ if he doesnt exist, insert at the end of the file.*/
83+
84+ printf ("Opening file %s \n" , nameOfTheLocalFile );
85+ puts ("The update is done!" );
86+ puts ("Closing the file" );
87+ }
88+
89+ void SendInformationToTheAPI (Player * Player ) {
90+ // i dont know what to do here yet
91+ }
0 commit comments