Esempio n. 1
0
void FinishedState::Handle(GameManager& gm){
	map<shared_ptr<Player>, int> scoreboard;
	
	for (int i{ 0 }; gm.GetPlayerList()->Size(); i++) {
		int points{ 0 };
		shared_ptr<Player> player = gm.GetPlayerList()->GetPlayerAt(i);

		// Points for every building in the city
		points += player->GetCityCardContainer()->Size();

		// 5 points if player owns buildings of all the 5 colours
		if (HasBuildingsOf5Colours(player)) {
			points += 5;
		}
		// 4 points for the first player who builds 8 buildings
		if (player.get() == gm.get8Buildings().get()) {
			points += 4;
		}
		// 2 points for each player who constructed 8 buildings as well
		else if (player->GetCityCardContainer()->Size() >= 8) {
			points += 2;
		}

		if (player->GetCityCardContainer()->HasCard("Drakenpoort")) {
			points += 2;
		}

		if (player->GetCityCardContainer()->HasCard("Universiteit")) {
			points += 2;
		}

		scoreboard[player] = points;
	}

	shared_ptr<Player> winner = GetWinningPlayer(scoreboard);

	winner->Send("Congratulations, you have won the game with " + std::to_string(scoreboard[winner]) + " points");
	gm.GetPlayerList()->SendAllBut(winner, "The game has been won by " + winner->GetName() + " with " + std::to_string(scoreboard[winner]) + " points");




	while (true){
		// prevent the server from shutting down.
		std::this_thread::sleep_for(std::chrono::milliseconds(1000));
	}

}
Esempio n. 2
0
void GameRunningState::Handle(GameManager& gm){

	gm.GetPlayerList()->SendAll("Everyone seems ready! Happy Citadels Game, and may the odds be ever in your favor!");

	while (true){
		m_CurrentRound->Handle(*this, gm);
	}


}
Esempio n. 3
0
void GameModule::SendCurRoomPokersTo(const unsigned int &playerID)
{
  using face2wind::PokerVo;
  using face2wind::RoomManager;
  using face2wind::PlayerManager;
  using face2wind::GameManager;

  PlayerManager *playerMgr = PlayerManager::GetInstance();
  RoomManager *roomMgr = RoomManager::GetInstance();
  GameManager *gameMgr = GameManager::GetInstance();

  unsigned int roomID = roomMgr->GetRoomID(playerID);
  if(0 == roomID)
    return;
  std::vector<unsigned int> *roomPlist = gameMgr->GetPlayerList(roomID);
  SC10202 *sc2 = new SC10202();
  sc2->nextTurnIndex = gameMgr->GetCurrentTurnIndex(roomID);
  unsigned int index = 0;
  for(std::vector<unsigned int>::iterator pid = roomPlist->begin();
      pid != roomPlist->end(); ++pid){
    std::vector<PokerVo*> *pokerList = gameMgr->GetPlayerPokerList(*pid);
    SC10202_pokerNumList num;
    if(NULL != pokerList)
      num.pokerNum = pokerList->size();
    else
      num.pokerNum = 0;
    sc2->pokerNumList.push_back(num);
    if(playerID == *pid && NULL != pokerList){
      sc2->roleIndex = index;
      for(std::vector<PokerVo*>::iterator pvo = pokerList->begin();
	  pvo != pokerList->end(); ++pvo){
	PokerInfo info;
	info.color = (*pvo)->color;
	info.value = (*pvo)->value;
	sc2->pokerList.push_back(info);
      }
    }
    ++index;
  }
  unsigned int roomPlayerSocketID = playerMgr->GetSocketFDWithPlayerID(playerID);
  networkMgr->SendMessage(10202,sc2,roomPlayerSocketID);
}