So, I have 5 header files with some stuff and an empty cpp file, I have various classes that work together with some missing pieces:
So far I have:
Interpreter: Takes input from the user via string, and sends the command to the right engine part for processing, well, perhaps more ideally the proper game component, which aren't in existence yet.
Object: Basic object class, courtesy goes to Bubba for the suggestion
Object Manager: container for objects
Database: handles the initialization of object managers and the creation of objects, as well as population of the managers..
Menu Object: Subclass to Object, the Menu objects are designed to be a sort of linked list menu system, it should provide easy creation of menu's and lots of on the fly menu tweaking, such as options that aren't available at a certain time.
And the code:
Interpreter:
Object/Object Manager:Code:#ifndef INTERPRETER_H #define INTERPRETER_H #include <string> #include <map> #include "Database.h" #include <iostream> class Interpreter { public: typedef std::map< std::string, std::string > Command_List; virtual void Navigate_Menu(std::string Command) { Command_List::iterator it = Commands.find(Command); if(it == Commands.end()) { std::cout << "Fail" << std::endl; } //if it is a recognized command, we delete //the current list of valid commands //then //We make a new list of valid coimmands by //inserting command strings into valid commands //by looping through the selected menu's //children and getting their Selection string } private: Command_List Commands; }; #endif
Database:Code:#ifndef OBJECT_H #define OBJECT_H #pragma warning(disable: 4786) #pragma warning(disable: 64) #include <vector> #include <map> #include <string> #include <boost\shared_ptr.hpp> #include <boost\weak_ptr.hpp> #include <boost\smart_ptr.hpp> #include <iostream> class CObject { public: virtual void Create() {} virtual void Access() {} virtual void Delete() {delete this;} private: virtual void Save_to_Disk(std::string Filename) {} virtual void Read_File(std::string Filename) {} }; class Object_Manager { public: Object_Manager() {}; ~Object_Manager() {}; typedef boost::shared_ptr<CObject> Object_Ptr; typedef boost::weak_ptr<CObject> Object_Observer; typedef std::map< std::string, Object_Ptr > Object_Map; void Add_Object(const std::string & name, CObject * pObject) { Object_Ptr Raw_Object(pObject); mObjects.insert(std::make_pair(name, Raw_Object)); } Object_Observer Request_Object(const std::string & name) { Object_Map::iterator it = mObjects.find(name); if (it == mObjects.end()) { std::cout << "Internal program error, " << name << " does not exist!" << std::endl; } else { return Object_Observer(it->second); } } void Request_Object_Removal(const std::string & name) { Object_Map::iterator it = mObjects.find(name); if (it != mObjects.end()) { mObjects.erase(it); } } private: Object_Map mObjects; }; #endif
Most of the code is largely incomplete, but it shows you the basic concept of the menu system at least. I want the process of events to move like so:Code:#ifndef DATABASE_H #define DATABASE_H #include "Menu_Object.h" class Database { public: }; #endif
Input->Interpreter->Database->Menu_Manager->put game component here->Output
Constructive criticism encouraged
I'm currently working on object serialization so I can save my objects to files and load them later, this will be perfect for a menu system I think. I'll post updates of my progress in this area, because it is crucial to creating menu objects on a massive scale with all the right stuff, as well as other objects I may have.



LinkBack URL
About LinkBacks
.




