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