In the "Pacman" game, there are 3 different types of enemies planned.
· Loose type: Will not look back until it touches the wall
· Guard type: When the enemy and the protagonist "Big Mouth" in the same row or the same column will be alerted to close to the big mouth.
· Disturbing: Constantly approaching the big mouth.
These three enemies are implemented using the following functions:
Ai ai handles void redone::makedecision (bool b) {int i = rand (); if (b)//Hit the wall, change direction {//counterclockwise if (i% 4 = = 0) {tw = up? twcommand = LE Ft:twcommand = up;} else if (i% 3 = = 0) {tw = down? twcommand = Right:twcommand = down;} else if (i% 2 = = 0) {tw = right? twcommand = Up:twcommand = right;} ELSE{TW = left? twcommand = Down:twcommand = left;} return;}} void Blueone::makedecision (bool b) {const int DR = This->drow-player->getrow (); const int DA = THIS->DARRAY-PLA Yer->getarray (); if (!b&&dr = = 0) {if (DA <= blue_alert&&da > 0) {twcommand = Left;return;} if (Da < 0 && da >=-blue_alert) {twcommand = Right;return;}} if (!b&&da = = 0) {if (DR <= blue_alert&&dr > 0) {twcommand = Up;return;} if (Dr < 0 && Dr >=-blue_alert) {twcommand = Down;return;}} Redone::makedecision (b);} void Yellowone::makedecision (bool b) {const int DR = This->drow-player->getrow (); const int DA = This->darray-p Layer->getarray (); if (!b) {if (Dr*dr > Da*da) {if (DA > 0) {twcommand = Left;return;} else if (DA < 0) {Twcommand = Right;return;}} Else{if (dr>0) {twcommand = Up;return;} if (DR < 0) {Twcommand = Down;return;}}} Redone::makedecision (b);}
In the Enermy class, a function is used to implement the AI method:
void virtual Makedecision (bool b) = 0; AI implementations
@ Mayuko
Pacman Development-The behavior of the enemy