# # # 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