1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <stdlib.h>
#include"gamedata.h"
#include"board.h"
#include"pac.h"
Gamedata* Gamedata::_instance=0;
long int Gamedata::hiscore=0;
long int Gamedata::score=0;
long int Gamedata::bonus=0;
int Gamedata::level=0;
int Gamedata::boardlevel=0;
int Gamedata::lives=0;
int Gamedata::eats=0;
Gamedata::Gamedata() { setlevel(0); lives=0; hiscore=0; score=0; bonus=0; eats=foods;}
Gamedata* Gamedata::instance() { //returns the pointer to the instance
if (_instance==0)
_instance=new Gamedata;
return _instance;
}
//initializing of gamedata before game starts
void Gamedata::start(void) { level=1; setboardlevel(); lives=3; score=0; bonus=5000; eats=foods;}
//initializing of gamedata after completed level
void Gamedata::start2(void) { levelup();
bonus=5000; eats=foods;}
void Gamedata::scorepluss(int sc) {score+=sc; if (score>hiscore) hiscore=score;}
void Gamedata::bondwn() {if (bonus) bonus-=5;}
void Gamedata::levelup() {level++;
setboardlevel();
}
void Gamedata::livesdwn() {if (lives) lives--;}
void Gamedata::livesup() {lives++;}
long int Gamedata::getscore() {return score;}
long int Gamedata::gethiscore() {return hiscore;}
long int Gamedata::getbonus() {return bonus;}
int Gamedata::getlives() {return lives;}
int Gamedata::getlevel() {return level;}
void Gamedata::resetscore() {score=0;}
void Gamedata::setbonus(long int b) {bonus=b;}
void Gamedata::setlevel(int l) {level=l; setboardlevel();}
void Gamedata::setboardlevel() {
if (level>LEVELS) boardlevel=1+(random()%LEVELS);
else boardlevel=level;
}
int Gamedata::getboardlevel() {
return boardlevel;
}
void Gamedata::setlives(int l) {lives=l;}
void Gamedata::reseteats() {eats=foods; }
int Gamedata::eatenall() {return !eats; }
void Gamedata::foodeat() {if (eats) eats--; else pacexit("food"); }
|