Example #1
0
void Model::nextPlayer() {
  this->incrementActivePlayerId();
  Player* player = this->activePlayer();
  this->notify();

  // check if this player has any cards to play
  // if not, end the turn and notify
  if (player->hand().size() == 0) {
    std::cerr << "Setting round to ended" << std::endl;
    this->roundEnded_ = true;
    std::cerr << "Notifying user" << std::endl;
    this->notify();
    if (!this->hasWinner()) {
      std::cerr << "Game didn't have a winner, so we start another round" << std::endl;
      this->startRound();
    } else {
      std::cerr << "Game had a winner" << std::endl;
      this->endGame();
    }
    std::cerr << "Updating the view after either starting another round or ending the game" << std::endl;
    return;
  }

  if (player->type() == "Computer") {
    Computer* computer = (Computer*)player;
    Card* card = computer->play(this->legalPlaysInHand(computer->hand()));
    if (card != NULL) {
      this->cardsOnTable_[card->getSuit()][card->getRank()] = card;
    }
    this->notify();
    this->nextPlayer();
  }

}