Thursday, December 24, 2009

C++ Programming = How do you jump from main function to another function to switch storyline?

ok so i had a solid introduction to my game in my main program. I want to jump to another function like story1() from somewhere in my main. How do I do that? I tried labels but it didn't work.





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;


}
  • powder
  • oil offshore
  • oil weight
  • petroleum oil
  • No comments:

    Post a Comment