-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpawn.cpp
More file actions
50 lines (43 loc) · 1.13 KB
/
pawn.cpp
File metadata and controls
50 lines (43 loc) · 1.13 KB
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
#include "pawn.h"
pawn::pawn() {
onCreate();
}
pawn::pawn(int x, int y, int Id) {
Point p = {x,y};
onCreate();
setLocation(p);
playerId = Id; // set to which player it belongs......
}
void pawn::onCreate() {
width = boxColSize;
height = boxRowSize;
sprite = new char*[height];
for(int i=0;i<height;i++)
sprite[i] = new char[width];
// create sprite for pawn............
strncpy(sprite[0], "|-------|", width);
strncpy(sprite[1], "| |", width);
strncpy(sprite[2], "| Pawn |", width);
strncpy(sprite[3], "|-------|", width);
}
bool pawn::canMove(Point to) {
int dx = location.x - to.x;
int dy = location.y - to.y;
if(abs(dy)<=2 && (dy!=0) && abs(dx)<=1) { // in reach only......
if(playerId == 1) {
if(dy == 1) // normal move single step........
return true;
// if initial location then only jump twosteps with no digonal
else if(location.y == 6 && abs(dx)==0)
return true;
}
if(playerId == 2) {
if(dy == -1) // normal move........
return true;
else if(location.y == 1 && abs(dx)==0) // initial condition
return true;
}
}
return false;
}
char pawn::getPeiceId() { return 'p'; }