Skip to content

Instantly share code, notes, and snippets.

@Lumaio
Last active August 29, 2015 14:06
Show Gist options
  • Save Lumaio/552b4e3b004c2bcbaadc to your computer and use it in GitHub Desktop.
Save Lumaio/552b4e3b004c2bcbaadc to your computer and use it in GitHub Desktop.
Shit yes nigga
World Created.
This is some info
This is some MORE info
#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;
}
#include <iostream>
#include <stdio.h>
#ifndef ROOM_H
#define ROOM_H
class Room
{
private:
public:
Room()=default;
~Room()=default;
};
#endif
#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);
}
#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