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
|
#pragma once
#include "places.h"
#include "dice.h"
#include <vector>
#include <initializer_list>
#include <iostream>
// Represents the Monopoly board
class Board {
std::vector<Places> places { // Specifies the details of each place on the board
{Go, new cGo},
{OldKentRoad, new cProp(2, 10, 30, 90, 160, 250, 60, 50, 50, 30), {WhitechapelRoad}},
{CommunityChest1, new cComm},
{WhitechapelRoad,new cProp(4, 20, 60, 180, 320, 450, 60, 50, 50, 30), {OldKentRoad}},
{IncomeTax, new cTax(200)},
{KingscrossStation, new cStation(25, 50, 100, 200, 200, 100), {MaryleboneStation, FenchurchStreetStation, LiverpoolStreetStation}},
{TheAngelIslington, new cProp(6, 30, 90, 270, 400, 550, 100, 50, 50, 50), {EustonRoad, PentovilleRoad}},
{Chance1, new cChance},
{EustonRoad, new cProp(6, 30, 90, 270, 400, 550, 100, 50, 50, 50), {TheAngelIslington, PentovilleRoad}},
{PentovilleRoad, new cProp(8, 40, 100, 300, 450, 600, 100, 50, 50, 60), {TheAngelIslington, EustonRoad}},
{Jail, new cJail},
{PallMall, new cProp(10, 50, 150, 450, 625, 750, 140, 100, 100, 70)},
{ElecticCompany, new cUtility(150, 75)},
{Whitehall, new cProp(10, 50, 150, 450, 625, 750, 140, 100, 100, 70)},
{NorthumberlandAvenue, new cProp(12, 60, 180, 500, 700, 900, 160, 100, 100, 80)},
{MaryleboneStation, new cStation(25, 50, 100, 200, 200, 100)},
{BowStreet, new cProp(14, 70, 200, 550, 750, 950, 180, 100, 100, 90)},
{CommunityChest2, new cComm},
{MarlboroughStreet, new cProp(14, 70, 200, 550, 750, 950, 180, 100, 100, 90)},
{VineStreet, new cProp(16, 80, 220, 600, 800, 1000, 200, 100, 100, 100)},
{Freeparking, new cParking},
{Strand, new cProp(18, 90, 250, 700, 875, 1050, 220, 150, 150, 110)},
{Chance2, new cChance},
{FleetStreet, new cProp(18, 90, 250, 700, 875, 1050, 220, 150, 150, 110)},
{TrafalgarSquare, new cProp(20, 100, 300, 750, 925, 1100, 240, 150, 150, 120)},
{FenchurchStreetStation, new cStation(25, 50, 100, 200, 200, 100)},
{LeicesterSquare, new cProp(22, 110, 330, 800, 975, 1150, 260, 150, 150, 130)},
{CoventryStreet, new cProp(22, 110, 330, 800, 975, 1150, 260, 150, 150, 130)},
{WaterWorks, new cUtility(150, 75)},
{Picadilly, new cProp(22, 120, 360, 850, 1025, 1200, 280, 150, 150, 140)},
{GoToJail, new cGoJail},
{RegentSreet, new cProp(26, 130, 390, 900, 1100, 1275, 300, 200, 200, 150)},
{OxfordStreet, new cProp(26, 130, 390, 900, 1100, 1275, 300, 200, 200, 150)},
{CommunityChest3, new cComm},
{BondStreet, new cProp(28, 150, 450, 1000, 1200, 1400, 320, 200, 200, 160)},
{LiverpoolStreetStation, new cStation(25, 50, 100, 200, 200, 100)},
{Chance3, new cChance},
{ParkLane, new cProp(35, 175, 500, 1100, 1300, 1500, 350, 200, 200, 175)},
{SuperTax, new cTax(100)},
{Mayfair, new cProp(50, 200, 600, 1400, 1700, 2000, 400, 200, 200, 200)}
};
cDice dic; // Dice to use
public:
Board() {
// Set pointer for each place to Board class
for (auto& p : places)
p.setBoard(this);
}
~Board() {
for (auto& p : places)
delete p.getPlaceC();
}
// Can't copy or assign Board class
Board(const Board&) = delete;
Board& operator=(const Board&) = delete;
// Number of board elements
unsigned size() const noexcept {
return unsigned(places.size());
}
// Display the board
void display() noexcept {
for (auto& b : places) {
for (const auto& ps : b.getPlayers())
std::cout << sNames[ps] << " ";
b.getPlaceC()->display(b);
std::cout << '\n';
}
std::cout << '\n';
}
// Get specified place
Places& getPlace(unsigned pos) noexcept {
return places[pos];
}
// Shake the dice
Dice shake() noexcept {
return dic.shake();
}
// Release owned places
void release(Symbols owner) {
for (auto& b : places)
if (b.getOwner() == owner)
b.setOwner(None);
}
};
|