From 1031174ed7446d22b3f5505ff3a4e84135b88cc3 Mon Sep 17 00:00:00 2001 From: tom Date: Mon, 23 Nov 2015 20:34:06 -0600 Subject: refracter --- src/Character.cpp | 68 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 27 deletions(-) (limited to 'src/Character.cpp') 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 men, vector 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 men, vector impassable) @@ -57,3 +33,41 @@ bool Character::check(Location L, vector men, vector impa return true; } + +void Character::wander(vector men, vector 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 men, vector impassable) +{ + vector closed; + vector open; + + + +} -- cgit v1.2.3