1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
// child process
void child(int READ, int WRITE) {
char input[2];
int num = 0;
int g, r, c;
Game response;
Cell move;
initGame();
system("clear");
printf("[This is where the name of the");
printf("game will go.]\n\n");
printf("\t1 - One Player\n");
printf("\t2 - Two Players\n");
printf("\tQ - Quit\n");
printf("\tEnter selection: ");
scanf("%ls", input);
printf("Checkpoint 1"); //Diagnostic
while ( input[0] != '1' && input[0] != '2' && input[0] != 'q' && input[0] != 'Q' ) {
system("clear");
printf("[This is where the name of the");
printf("game will go.]\n");
printf("\nInvalid selection!\n");
printf("\t1 - One Player");
printf("\t2 - Two Players");
printf("\tQ - Quit\n");
printf("\tEnter selection: ");
scanf("%ls", input);
}
printf("Checkpoint 2"); //Diagnostic
if ( input[0] == 'q' || input[0] == 'Q' ) game.quit = 1;
else {
game.players = atoi(input[0]);
populateVectorList();
}
while (!game.quit) {
displayBoard();
if (game.turn > 2) {
printf("Player 2 moved to Grid %i, Row %i, Column %i.", game.lastMove.grid, game.lastMove.row, game.lastMove.col);
}
printf("Player 1, it's your turn!");
printf("Enter grid # (1-4), 'Q' to quit: ");
scanf("%ls", input);
while (input[0] != 'q' || input[0] != 'Q' || input[0] != '1' || input[0] != '2' || input[0] != '3' || input[0] != '4') {
system("clear");
displayBoard();
printf("Player 1, it's your turn!");
printf("Enter grid # (1-4), 'Q' to quit: ");
scanf("%ls", input);
}
if (input[0] == 'q' || input[0] == 'Q') {
game.quit = 1;
continue;
} else g = atoi(input);
printf("Enter row #: ");
scanf("%ls", input);
while (!(0 < atoi(input) < 5)) {
system("clear");
displayBoard();
printf("Player 1, it's your turn!");
printf("Enter grid # (1-4), 'Q' to quit: %d/n", g);
printf("Enter row #: ");
scanf("%ls", input);
}
r = atoi(input);
printf("Enter column #: ");
scanf("%ls", input);
while (!(0 < atoi(input) < 5)) {
system("clear");
displayBoard();
printf("Player 1, it's your turn!");
printf("Enter grid # (1-4), 'Q' to quit: %i/n", g);
printf("Enter row #: %i/n", r);
printf("Enter column #: ");
scanf("%ls", input);
}
c = atoi(input);
game.board[g][r][c] = 1;
game.lastMove.grid = g;
game.lastMove.row = r;
game.lastMove.col = c;
game.turn++;
write(WRITE, &game, sizeof(game));
read(READ, &response, sizeof(response));
game = response;
}
printf("CHILD SEZ GOODBYE!!");
close(READ);
close(WRITE);
}
|