Last active
August 29, 2015 14:06
-
-
Save Lumaio/552b4e3b004c2bcbaadc to your computer and use it in GitHub Desktop.
Shit yes nigga
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
World Created. | |
This is some info | |
This is some MORE info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include "World.h" | |
using namespace std; | |
void info() | |
{ | |
printf("This is some info\n"); | |
} | |
void info2() | |
{ | |
printf("This is some MORE info\n"); | |
} | |
int main() | |
{ | |
World* world = new World(10, 10); | |
world->add_command("info", &info); | |
world->add_command("info2", &info2); | |
world->do_command("info"); | |
world->do_command("info2"); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#ifndef ROOM_H | |
#define ROOM_H | |
class Room | |
{ | |
private: | |
public: | |
Room()=default; | |
~Room()=default; | |
}; | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "World.h" | |
/* Command Methods */ | |
void World::info() | |
{ | |
printf("Width: %i\nHeight: %i\n", width, height); | |
} | |
/* End Cmd Methods*/ | |
World::World(int w, int h) | |
{ | |
width=w; | |
height=h; | |
printf("World Created.\n"); | |
} | |
void World::do_command(std::string command) | |
{ | |
for (int i = 0; i < str_funcs.size(); i++) | |
{ | |
if (command == str_funcs[i]) | |
{ | |
funcs[i](); | |
} | |
} | |
} | |
void World::add_command(std::string cmd, void(*func)()) | |
{ | |
funcs.push_back(func); | |
str_funcs.push_back(cmd); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <stdio.h> | |
#include "Room.h" | |
#ifndef WORLD_H | |
#define WORLD_H | |
class World | |
{ | |
private: | |
// Function Pointer | |
typedef void (*func)(); | |
// World Stats | |
int width; | |
int height; | |
std::vector<std::vector<Room>> world; | |
// Function Vectors | |
std::vector<void(*)()> funcs; | |
std::vector<std::string> str_funcs; | |
// Builtin Commands | |
void info(); | |
public: | |
World(int w, int h); | |
~World()=default; | |
void do_command(std::string command); | |
void add_command(std::string cmd, func); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment