home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h> // rand()
- #include "game.h"
- #include "cfighter.h"
-
- const int DIE_SIZE = 10;
-
- void ComputerFighter::configure(int s)
- {
- request_timer_cue(SPEED,(callback)&ComputerFighter::on_timer);
-
- set_side(s);
- Fighter::initialize();
- }
-
- void ComputerFighter::on_timer()
- {
- if (getmode()!=WAIT) return;
-
- int die=rand()%DIE_SIZE;
- switch (die)
- {
- case 0:
- punch();
- break;
- case 1:
- kick();
- break;
- case 2:
- block();
- break;
- case 3:
- move_closer();
- break;
- case 4:
- move_closer();
- break;
- case 5:
- move_closer();
- break;
- case 6:
- move_closer();
- break;
- case 7:
- move_closer();
- break;
- case 8:
- move_closer();
- break;
- }
- }
-
- void ComputerFighter::move_closer()
- {
- int ox=opponent->getx();
- if (get_side()==LEFTGUY)
- {
- if (ox>getx())
- Fighter::right();
- }
- else
- {
- if (getx()>ox)
- Fighter::left();
- }
- }
-