79 lines
1.7 KiB
C
79 lines
1.7 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <sys/ipc.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/msg.h>
|
|
#include <signal.h>
|
|
#include <sys/sem.h>
|
|
#include <sys/shm.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
#include <custom_sem.h>
|
|
#include <structures.h>
|
|
#include <custom_shm.h>
|
|
#include <errExit.h>
|
|
#include <custom_msgq.h>
|
|
#include <forza4.h>
|
|
#include <client.h>
|
|
|
|
void checkClientinput(int argc, char *argv[]);
|
|
|
|
//TODO: mettere main ma non l'ho fatto per makefile
|
|
int main(int argc, char *argv[]){
|
|
|
|
printf("Il mio pid per killarmi: %d\n", getpid()); //TMP
|
|
|
|
setupClient(argc, argv);
|
|
|
|
// aspetto che il server mi dia il permesso di collegarmi e segnalo collegamento al server
|
|
semOp(_SEMID, ID, -1);
|
|
printf(PCLIENT "Connecting to server...\n");
|
|
semOp(_SEMID, 2, 1);
|
|
|
|
|
|
// mando i miei dati al server
|
|
player_ds player = {.mtype = 3, .id = ID, .pid = getpid()};
|
|
strcpy(player.name_player, argv[1]);
|
|
sndPlayer(&player);
|
|
|
|
printf(PCLIENT "Searching for oponent...\n");
|
|
|
|
semOp(_SEMID, ID, -1);
|
|
|
|
printf(PCLIENT "Opponent found\n");
|
|
|
|
printBoard();
|
|
printf(PCLIENT "Waiting for oponent\n");
|
|
|
|
|
|
|
|
// PARTITA
|
|
move_t move = {.mtype = 2};
|
|
|
|
while (1) {
|
|
// aspetto il mio turno
|
|
semOp(_SEMID, ID, -1);
|
|
printBoard();
|
|
|
|
// input e controllo
|
|
printf(PCLIENT "Your Turn: ");
|
|
|
|
int pos;
|
|
do {
|
|
scanf("%d", &move.move);
|
|
move.move = checkMove(move.move - 1);
|
|
} while (move.move == -1);
|
|
|
|
// mando mossa al server
|
|
sndMove(&move);
|
|
|
|
semOp(_SEMID, ID, -1);
|
|
printBoard();
|
|
|
|
printf(PCLIENT "Waiting for opponent\n");
|
|
}
|
|
|
|
return 0;
|
|
} |