int main(int argc, char ** argv) {
  if (argc != 4) {
    fprintf(stderr,"Usage: minesweeper width height numMines\n");
    return EXIT_FAILURE;
  }
  int width = atoi(argv[1]);
  int height = atoi(argv[2]);
  int numMines = atoi(argv[3]);
  if (width <= 0 || height <= 0 || numMines <= 0) {
    fprintf(stderr,
	    "Width, height, and numMines must all be positive ints\n");
    return EXIT_FAILURE;
  }
  char * line = NULL;
  size_t linesz = 0;

  do {
    board_t * b = makeBoard (width, height, numMines);
    int gameOver = 0;
    while (!gameOver) {
      gameOver = playTurn(b, &line, &linesz);
    }
    freeBoard(b);
    do {
      printf("Do you want to play again?\n");
    } while(getline(&line, &linesz, stdin) == -1);
  } while(line[0] == 'Y' || line[0] == 'y');
  free(line);
  return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
void World::endTurn()
{
	playTurn();
	draft(m_age);
	if (m_age >= NUMBER_OF_AGES && betweenTurns())
	{
		computeScores();
		m_gameOver = true;
	}
}
Ejemplo n.º 3
0
TicTacToeGame::TicTacToeGame(Player* player1, Player* player2) {
	playerTurn = CROSS;

	this->crossPlayer = player1;
	player1->setId(CROSS);

	this->circlePlayer = player2;
	player2->setId(CIRCLE);
	

	while (1) {
		playTurn();
		board.showBoard();
		AnybodyWon();
	}
}
Ejemplo n.º 4
0
int main(int argc, char **argv) {
  // make random game
  Node *queue1 = NULL;
  Node *queue2 = NULL;
  struct gameState state;
  makeGame(&queue1, &queue2, &state);

  // play game
  while (!isGameOver(&state)) {
    playTurn(&queue1, &queue2, &state);
  }

  // record sequence of states of game
  recordResults(queue1, queue2);

  return EXIT_SUCCESS;
}