also fyi i'm a beginnerC++ Programming = How do you jump from main function to another function to switch storyline?
Hm....
Get first think:
Hirarch:
/*
input -%26gt; event handler -%26gt; action
action :: input -%26gt; event handler -%26gt; action
*/
Example:
1. create eventhandler:
class eventhandler{
public:
friend story;
friend action;
int handler;
eventhandler(){handler=0;}
~eventhandler(){}
int operator!(){
return !(handler==255);}//exit game if message=255
void run(){
switch(handler){
case 1: //%26lt;switch to story%26gt;
break;
case 2: //%26lt;switch to another action%26gt;
break;
default:;
}
}
};
2. Create action, ex: story and action
class story:public eventhandler{
public:
story(){handler=1;}
~story(){handler=0;}
void run(){}
};
class action:public eventhandler{
public:
action(){ handler=2; }
~action(){ handler=0; }
void run(){}
};
void main(){
eventhandler mygame;
do{ mygame.run();}
while (!mygame);
return; }C++ Programming = How do you jump from main function to another function to switch storyline?
You don't ';jump'; - you call a function, e.g.
static void chapter1(void)
{
....//
}
static void chapter2(void)
{
....//
}
int main()
{
....chapter1();
....chapter2();
....return 0;
}
No comments:
Post a Comment