Simple TMX Level Generator (no detail)



  • This piece of code I created was designed simply for entertainment purposes and should not be taken seriously.

    #include < iostream >
    #include < fstream >
    #include < string >
    
    using std::string;
    using std::fstream;
    
    class Level {
    protected:
    	enum Status { GOOD = 1, BAD = 2, BUSY = 3 };
    	int level_status;
    	string level_name;
    public:
    	Level(string _name, int _status);
    	virtual ~Level();
    	bool checkAttributes(string& n, int& s) {
    		if (n.empty() || n.substr(n.find_last_of(".") + 1) != "tmx") {
    			std::cerr << ":: [!] Failed to generate level with name '" + n + "'! Try adding '.tmx'!\n";
    			return false;
    		}
    		else {
    			std::cout << ":: [?] File '" + n + "' verifed! Moving onto status verification.\n";
    			this->level_name = n;
    			goto Status;
    		}
    	Status: {
    			if (s < 1 || s > 3) {
    				std::cerr << ":: [!] Failed to generate the file with status of '" + std::to_string(s) + "'!\n";
    				return false;
    			}
    			else {
    				this->level_status = s;
    				std::ofstream outFile(n);
    				std::cout << ":: [?] File '" + n + "' generated with status '" + std::to_string(s) + "' successfully!\n";
    				return true;
    			}
    		}
    	}
    };
    
    Level::Level(string _name, int _status) {
    	this->checkAttributes(_name, _status);
    }
    
    Level::~Level() { 
            delete(this); 
    }
    
    int main(int argc, char const *argv[]) {
            string level = "";
            int status;
    	Level level_01(level, status);
    	
    	std::cin.get();
    	return EXIT_SUCCESS;
    }
    

    Note that there are spaces between angle brackets (at the top), due to the code embed escaping them as potential HTML tags.
    This program checks for two main attributes: a valid file name, with ".tmx" as an extension and a valid (fictitious) level status, between (including) one and three.


Log in to reply