aggiunta l'uscita da timeout (migliorabile)
This commit is contained in:
parent
d8ff25fa84
commit
01eaf5f985
|
@ -9,6 +9,7 @@
|
|||
#include <sys/sem.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <server.h>
|
||||
#include <structures.h>
|
||||
|
@ -19,6 +20,8 @@
|
|||
#include <custom_msgq.h>
|
||||
#include <custom_sig.h>
|
||||
|
||||
#define TIME_TO_MOVE 10
|
||||
|
||||
void waitPlayer(char name[2][MAX_NAME]) {
|
||||
player_ds player;
|
||||
|
||||
|
@ -57,6 +60,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
int turns_left = _INPUT_S.rows * _INPUT_S.collums;
|
||||
int turn = 0;
|
||||
time_t timeout;
|
||||
tile_t result = -1;
|
||||
move_t move;
|
||||
|
||||
|
@ -69,9 +73,19 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
printf(PSERVER "%s's turn\n", name[turn]);
|
||||
|
||||
// salvo il tempo prima di aspettare la mossa
|
||||
timeout = time(0);
|
||||
// aspetto che mi mandi una mossa
|
||||
rcvMove(&move);
|
||||
|
||||
// se il tempo di attesa è maggiore del tempo per mossa
|
||||
// setto il giocatore in attesa come vincitore
|
||||
if (time(0) - timeout >= TIME_TO_MOVE) {
|
||||
printf("turn: %d", turn);
|
||||
result = 1 - turn;
|
||||
break;
|
||||
}
|
||||
|
||||
insertMove(move.move, turn);
|
||||
|
||||
// info
|
||||
|
@ -92,7 +106,7 @@ int main(int argc, char *argv[]) {
|
|||
} else {
|
||||
printf(PSERVER "%s won\n", name[result]);
|
||||
}
|
||||
|
||||
printf("winner %d\n", result);
|
||||
game_end_t game_end = {.mtype = GAME_END, .winner = result};
|
||||
sndGame_end(&game_end);
|
||||
sndGame_end(&game_end);
|
||||
|
|
Loading…
Reference in New Issue