//STARTSOLUTION #include #include #include //#include "battlemap.h" using namespace std; class GameObject { public: GameObject(string const& name, string const& description): name{name}, description{description} {} string get_name() { return name; } private: string name; string description; }; class BattleMap { public: BattleMap(string const& name): name{name}, squares(5) {} void put_object(GameObject const& o, char square) { squares[char_to_index(square)].push_back(o); } void print(ostream& os = cout) const { string chars{"abcde"}; os << name << ":\n"; for( auto c: chars ) { os << "Square " << c << "\n"; for( auto o: squares.at(char_to_index(c)) ) { os << o.get_name() << " "; } os << '\n' << endl; } } private: string name; vector> squares; int char_to_index(char ch) const { string chars{"abcdef"}; int index{0}; for( auto c: chars ) { if(c == ch) { return index; } ++index; } return 0; } }; //ENDSOLUTION int main() { BattleMap battleMap{"Map 1"}; battleMap.put_object(GameObject{"Bush", "A terrain feature you can hide in"}, 'a'); battleMap.put_object(GameObject{"Table", "A terrain feature you can stand on"}, 'b'); battleMap.put_object(GameObject{"Orc", "An enemy combatant"}, 'b'); battleMap.put_object(GameObject{"Legolas", "Mirkwood hero character"}, 'a'); battleMap.put_object(GameObject{"Fireplace", "A terrain feature that burns you"}, 'a'); battleMap.put_object(GameObject{"Bush", "A terrain feature you can hide in"}, 'c'); battleMap.put_object(GameObject{"Bush", "A terrain feature you can hide in"}, 'd'); battleMap.put_object(GameObject{"Bush", "A terrain feature you can hide in"}, 'e'); battleMap.print(); }