#ifndef CITY_H #define CITY_H // Programmer: Brett Weiland // Date: 4/30/23 // File: city.h // Assignment: SP-B-finalProject // Purpose: Contains the city object, // which acts as a game engine for gameObject based objects to interact with eachother. // Also containts game over conditions. #include #include #include #include "gameObject.h" #include "coordinate.h" #include "npc.h" #include "cop.h" #include "robber.h" #include "jewl.h" class city { private: //inventory for NPCs are relient on this being 47 unless modified. //Please see npc.h for explaination. static const unsigned int JEWL_COUNT = 47; static const unsigned int ROBBERS_COUNT = 4; static const unsigned int COPS_COUNT = 1; const unsigned int ROBBERS_GREEDY = 2; //must be lower then JEWL_COUNT //map dimentions static const int MAP_WIDTH = 10; static const int MAP_HEIGHT = 10; //used for keeping track of which jewls are free outside of map_ptr; //useful for finding random free jewls unsigned int jewls_available_qty = JEWL_COUNT; jewl *jewls_available[JEWL_COUNT]; //this array of gameObject pointers is useful for looking up objects on location, //as well as keep track of where objects are in a sane way. //If objects are stacked, they are linked in a doubly linked list for that cell. //If there are no objects, the cell is a null pointer. gameObject *map_ptr[MAP_HEIGHT][MAP_WIDTH] = {NULL}; char rendered_map[MAP_HEIGHT][MAP_WIDTH]; //map as seen by humans. use for display only static unsigned int rounds_taken; //win conditions for robbers. //robbers win if they collectively get more then ROBBER_WIN_VALUE or uncaught in MAX_ROUNDS const unsigned int ROBBER_WIN_VALUE; //if robber gets more money then this, they win const unsigned int MAX_ROUNDS; //if robbers aren't caught b //gameObjects cop cops[COPS_COUNT]; robber robbers[ROBBERS_COUNT]; jewl jewls[JEWL_COUNT]; //Desc: gets a random UNOCUPIED location in the map. //Pre: map_ptr is updated with objects to avoid stacking. //Post: random unocupied coordinate within bounds returned coordinate randomLocation() const; //Desc: uses map_ptr to generate a 2d array of characters, rendered_map. // when gameObjects are stacked, the first one on the linked list is printed. // checks the gameObject's get_icon() function. //Pre: map_ptr updated //Post: rendered_map updated void renderMap(); //Desc: tests if npc derived class is movable, and calls its move() function. // updates map_ptr accordingly. //Pre: valid npc passed //Post: character is moved, map_ptr updated void moveNPC(npc &character); //Desc: tests to see if all robbers arrested for game over condition. //Pre: none //Post: returns true if all robbers arrested bool allRobbersArrested() const; public: //used to communicate if/why the game has stopped running. enum class CITY_STATUS { CONTINUE, COPS_WIN, ROBBERS_MAX_VAL, ROUNDS_DEPLETED }; //Desc: city constructor //Pre: win conditions passed (see docs in private section of this object) //Post: city is constructed along with all of its gameObjects city(const unsigned int robber_win_value, const unsigned int rounds); //Desc: operate city for a single turn. //Pre: none //Post: CITY_STATUS describing win condition or nothing returned CITY_STATUS runTurn(); //Desc: Adds gameObject to map_ptr location. // order in doubly linked list based on gameObject.get_drawPriority(). //Pre: gameObject with updated coordinates passed //Post: gameObject added to map_ptr void addMapMarker(gameObject &item); //Desc: removes gameObject from map_ptr location. //Pre: coordinates of gameObjects reflect where it is on the map_ptr //Post: gameObject removed from that location on map_ptr void delMapMarker(gameObject &item); //Desc: prints rendered_map. //Pre: rendered_map is updated using renderMap() //Post: map is printed void printMap() const; //Desc: finds top gameObject in location. // Other gameObjects at that location can be found using the top's linked list. //Pre: coordinate for location to check is passed //Post: pointer to top gameoOject returned or NULL if nothing resides that space gameObject *findObjsByLocation(const coordinate loc); //Desc: gets a random directoin while avoiding borders. //Pre: coordinates to get direction from passed //Post: random direction is returned direction::TYPE randomDirection(const coordinate &scanner) const; //Desc: gets direction to nearest cop. //Pre: one cop must exist. //Post: direction to nearest cop returned. direction::TYPE nearestCopDirection(const coordinate &scanner) const; //Desc: gets the direction to any jewl in jewls_available. //Pre: one unpicked jewl must exist. //Post: direction to any random unpicked jewl returned. // returns random direction if no jewl found. direction::TYPE directionToAnyJewl(const coordinate &scanner) const; //Desc: unarrests every robber. //Pre: none //Post: all robbers freed void freeAllRobbers(); //Desc: adds jewl to list of available/unpicked jewls. //Pre: jewl passed. this function not responsible for adding jewl to map //Post: jewl is added to list void markJewlAvailable(jewl &item); //Desc: removes jewl from list of unpicked jewls. //Pre: jewl passed. this function not responsible for removing jewl from map //Post: jewl is removed from list void markJewlTaken(jewl &item); //Desc: prints summary of NPCs. //Pre: none //Post: prints NPC info void summarize() const; }; #endif