summaryrefslogtreecommitdiff
path: root/src/Character.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Character.cpp')
-rw-r--r--src/Character.cpp70
1 files changed, 66 insertions, 4 deletions
diff --git a/src/Character.cpp b/src/Character.cpp
index 7f12035..fd482a9 100644
--- a/src/Character.cpp
+++ b/src/Character.cpp
@@ -6,18 +6,20 @@ Character::Character(char nSymbol, int nColor, int nRow, int nCol)
row = nRow;
col = nCol;
color = nColor;
+ l.x = row;
+ l.y = col;
}
-void Character::move(int nRow, int nCol)
+void Character::move(Location L)
{
- row = nRow;
- col = nCol;
+ l.x = L.x;
+ l.y = L.y;
}
void Character::draw(WINDOW * w)
{
wattron(w,COLOR_PAIR(color));
- mvwaddch(w,row,col,symbol);
+ mvwaddch(w,l.x,l.y,symbol);
}
int Character::getRow()
@@ -34,3 +36,63 @@ char Character::getSymbol()
{
return symbol;
}
+
+bool Character::action(vector <Location> occupied)
+{
+ if(order == "wander")
+ {
+ Location L;
+ int r = rand()%15+1;
+ if(r==1)
+ {
+ L.x = l.x+1;
+ L.y = l.y;
+ }
+ else if(r==2)
+ {
+ L.x = l.x-1;
+ L.y = l.y;
+ }
+ else if(r==3)
+ {
+ L.x = l.x; L.y = l.y+1;
+ }
+ else if(r==4)
+ {
+ L.x = l.x; L.y = l.y-1;
+ }
+ else if(r==5)
+ {
+ L.x = l.x+1; L.y = l.y+1;
+ }
+ else if(r==6)
+ {
+ L.x = l.x-1; L.y = l.y-1;
+ }
+ else if(r==7)
+ {
+ L.x = l.x+1; L.y = l.y-1;
+ }
+ else if(r==8)
+ { L.x = l.x-1; L.y = l.y+1;
+
+ }
+ else
+ return false;
+
+ if(check(L,occupied))
+ move(L);
+ else
+ return false;
+
+ return true;
+ }
+}
+
+bool Character::check(Location L, vector <Location> occupied)
+{
+ for(int i = 0; i < 10; i++)
+ if(l.x == occupied[i].x && l.y == occupied[i].y)
+ return true;
+ return true;
+}