Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

1 Department of Computer Science and Software Engineering Advanced program design with C++ Problem statement This is a team assignment. It is divided into four distinct parts. Each part is about the...

1 answer below »
1
Department of Computer Science
and Software Engineering
Advanced program design with C++
Problem statement
This is a team assignment. It is divided into four distinct parts. Each part is about the development
of a part of the topic presented as the team project. Even though it is about the development of a
part of your team project, each assignment is to be developed/presented/tested separately. The
description of each part portrays what are the features that the part should implement, and what
you should demonstrate. Note that the following descriptions describe the baseline of the
assignment, and are related to the project description [1]. See the course web page for a full
description of the team project, as well as links to the details of the game rules to be implemented.
Design Requirements (for all the five parts)
1. All data members of all classes must be of pointer type.
2. All file names and the content of the files must be according to what is given in the description
elow.
Part 1: Game start
Provide a group of C++ classes that implements a user interaction mechanism to start the game
y allowing the following:
1) select the number of players in the game (2-4 players).
2) select the appropriate game map from a list of files as stored in a directory. Use the map loade
to load the appropriate game map (e.g. for 2 players the 5X5 game map, for 3 players 5X5 plus
the top and bottom green squares game map, etc.).
3) use ResourceTracker()method to set the four game resource markers.
4) create the players objects.
5) use the map loader to load a village map and assign one to each player.
6) create a concreate deck of 60 harvest tiles objects (not random).
7) create a concreate deck of 144 buildings tiles objects (not random).
8) use DrawBuilding()method to draw 5 buildings tiles to form the initial face up pool of the game.
9) assign an empty hand of cards to each player.
10) each player uses DrawBuilding()method to draw six buildings tiles, that stays hidden to the othe
players and two harvest tiles from each deck. Player’s harvest tiles and buildings are private (hidden to
the other players).
2
11) each player uses DrawHarvestTile()to draw one harvest tile to be placed face down with his
village board as his ‘shipment’ tile1.
Requirements part 1: You must deliver a driver that demonstrates the above game set up steps.
Part 2: Game play: Main loop
Provide a group of C++ classes that implements the startup phase following the rules of the New
Haven game. This phase is composed of the following sequence:
1. The player with the smallest ID number will begin. The play continues with each player taking a
turn clockwise until one space is left unfilled on the board. The game ends when there is only
one space left on the board. Each player will take an equal number of turns.
2. On each turn the active player begins by selecting one of their harvest tiles and placing it onto
the Game Board using PlaceHarvestTile()method. This play will generate a supply of
esources. The amount of resources collected is indicated by increasing the Resource Markers.
The active player will then construct buildings in his village using BuildVillage() method
with the co
esponding resources. When the active player is finished, each other player in
clockwise order will have the option of also using any remaining resources to construct
uildings in their own village.
3. After everyone has had one chance to build or passes, the active player draws new buildings
ased on the final position of the Resource Markers. The Resource Markers are then reset to
zero value and the player draws a new harvest tile to replace the one just played. The selection
of face up Buildings is replenished and the play proceeds with the next player in a clockwise
turn.
Requirements part 2: You must deliver a driver that demonstrates:
• Running of a game loop with each player turn starting with the first and going clockwise
order.
• Each player draws his resources (building, harvest), uses the exchange() method to select
the position on the board to place the harvest tile, then plays a building tile with the
appropriate cost of the resources.
• A display of each player’s turn and possessions.
Part 3: Game play: Turn Sequence
Provide a group of C++ classes that implements each of the following player sequences.
1. Play a harvest tile
The active player selects either a harvest tile from his possession and place it on any open space on the
Game Board. The colors and symbols on the harvest tile do not need to align with adjacent tiles already on
the game board. The new harvest tile doesn’t even need to be placed adjacent to tiles already on the board.
The harvest tile must only be played within the area allowed for the number of players.
The player can also choose to play with his SHIPMENT tile, instead of his normal harvest tile. In this case
he needs to place SHIPMENT tile face down onto the Board. This tile represents his receiving a supply of
esources.
1 Never look at this tile until AFTER it has been played. This tile represents the opportunity that once per game
player may receive 4 of the same resources and temporarily ignore what is actually on the tile.
3
2. Determine Resources Gathered
Use CalculateResources()to calculate the amount of resources collected for each colo
shown on the harvest tile the player just placed. For each color on the tile, the value is equal to the
squares of that color on the tile plus the number of squares forming a connected chain of matching
color from the harvest tile just placed. These chains may only connect orthogonally across edges,
never diagonally through corners.
Updates the ResourceTracker()to reflect the total collected of each color. Note: since there are
1, 2 or 3 colors possible on each tile placed, there will always be at least one Resource which
emains at zero.
3. Build player Village
Each active player can use any of his building tiles as a potential addition to his village. He can
uild as many as he likes and can afford. A building tile may only be played if the remaining
esources in the matching color equals or exceeds the number on the Village Board space. Fo
every Building played, decrease the co
esponding Resource Marker by the number on the board
space where the Building was played.
There are a set of restrictions on how player may place Buildings:
o Only one Building may occupy each space.
o The first Building of a particular color that the player places into his Village may be put into
any empty space. It does not matter what other colors may be adjacent to that space.
o If the color of the Building the player places is already on his Village Board, then the playe
must place the new Building adjacent to a Building of the same color. Buildings are only
adjacent if they are connected across edges, not diagonally. This rule means that all Buildings
of a certain color will be connected as part of a single large chain in the Village.
o Buildings may only be played face up if the number on the space matches the number showing
on the Building.
o Buildings may be played face down onto any number space, regardless of the number on the
Building.
4. Share the Wealth
It will often be the case that the player cannot use all of the resources created by placing his harvest
tile. Proceeding clockwise, every other player has one chance to erect Buildings using the
esources still available.
Proceeding clockwise, each player may use any leftover resources to construct buildings in thei
village, or pass. If they build, they follow the same rules as listed above under Build Player Village.
Each player in turn order only gets one opportunity to erect Buildings in their Village, or pass.
5. Draw Buildings
After all other players have built or passed, the active player draws new Buildings. He must draw
one Building for every Resource Marker on the 0 (zero) space of the Resource Track.
The first Building the player takes must be from the set of five Buildings of the game pool. Any
other buildings he takes may be from this set of game pool or from the deck. Once the player has
finished drawing, he must replace Buildings drawn from the face up, set with new Buildings from
the deck.
4
6. End of Turn
The player needs to rest all four Resource Markers back to zero for the Resource Track, then draw
a new Harvest Tile to replace the one he played at the start of the turn. Then the turn passes to the
next payer following clockwise order.
Note: If the player is playing his SHIPMENT Tile, he does not get to draw a replacement Harvest
Tile. Instead, he has to flip the Shipment Tile over from left to right so it is now face up. It is no
longer 4 of anything and becomes only what is actually shown on the Tile.
Requirements part 3: You must deliver a driver that demonstrates the above game turn sequences.
Part 4: Main game loop: Compute the game score
The game ends when there is exactly one open space left on the Game Board. Scoring is based on how
many colonists each player attracted to his Village.
The player with the highest score is the winner. In the event of a tie, the player with the fewest
empty spaces on their board wins. If still tied, then the player with the least buildings leftover
wins. If this result is still a tie then it is a shared win between those players.
Requirements part 4: You must deliver a driver that demonstrates:
• The result of the ComputeScore() method that counts the number of colonists for each
player.
• Displays the winner.
Part 5: Turn Observer
Using the Observer design pattern, implement a view that displays information happening in the
cu
ent turn. It should first display a header showing what player and what is cu
ently being
played, example: The active player 2: plays a Harvest Tile by placing it on the Game Board, this
play,
i) will generate resources collected that will be indicated by an increase of Resource Markers.
Then, this active player will construct Buildings in his/her Village using the co
esponding
esources.
ii) Which will update the village buildings count of the player.
For every building played
iii) It will result in a decrease of co
esponding Resources Marker by the number of the played
Building.
Your solution should display important information related
Answered Same Day Apr 09, 2021

