win/loss
This commit is contained in:
parent
f40ecead80
commit
3bd1b32212
|
@ -54,7 +54,7 @@ int main(int argc, char *argv[]){
|
|||
|
||||
while (1) {
|
||||
// aspetto il mio turno
|
||||
semOp(_SEMID, ID, -1); // mettere id eccetera in var
|
||||
semOp(_SEMID, ID, -1);
|
||||
printBoard();
|
||||
|
||||
// input e controllo
|
||||
|
|
|
@ -34,7 +34,7 @@ int main(int argc, char *argv[]){
|
|||
player_ds player;
|
||||
char name[2][MAX_NAME];
|
||||
|
||||
// aspetto PRIMO client
|
||||
// aspetto PRIMO client //FIXME: codice duplicato
|
||||
semOp(_SEMID, SERVER, -1);
|
||||
// ricevo nome primo client
|
||||
rcvPlayer(&player);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <custom_sem.h>
|
||||
#include <custom_shm.h>
|
||||
#include <forza4.h>
|
||||
#include <client.h>
|
||||
|
||||
pid_t _PIDS[2];
|
||||
|
||||
|
@ -109,7 +110,7 @@ void sigHandlerClient(int sig) {
|
|||
if (sig == SIGINT) {
|
||||
//TODO: abbandono
|
||||
|
||||
kill(getpid(), SIGINT);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Terminazione e chiusura terminale
|
||||
|
@ -128,8 +129,15 @@ void sigHandlerClient(int sig) {
|
|||
if (sig == SIGUSR1) {
|
||||
game_end_t winner;
|
||||
rcvGame_end(&winner);
|
||||
//TODO:
|
||||
kill(getpid(), SIGTERM);
|
||||
|
||||
printBoard();
|
||||
if (winner.winner == ID) {
|
||||
printf("YOU WON!!!\n");
|
||||
} else {
|
||||
printf("YOU LOST!!!\n");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,22 +57,22 @@ int checkLine(int pos, int delta) {
|
|||
int checkWin(int pos) {
|
||||
int result = checkLine(pos, ORIZONTAL);
|
||||
if (result) {
|
||||
return _BOARD[pos];
|
||||
return _BOARD[pos] - 1;
|
||||
}
|
||||
|
||||
result = checkLine(pos, VERTICAL);
|
||||
if (result) {
|
||||
return _BOARD[pos];
|
||||
return _BOARD[pos] - 1;
|
||||
}
|
||||
|
||||
result = checkLine(pos, DIAGONAL);
|
||||
if (result) {
|
||||
return _BOARD[pos];
|
||||
return _BOARD[pos] - 1;
|
||||
}
|
||||
|
||||
result = checkLine(pos, DIAGONAL_INV);
|
||||
if (result) {
|
||||
return _BOARD[pos];
|
||||
return _BOARD[pos] - 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue