summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-11-23 20:34:06 -0600
committertom <tom@ground-control>2015-11-23 20:34:06 -0600
commit1031174ed7446d22b3f5505ff3a4e84135b88cc3 (patch)
treeaf3a4ec1f990093017927eebb4a21a145835c6ca
parent9d9c1d29dbcd802c89641b70b5574361e775c0e4 (diff)
refracter
-rw-r--r--inc/Character.hpp5
-rw-r--r--src/Character.cpp68
2 files changed, 45 insertions, 28 deletions
diff --git a/inc/Character.hpp b/inc/Character.hpp
index a1fc7b7..67fcfd2 100644
--- a/inc/Character.hpp
+++ b/inc/Character.hpp
@@ -16,12 +16,15 @@ class Character
void draw(WINDOW * w);
void action(vector <Character> men, vector <Location> impassable);
bool check(Location L, vector <Character> men, vector <Location> impassable);
+ void astar(vector <Character> men, vector <Location> impassable);
+ void wander(vector <Character> men, vector <Location> impassable);
Location getLocation(){return l;}
char getSymbol(){return symbol;}
private:
string order = "wander";
- Location l;
+ Location l; // current location
+ Location d; // destination
char symbol;
int row;
int col;
diff --git a/src/Character.cpp b/src/Character.cpp
index 24ed475..8102b4c 100644
--- a/src/Character.cpp
+++ b/src/Character.cpp
@@ -16,33 +16,9 @@ void Character::draw(WINDOW * w)
void Character::action(vector <Character> men, vector <Location> impassable)
{
if(order == "wander")
- {
- int r = rand()%15+1;
- bool stay = false;
- Location L;
- if(r==1)
- L = Location(l.x+1,l.y);
- else if(r==2)
- L = Location(l.x-1,l.y);
- else if(r==3)
- L = Location(l.x,l.y+1);
- else if(r==4)
- L = Location(l.x,l.y-1);
- else if(r==5)
- L = Location(l.x+1,l.x+1);
- else if(r==6)
- L = Location(l.x-1,l.y-1);
- else if(r==7)
- L = Location(l.x+1,l.y-1);
- else if(r==8)
- L = Location(l.x-1,l.y+1);
- else
- stay = true;
-
- if (!stay)
- if(check(L,men,impassable))
- move(L);
- }
+ wander(men, impassable);
+ else if(order == "move")
+ astar(men,impassable);
}
bool Character::check(Location L, vector <Character> men, vector <Location> impassable)
@@ -57,3 +33,41 @@ bool Character::check(Location L, vector <Character> men, vector <Location> impa
return true;
}
+
+void Character::wander(vector <Character> men, vector <Location> impassable)
+{
+ int r = rand()%15+1;
+ bool stay = false;
+ Location L;
+ if(r==1)
+ L = Location(l.x+1,l.y);
+ else if(r==2)
+ L = Location(l.x-1,l.y);
+ else if(r==3)
+ L = Location(l.x,l.y+1);
+ else if(r==4)
+ L = Location(l.x,l.y-1);
+ else if(r==5)
+ L = Location(l.x+1,l.x+1);
+ else if(r==6)
+ L = Location(l.x-1,l.y-1);
+ else if(r==7)
+ L = Location(l.x+1,l.y-1);
+ else if(r==8)
+ L = Location(l.x-1,l.y+1);
+ else
+ stay = true;
+
+ if (!stay)
+ if(check(L,men,impassable))
+ move(L);
+}
+
+void Character::astar(vector <Character> men, vector <Location> impassable)
+{
+ vector <Location> closed;
+ vector <Location> open;
+
+
+
+}