11-13 Game Programming Behavior patterns

Source: Internet
Author: User

# # # behavioral pattern#### interpreter Patternstring-Code InstructionSet: Provides basic operationsVirtualMachine : Execution instruction Front-end: Generate more efficient bytecode " 'voidSethealth (intWizardintamount);voidSetwisdom (intWizardintamount);voidSetagility (intWizardintamount);voidPlaySound (intsoundid);voidSpawnparticles (intparticletype);enuminstruction{Inst_set_health=0x00, Inst_set_wisdom=0x01, Inst_set_agility=0x02, Inst_play_sound=0x03, Inst_spawn_particles=0x04};Switch(instruction) { CaseInst_set_health:sethealth (0, -);  Break;  CaseInst_set_wisdom:setwisdom (0, -);  Break;  Caseinst_set_agility:setagility (0, -);  Break;  CaseInst_play_sound:playsound (Sound_bang);  Break;  Caseinst_spawn_particles:spawnparticles (particle_flame);  Break;} # # # Stack Matchineclassvm{ Public: VM (): Stacksize_ (0)  {}  Private:  voidPushintvalue) {    //Check for stack overflow.ASSERT (Stacksize_ <max_stack); Stack_[stacksize_++] =value; }  intpop () {//Make sure the stack isn ' t empty.ASSERT (Stacksize_ >0); returnstack_[--Stacksize_]; }Private:  Static Const intMax_stack = -; intStacksize_; intstack_[max_stack];}; Caseinst_add:{intb =pop (); intA =pop (); Push (a+b);  Break;} ' # # # # Subclass Sandbox class using the method provided by the parent class # # # # # # # # # # #classmonster{}classDrogon:monster {}classtroll:monster {} VSclassBreed {}classmonster{ Publicbreed breed;} Monster Drogon=Newmonster{breed=NewBreed ("Drogon")}; Breed Read Config//Benefits//Monster breed can be arbitrarily modified to configure the spawn mobs without recompiling the code```

11-13 Game Programming Behavior patterns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.