From afa02f645056c5823b0d8a29d37c1ff10aedce7a Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Feb 2024 21:53:44 -0600 Subject: init --- npc.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 npc.h (limited to 'npc.h') diff --git a/npc.h b/npc.h new file mode 100644 index 0000000..c45d971 --- /dev/null +++ b/npc.h @@ -0,0 +1,83 @@ +#ifndef NPC_H +#define NPC_H + +// Programmer: Brett Weiland +// Date: 4/30/23 +// File: npc.h +// Assignment: SP-B-finalProject +// Purpose: contains the abstract base class for npcs. +// npcs are gameObjects that move, and consist of the cop and robber. + +#include +#include + +#include "gameObject.h" +#include "coordinate.h" + +template +class npc : public gameObject { + public: + //Desc: npc initilizer + //Pre: none + //Post: npc initilized, ID is set and static ID counter incrimented + npc(); + + //Desc: the move function for the NPC. Called once for every NPC each round + //Pre: none + //Post: NPC's actions for that round will be taken, unless another npc interacts with it + virtual void move() = 0; + + //Desc: called when NPC is arrested. returns inventory pointer to caller, + // cop uses this to record items in their own stash. + //Pre: none + //Post: npc is no longer active (can't move), more behavior is defined by cop arrest() function + T **getArrested(); + + //Desc: gets value of all items in inventory + //Pre: inventory must have pointers to items with value() function or NULL where there are none + //Post: total value of al objects in inventory returned + unsigned int get_inventoryValue() const; + + //getters and setters + int get_id() const; + bool is_active() const; //false if arrested + void free(); //sets active to true + unsigned int get_inventoryQty() const; + protected: + /** + IMPORTAINT + with the schools -pedantic-errors option, there seemed to be no way to declare + a static array of any size other then a static constant type, which requires initilizatoin + in the class at compile time. + + I could use preprocessor directives, + but I figured I should stay away from for my grade them due to never seeing them in class. + I could have also used a dynamic array, but we have not been taught new/delete yet. + + Dynmaic arrays are great, I would have allowed them, they aren't too difficult. + You would just need to learn destructors. + **/ + static const std::size_t INVENTORY_SIZE = 47; // MUST BE SET TO CITY JEWL COUNT <--- + + //inventory size shold be set to jewl count to ensure any gameObject has enough inventory space. + T *inventory[INVENTORY_SIZE] = {NULL}; + + //number of items in inventory + unsigned int inventory_qty = 0; + int id; + + //false if we should be on the map, but shouldn't be allowed to move. + //Used when robber is arrested + bool active = true; + + private: + static int id_counter; //ensures the next constructed ID is one higher then ours +}; + +template int npc::id_counter = 1; + + +#include "npc.hpp" + + +#endif -- cgit v1.2.3