Solution

Abr Writing answered on Apr 16 2021
143 Votes
New Haven/CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
set(CMAKE_CXX_STANDARD 14)
project(game)
add_executable(game GameDriver.cpp Player.cpp Resources.cpp MapVG.cpp MapGB.cpp MapVGLoader.cpp MapGBLoader.cpp GameObservers.cpp Graph/Graph.cpp Graph/Node.cpp)
New Haven/game2.txt
0 11240
4 23420
20 44320
24 12420
New Haven/game3.txt
5 11240
9 23420
25 44320
29 12420
New Haven/game4.txt
6 11240
10 23420
34 44320
38 12420
New Haven/GameDrive
New Haven/GameDriver.cpp
New Haven/GameDriver.cpp
#include "GameObservers.h"
#include using std::cout;
using std::cin;
int main(){
    Game* game = new Game();
    TurnObserver* turnObserver = new TurnObserver(game);
    StatsObserver* statsObserver = new StatsObserver(game);    
    game->initialize();
    while (!game->gameDone()) {
        game->placeTilePhase();
        game->placeBuildingsPhase();
        game->drawPhase();
        game->nextTurn();
        string skip = "";
        while (skip != "Y" && skip != "N") {
            cout 
 "Skip to game end (Y/N)?";
            cin 
 skip;
        }
        if(skip == "Y"){
            *(game->activePlayer) = 0;
            *(game->handPlayer) = 0;
            *(game-
ound_num) = 11;
        }
    }
    game->ComputeScore();
    string end = "Enter anything to end the game";
    cout 
 end;
    cin 
 end;
    delete game;
    delete turnObserver;
    delete statsObserver;
    return 0;
}
New Haven/GameObservers.cpp
#include "GameObservers.h"
#include #include
its/stdc++.h
using std::cout;
using std::cin;
Observer::Observer(){};
Observer::~Observer(){};
Subject::Subject() {
_observers = new list;
}
Subject::~Subject() {
delete _observers;
}
void Subject::Attach(Observer* o){
_observers->push_back(o);
}
void Subject::Detach(Observer *o) {
_observers-
emove(o);
}
void Subject::Notify() {
list::iterator i = _observers-
egin();
for(; i != _observers->end(); i++)
(*i)->Update();
}
ool Game::valid_tile_pos(string pos) {
bool valid = false;
if(*playercount >= 2){
if(pos == "0" || pos == "1" || pos == "2" || pos == "3" || pos == "4" || pos == "5" || pos == "6"
|| pos == "7" || pos == "8" || pos == "9" || pos == "10" || pos == "11" || pos == "12" || pos == "13"
|| pos == "14" || pos == "15" || pos == "16" || pos == "17" || pos == "18" || pos == "19" || pos == "20"
|| pos == "21" || pos == "22" || pos == "23" || pos == "24")
valid = true;
}
if(*playercount >= 3){
if(pos == "25" || pos == "26" || pos == "27" || pos == "28" || pos == "29" || pos == "30" || pos == "31"
|| pos == "32" || pos == "33" || pos == "34")
valid = true;
}
if(*playercount == 4){
if(pos == "35" || pos == "36" || pos == "37" || pos == "38" || pos == "39" || pos == "40" || pos == "41"
|| pos == "42" || pos == "43" || pos == "44")
valid = true;
}
return valid;
}
ool Game::valid_building_pos(string pos) {
return (pos == "0" || pos == "1" || pos == "2" || pos == "3" || pos == "4" || pos == "5" || pos == "6"
|| pos == "7" || pos == "8" || pos == "9" || pos == "10" || pos == "11" || pos == "12" || pos == "13"
|| pos == "14" || pos == "15" || pos == "16" || pos == "17" || pos == "18" || pos == "19" || pos == "20"
|| pos == "21" || pos == "22" || pos == "23" || pos == "24" || pos == "25" || pos == "26" || pos == "27"
|| pos == "28" || pos == "29");
}
ool Game::is_number(string str) {
bool isNumber = true;
for(int i=0; i < str.size(); i++) {
if(str[i] != '0' && str[i] != '1' && str[i] != '2' && str[i] != '3' && str[i] != '4' && str[i] != '5'
&& str[i] != '6' && str[i] != '7' && str[i] != '8' && str[i] != '9')
isNumber = false;
}
return isNumber;
}
Game::Game() {
round_num = new int(1);
activePlayer = new int(0);
playercount = new int(0);
deliveryPos = new int(0);
handPlayer = new int(0);
phase = new string("Place Tile");
usedDelivery = new bool(false);
deliveryTile = new HarvestTile();
revealedBuildings = new RevealedBuildings();
players = new Player*[4];
gameBoard = new MapGB();
buildingDeck = new BuildingDeck();
harvestTileDeck = new HarvestTileDeck();
winStr = new string();
}
Game::~Game() {
delete round_num;
delete activePlayer;
delete playercount;
delete deliveryPos;
delete handPlayer;
delete phase;
delete usedDelivery;
delete deliveryTile;
delete revealedBuildings;
delete players[0];
delete players[1];
delete players[2];
delete players[3];
delete[] players;
delete gameBoard;
delete buildingDeck;
delete harvestTileDeck;
delete winStr;
}
void Game::initialize() {

string playercountstr;
while(!(playercountstr == "2" || playercountstr == "3" || playercountstr == "4")) {
cout
"Enter number of players:";
cin
playercountstr;
}
*playercount = stoi(playercountstr);

MapGBLoader gbloader;
gameBoard = gbloader.load(*playercount);

for(int i = 0; i < *playercount; i++){
string villageName;
cout
"Enter village name for Player "
i+1
":";
cin
villageName;
if(villageName.length() > 17)
villageName = villageName.substr(0, 17);
players[i] = new Player(i+1, villageName);
}

for(int i = 0; i < 5; i++) {
revealedBuildings->addBuilding(buildingDeck->drawBuilding());
}

for(int i = 0; i < *playercount; i++){
for(int j = 0; j < 6; j++){
players[i]->DrawBuilding(buildingDeck);
}
players[i]->DrawHarvestTile(harvestTileDeck);
players[i]->DrawHarvestTile(harvestTileDeck);
players[i]->getHand()->setDeliveryTile(harvestTileDeck->drawHarvestTile());
}
}
void Game::placeTilePhase() {
*phase = "place tile";
Notify();
string tilestr = "";
bool validTile = false;
while(!validTile) {
cout
"Select harvest tile to play:";
cin
tilestr;
if(tilestr == "0" || tilestr == "1")
validTile = true;
else if(tilestr == "2" && players[*activePlayer]->getHand()->hasDeliveryTile())
validTile = true;
}
int tile = stoi(tilestr);

if(tile == 2){
*usedDelivery = true;
string data[4] = {"","","",""};
string mes[4] = {"top left", "top right", "bottom left", "bottom right"};
HarvestTile* placedTile = new HarvestTile();
*deliveryTile = players[*activePlayer]->getHand()->useDeliveryTile();
cout
"Select tile data (Wheat, Timber, Rock, Sheep)\n";
for(int i=0; i < 4; i++) {
while (data[i] != "Wheat" && data[i] != "Timber" && data[i] != "Rock" && data[i] != "Sheep") {
cout
"Select "
mes[i]
" data:";
cin
data[i];
}
}
placedTile->setTopLeftResource(&data[0]);
placedTile->setTopRightResource(&data[1]);
placedTile->setBottomLeftResource(&data[2]);
placedTile->setBottomRightResource(&data[3]);
players[*activePlayer]->getHand()->addHarvestTile(*placedTile);
string posstr = "";
bool validPos = false;
while(!validPos){
cout
"Select position for tile:";
cin
posstr;
if(valid_tile_pos(posstr)) {
*deliveryPos = stoi(posstr);
validPos = players[*activePlayer]->PlaceHarvestTile(gameBoard, 2, *deliveryPos, 0);
}
}
}

else{
string rotstring = "";
while(rotstring != "0" && rotstring != "1" && rotstring != "2" && rotstring != "3") {
cout
"Select rotation (0:none 1:90cw 2:180cw 3:270cw):";
cin
rotstring;
}
string posstr = "";
bool validPos = false;
while(!validPos){
cout
"Select position for tile:";
cin
posstr;
if(valid_tile_pos(posstr))
validPos = players[*activePlayer]->PlaceHarvestTile(gameBoard, tile, stoi(posstr), stoi(rotstring));
}
}
}
void Game::placeBuildingsPhase() {
for(int i=0; i < *playercount; i++){
bool placing = true;
*handPlayer = (*activePlayer + i) % *playercount;
*phase = "player "+to_string(*handPlayer + 1)+" place building";
Notify();
while(placing) {
if (players[*handPlayer]->getHand()->getNumOfBuildings() > 0) {
string option = "";
while (option != "0" && option != "1") {
cout
"Place building (0) or Skip (1):";
cin
option;
}
if (option == "0") {
string buildingStr = "";
int building = 0;
bool validBuilding = false;
while (!validBuilding) {
cout
"Select building to place:";
cin
buildingStr;
if (is_number(buildingStr)) {
building = stoi(buildingStr);
if (building >= 0 && building < players[*handPlayer]->getHand()->getNumOfBuildings()) {
validBuilding = true;
}
}
}
string flippedStr = "";
bool flipped = false;
while(flippedStr != "0" && flippedStr != "1"){
cout
"Place building face up (0) or flipped (1):";
cin
flippedStr;
}
if(flippedStr == "1")
flipped = true;
string buildPos = "";
while(!valid_building_pos(buildPos)){
cout
"Select position to build:";
cin
buildPos;
}
if(players[*handPlayer]->BuildVillage(building, stoi(buildPos), flipped, players[*activePlayer]->ResourceTracker()))
Notify();
}
else {
placing = false;
}
}
else{
placing = false;
}
}
}
*handPlayer = *activePlayer;
}
void Game::drawPhase() {
*phase = "draw";
Notify();

bool fromPool = false;
for(int i=0; i<4; i++){
if(players[*activePlayer]->ResourceTracker()->at(i) == 0){
if(!fromPool){
string selectedstr = "";
int selected = 5;
while(selected >= revealedBuildings->getSize()) {
cout
"Draw a revealed building:";
cin
selectedstr;
if (selectedstr == "0" || selectedstr == "1" || selectedstr == "2" ||
selectedstr == "3" || selectedstr == "4") {
selected = stoi(selectedstr);
}
}
players[*activePlayer]->getHand()->addBuilding(revealedBuildings->DrawBuilding(selected));
fromPool = true;
Notify();
}
else{
string option = "";
cout
"Draw from revealed (0) or Draw from deck (1)\n";
while(!(option == "0" || option == "1")){
cout
"Draw Location:";
cin
option;
}
if(option == "0"){
string selectedstr;
int selected = 5;
while(selected >= revealedBuildings->getSize()) {
cout
"Draw a revealed building:";
cin
selectedstr;
if (selectedstr == "0" || selectedstr == "1" || selectedstr == "2" ||
selectedstr == "3" || selectedstr == "4") {
selected = stoi(selectedstr);
}
}
players[*activePlayer]->getHand()->addBuilding(revealedBuildings->DrawBuilding(selected));
fromPool = true;
Notify();
}
else{
players[*activePlayer]->DrawBuilding(buildingDeck);
Notify();
}
}
}
}

if(!*usedDelivery){
players[*activePlayer]->DrawHarvestTile(harvestTileDeck);
}
}
void Game::nextTurn(){

int missing = 5 - revealedBuildings->getSize();
for(int i = 0; i < missing; i++){
revealedBuildings->addBuilding(buildingDeck->drawBuilding());
}

if(*usedDelivery) {
players[*activePlayer]->getHand()->addHarvestTile(*deliveryTile);
players[*activePlayer]->getHand()->exchange(gameBoard, *activePlayer + 1, 2, to_string(*deliveryPos), 0);
}

players[*activePlayer]->ResourceTracker()->assign(4, 0);
*usedDelivery = false;

if (*activePlayer >= *playercount - 1) {
*activePlayer = 0;
*handPlayer = 0;
*round_num = *round_num + 1;
} else {
*activePlayer = *activePlayer + 1;
*handPlayer = *handPlayer + 1;
}
}
void Game::ComputeScore() {
*phase = "GAME OVER";
*handPlayer = -1;

int scores[*playercount];
int buildingCount[*playercount];
int handBuildings[*playercount];
for(int i=0; i < *playercount; i++){
scores[i] = players[i]->getScoreCounter()->CalculateScore(players[i]->getVillage());
buildingCount[i] = players[i]->getVillage()->getBuildingCount();
handBuildings[i] = players[i]->getHand()->getNumOfBuildings();
}

vecto
int> topScorePlayers;
int highestScore = 0;
for(int i=0; i < *playercount; i++){
if(scores[i] == highestScore) {
topScorePlayers.push_back(i);
}
else if(scores[i] > highestScore){
topScorePlayers.clear();
topScorePlayers.push_back(i);
highestScore = scores[i];
}
}

vecto
int> topBuildingPlayers;
int highestCount = 0;
for(int i=0; i < topScorePlayers.size(); i++){
if(buildingCount[topScorePlayers.at(i)] == highestCount) {
topBuildingPlayers.push_back(topScorePlayers.at(i));
}
else if(buildingCount[topScorePlayers.at(i)] > highestCount){
topBuildingPlayers.clear();
topBuildingPlayers.push_back(topScorePlayers.at(i));
highestCount = buildingCount[topScorePlayers.at(i)];
}
}

vecto
int> topHandPlayers;
int smallestHand = INT_MAX;
for(int i=0; i < topBuildingPlayers.size(); i++){
if(handBuildings[topBuildingPlayers.at(i)] == smallestHand) {
topHandPlayers.push_back(topBuildingPlayers.at(i));
}
else if(handBuildings[topBuildingPlayers.at(i)] < smallestHand){
topHandPlayers.clear();
topHandPlayers.push_back(topBuildingPlayers.at(i));
smallestHand = handBuildings[topBuildingPlayers.at(i)];
}
}

*winStr = "PLAYER(S) "+ to_string(topHandPlayers.at(0)+1);
for(int i = 1; i < topHandPlayers.size(); i++){
*winStr +=" & "+ to_string(topHandPlayers.at(i)+1);
}
*winStr += " WIN!\n";
Notify();
}
ool Game::gameDone() {
return *round_num > 10;
}
int Game::getRound() {
return *round_num;
}
int Game::getActivePlayer() {
return *activePlayer;
}
int Game::getPlayerCount() {
return *playercount;
}
vecto
string> Game::getGameBoardStrs() {
return gameBoard->toStrings();
}
vecto
vecto
string
Game::getVillagesStrs() {
vecto
vecto
string
villagesStrs(*playercount);
for(int i = 0; i < *playercount; i++){
villagesStrs[i] = players[i]->getVillage()->toStrings();
}
return villagesStrs;
}
string Game::getRevealedBuildingsStr() {
return revealedBuildings->toString();
}
vecto
string> Game::getVillageNames() {
vecto
string> villagesNames(*playercount);
for(int i = 0; i < *playercount; i++){
villagesNames[i] = players[i]->getVillage()->getName();
}
return villagesNames;
}
string Game::getTrackerStr() {
return players[*activePlayer]->tracker_to_string();
}
int Game::getHandPlayer() {
return *handPlayer;
}
void Game::printCu
entHand() {
cout
*players[*handPlayer]->getHand();
}
string Game::getPhase() {
return *phase;
}
vecto
string> Game::getStatsStrs(){
vecto
string> stats(*playercount);
for(int i=0; i < stats.size(); i++){
int score = players[i]->getScoreCounter()->CalculateScore(players[i]->getVillage());
int bCount = players[i]->getVillage()->getBuildingCount();
int hCount = players[i]->getHand()->getNumOfBuildings();
stats[i] = "Player "+to_string(i+1)+" ("+players[i]->getVillage()->getName()+") - score:"+to_string(score)
+" - board buildings:"+to_string(bCount)+" - hand buildings:"+to_string(hCount);
}
return stats;
}
string Game::getWinnerStr() {
return *winStr;
}
TurnObserver::TurnObserver() {}
TurnObserver::TurnObserver(Game *g) {
_subject = g;
_subject->Attach(this);
}
TurnObserver::~TurnObserver() {
_subject->Detach(this);
}
void TurnObserver::Update() {
display();
}
void TurnObserver::display() {
cout
string(50, '\n');
if(_subject->getRound() <= 10)
cout
"ROUND "
to_string(_subject->getRound())
" PLAYER "
to_string(_subject->getActivePlayer()+1)
"'S TURN - ";
cout
_subject->getPhase()
"\n";

vecto
string> gameBoardStrings = _subject->getGameBoardStrs();
vecto
vecto
string
villagesStrs = _subject->getVillagesStrs();
string revealedStr = _subject->getRevealedBuildingsStr();
vecto
string> villageNames = _subject->getVillageNames();

cout
"Gameboard";
if(_subject->getPlayerCount() < 4){
cout
" ";
}
else{
cout
" ";
}
for(int i=0; i < villageNames.size(); i++){
cout
villageNames[i];
cout
string(22-villageNames[i].length(), ' ');
}
cout
"\n";

for(int i=0; i < 7; i++){
cout
gameBoardStrings.at(i);
for(int j=0; j < villagesStrs.size(); j++){
cout
" "
villagesStrs[j][i];
}
cout
"\n";
}

cout
gameBoardStrings.at(7)
"\n";
cout
gameBoardStrings.at(8)
"\n";
cout
gameBoardStrings.at(9)
" Revealed Buildings\n";
cout
gameBoardStrings.at(10)
" "
revealedStr
"\n";

cout
gameBoardStrings.at(11)
"\n";
cout
gameBoardStrings.at(12)
"\n";
cout
gameBoardStrings.at(13)
" Resource Tracker\n";
cout
gameBoardStrings.at(14)
" "
_subject->getTrackerStr()
"\n";

for(int i=15; i < gameBoardStrings.size(); i++){
cout
gameBoardStrings.at(i)
"\n";
}
cout
"\n";

if(_subject->getHandPlayer() != -1) {
cout
"Player "
to_string(_subject->getHandPlayer() + 1)
"'s ";
_subject->printCu
entHand();
cout
"\n";
}
}
StatsObserver::StatsObserver() {}
StatsObserver::StatsObserver(Game *g) {
_subject = g;
_subject->Attach(this);
}
StatsObserver::~StatsObserver() {
_subject->Detach(this);
}
void StatsObserver::Update() {
display();
}
void StatsObserver::display() {
if(_subject->gameDone())
cout
_subject->getWinnerStr()
"\n";
vecto
string> stats = _subject->getStatsStrs();
for(int i=0; i < stats.size(); i++){
cout
stats[i]
"\n";
}
cout
"\n";
}
New Haven/GameObservers.h
#ifndef GAME_GAMEOBSERVERS_H
#define GAME_GAMEOBSERVERS_H
#include #include "MapGB.h"
#include "Player.h"
#include "Resources.h"
#include "MapGBLoader.h"
using std::list;
class Observer{
public:
~Observer();
virtual void Update() = 0;
protected:
Observer();
};
class Subject{
public:
virtual void Attach(Observer* o);
virtual void Detach(Observer* o);
virtual void Notify();
Subject();
~Subject();
private:
list *_observers;
};
class Game : public Subject{
friend int main();
private:
int* round_num;
int* activePlayer;
int* playercount;
int* deliveryPos;
int* handPlayer;
string* phase;
bool* usedDelivery;
HarvestTile* deliveryTile;
RevealedBuildings* revealedBuildings;
Player** players;
MapGB* gameBoard;
BuildingDeck* buildingDeck;
HarvestTileDeck* harvestTileDeck;
string* winStr;
bool valid_tile_pos(string pos);
bool valid_building_pos(string pos);
bool is_number(string str);
public:
Game();
~Game();
void initialize();
void placeTilePhase();
void placeBuildingsPhase();
void drawPhase();
void nextTurn();
void ComputeScore();
bool gameDone();
int getRound();
int getActivePlayer();
int getPlayerCount();
vecto
string> getGameBoardStrs();
vecto
vecto
string
getVillagesStrs();
string getRevealedBuildingsStr();
vecto
string> getVillageNames();
string getTrackerStr();
int getHandPlayer();
void printCu
entHand();
string getPhase();
vecto
string> getStatsStrs();
string getWinnerStr();
};
class TurnObserver : public Observer{
public:
TurnObserver();
TurnObserver(Game* g);
~TurnObserver();
void Update();
void display();
private:
Game* _subject;
};
class StatsObserver : public Observer{
public:
StatsObserver();
StatsObserver(Game* g);
~StatsObserver();
void Update();
void display();
private:
Game* _subject;
};
#endif
New Haven/Graph/.gitignore
#Ignore all files inside directory "Code Blocks",
#relative to the location of the .gitignore file (infinite depth)
Code Blocks/**
New Haven/Graph/Graph.cpp
New...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here