Well now what!

I have gone and done it this time. I spent the past few weeks working on this game and now I don't know how to finish it.

The game has these tanks that drive and shoot.

I have functions that move the tanks. Like,

void driveforward() {...} and
void turnright() {...}.

Up till now, pressing on the keyboard will trigger a function call. Arrow keys steer and spacebar shoots. It all works fine, but I wanted to remove the keyboard controls from the game. This game is about programming your tank to do battle.

I want the players to choose in advance the order of function calls and then when the game starts the tanks go at it.

Is there a way to make a vector of function calls? How would I do this? Thanks for any help.
Perhaps you could make a vector of keystrokes and use that instead of actual keyboard input.
Another way is perhaps using a queue of std::function. but they'd need to have the same return type and parameters.
Is there a way to make a vector of function calls?


1
2
3
4
5
6
7
8
9
10
11
12
13
#include <vector>
using namespace std;

void some_func ();

typedef void (*func_t)();

int main ()
{   vector<func_t>	vfunc;	//  Vector of function pointers

    vfunc.push_back (some_func);	//  Add a function
    vfunc[0] ();			// Calls some_func
}

Last edited on
Wow anon, that is pretty code.

That looks a lot neater than what I was trying.

I was making a vector of ints and passing them into a switch statement.

Thanks.
You can also use a std::vector<std::function<void()>>
It is preferable to use vector of function object as naraku9333 suggested instead of raw function pointer: you can store normal functions, member functions, lambdas, binded functions and functors here easily.
hmmm... thanks everyone.
Topic archived. No new replies allowed.