Skip to content

Commit 902b9d4

Browse files
committed
Changes:
- Ive added a new field into Player struct -Ive added two files(Stack and Play) with Headers and .c but they arent developed
1 parent 8d47b78 commit 902b9d4

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed

libs/Stack/stack.c

Whitespace-only changes.

libs/Stack/stack.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef STACK_H_INCLUDED
2+
#define STACK_H_INCLUDED
3+
4+
typedef struct sNode {
5+
void *info;
6+
unsigned sizeInfo;
7+
struct sNode *next;
8+
} tNode;
9+
10+
typedef tNode *tStack;
11+
12+
void createStack(tStack *ps); // ps is equal to pointer to stack
13+
int insertIntoStack(tStack *ps, const void *d, unsigned quantityOfBytes);
14+
int grabElementFromStack(tStack *ps, void *d, unsigned quantityOfBytes);
15+
int isTheStackEmpty(const tStack *ps);
16+
int isTheStackFull(const tStack *ps, unsigned quantityOfBytes);
17+
int ViewLastElementOfStack(const tStack *ps, void *d, unsigned quantityOfBytes);
18+
void destroyStack(tStack *ps);
19+
20+
#endif // STACK_H_INCLUDED

src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "./configuration/main.h"
88
#include "./macros.h"
9+
#include "./play.h"
910
#include "./structs.h"
1011
#include "./utilities.h"
1112

src/play/play.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

src/play/play.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef PLAY_H_INCLUDED
2+
#define PLAY_H_INCLUDED
3+
4+
int playTicTacToe(const int Games_Per_Player, char* Name_Of_The_Local_File);
5+
6+
#endif // PLAY_H_INCLUDED

src/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef struct {
1919
size_t points;
2020
char assignedForm;
2121
size_t remainingTurns;
22+
char Turn; // it will be easer to use a char to represent the turn and having this here
2223
} Player;
2324

2425
typedef struct {

0 commit comments

Comments
 (0)