summaryrefslogtreecommitdiff
path: root/src/Character.cpp
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-11-21 15:05:47 -0600
committertom <tom@ground-control>2015-11-21 15:05:47 -0600
commitf198372b1c9f5cccdfbfc6cf57d8716a53be5bc8 (patch)
tree56cec43c262d8c6ccb401f2d278444920295ec43 /src/Character.cpp
parent7f79b2e216617ff74ebd41ac02663b20ef3d0904 (diff)
some cleaning and collision fully implemented
Diffstat (limited to 'src/Character.cpp')
-rw-r--r--src/Character.cpp87
1 files changed, 39 insertions, 48 deletions
diff --git a/src/Character.cpp b/src/Character.cpp
index fd482a9..423a342 100644
--- a/src/Character.cpp
+++ b/src/Character.cpp
@@ -1,19 +1,10 @@
#include "Character.hpp"
-Character::Character(char nSymbol, int nColor, int nRow, int nCol)
+Character::Character(char nSymbol, int nColor, Location L)
{
- symbol = nSymbol;
- row = nRow;
- col = nCol;
+ symbol = nSymbol;
color = nColor;
- l.x = row;
- l.y = col;
-}
-
-void Character::move(Location L)
-{
- l.x = L.x;
- l.y = L.y;
+ l = L;
}
void Character::draw(WINDOW * w)
@@ -22,77 +13,77 @@ void Character::draw(WINDOW * w)
mvwaddch(w,l.x,l.y,symbol);
}
-int Character::getRow()
-{
- return row;
-}
-
-int Character::getCol()
-{
- return col;
-}
-
-char Character::getSymbol()
-{
- return symbol;
-}
-
-bool Character::action(vector <Location> occupied)
+Location Character::action(vector <Location> occupied)
{
if(order == "wander")
{
- Location L;
+ Location Lo;
int r = rand()%15+1;
if(r==1)
{
- L.x = l.x+1;
- L.y = l.y;
+ Lo.x = l.x+1;
+ Lo.y = l.y;
}
else if(r==2)
{
- L.x = l.x-1;
- L.y = l.y;
+ Lo.x = l.x-1;
+ Lo.y = l.y;
}
else if(r==3)
{
- L.x = l.x; L.y = l.y+1;
+ Lo.x = l.x;
+ Lo.y = l.y+1;
}
else if(r==4)
{
- L.x = l.x; L.y = l.y-1;
+ Lo.x = l.x;
+ Lo.y = l.y-1;
}
else if(r==5)
{
- L.x = l.x+1; L.y = l.y+1;
+ Lo.x = l.x+1;
+ Lo.y = l.y+1;
}
else if(r==6)
{
- L.x = l.x-1; L.y = l.y-1;
+ Lo.x = l.x-1;
+ Lo.y = l.y-1;
}
else if(r==7)
{
- L.x = l.x+1; L.y = l.y-1;
+ Lo.x = l.x+1;
+ Lo.y = l.y-1;
}
else if(r==8)
- { L.x = l.x-1; L.y = l.y+1;
-
+ {
+ Lo.x = l.x-1;
+ Lo.y = l.y+1;
}
else
- return false;
+ {
+ Lo = l;
+ }
+
+ //move(Lo);
- if(check(L,occupied))
- move(L);
+ if(check(Lo,occupied))
+ {
+ move(Lo);
+ return Lo;
+ }
else
- return false;
-
- return true;
+ return l;
}
}
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;
+ {
+ if(L.x == occupied[i].x && L.y == occupied[i].y)
+ {
+ return false;
+ }
+ }
return true;
}