File: pacman.cc

package info (click to toggle)
pacman 10-17.2
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 648 kB
  • ctags: 770
  • sloc: cpp: 3,336; sh: 83; makefile: 51
file content (101 lines) | stat: -rw-r--r-- 2,739 bytes parent folder | download | duplicates (10)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include"pacman.h"
#include"types.h"
#include"pac.h"

Pacman::Pacman() {	//constructon
 b=Board::instance();	//get the instance of the board
 g=new G_Pacman;	//a new one
 supertime=0;		//supertime must be set to zero
}

Pacman::~Pacman() {	//destructor
delete g;
}

void Pacman::start() {
 x=PACX; 		//set it's initial coordinates
 y=PACY;
 st=normal;		//set status to normal
 d=still; 		//direction is still
 try_d=right;		//face right
 supertime=0;		//supertime must be set to zero
}

int Pacman::is_dead() {	//is pacman dead?
 return st==dead;
}

void Pacman::die(Gamedata *da) {	//let pacman die a life
 st=dead; 				//status is dead
 da->livesdwn();			//decrement a life
}

int Pacman::getsupertime() {	//get the remaning time pacman is super
return supertime;}

int Pacman::is_super() { 	//is pacman super?
return st==super; }

void Pacman::draw(void) {	//specific draw for pacman
 g->draw(x,y,d,try_d);	//draw pacman direction it was going and was tried
}

GID_TYPE Pacman::getgid() {
return g->getgid(d,try_d);
}

void Pacman::getxy(int *xx,int *yy) {
*xx=x;
*yy=y;
}

int Pacman::go(direction dd,Gamedata *da) {//what direction to try to move it
typ w;					//what's at new coordinates
int i=1;	//this i is returned: it is whether pacman moved or not.
int xx,yy;	//possible next coordinates
if (dd!=none) try_d=d=dd;//if a direction!=none given, set the two directions
if (st==dead) { 	//if pacman died
d=still; 		//then actual moving direction is still 
return 0;		//and return not moved
}
switch (st) {
 case super: {		//if super
  if (supertime) 	//if supertime is > 0
   supertime--; 	//decrement supertime
  else 
   st=normal;   	//if supertime is zero then status is normal
} break;
 case normal: break;
}

next(&xx,&yy,d,x,y);	//compute next coordinates
w=b->what_is(xx,yy);	//what's at new coordinates

switch (w) {		//if it's
 case classSpecialWall: case classWall: //can't move through walls
  { i=0; d=still; } break;
 case classFood: { 
  x=xx; y=yy; 				//set to new coordinates
  b->eat(x,y);				//eat food at board coordinates
  da->foodeat(); 			//let gamedata know a food is eaten
  da->scorepluss(FOODSCORE); 		//increase the score
 } break;
 case classSuperFood: { 
  x=xx; y=yy; 				//set to new coordinates
  b->eat(x,y); 				//eat superfood at board coordinates
  st=super; 				//set status to super
  supertime=SUPERTIME;			//set supertime, too 
 } break; 
 case classBlank: { 
  x=xx; y=yy;  				//set to new coordinates
 } break;
// case BonusLife: { x=xx; y=yy; b->eat(x,y); } break;
// case BonusPoint: { x=xx; y=yy; b->eat(x,y); } break;
 default: /*printf("caseerror\n");*/ break;
}	
//printf("%d\n",d);	   
//printf("%s",w);	   
return i;	//this i is returned: it is whether pacman moved or not.
}