diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Character.cpp | 62 | ||||
-rw-r--r-- | src/Frame.cpp | 42 | ||||
-rw-r--r-- | src/List.cpp | 7 | ||||
-rw-r--r-- | src/main.cpp | 7 |
4 files changed, 62 insertions, 56 deletions
diff --git a/src/Character.cpp b/src/Character.cpp index d5f8bc0..24ed475 100644 --- a/src/Character.cpp +++ b/src/Character.cpp @@ -13,65 +13,47 @@ void Character::draw(WINDOW * w) mvwaddch(w,l.x,l.y,symbol); } -void Character::action(vector <Character> men) +void Character::action(vector <Character> men, vector <Location> impassable) { if(order == "wander") - { - Location Lo; + { int r = rand()%15+1; + bool stay = false; + Location L; if(r==1) - { - Lo.x = l.x+1; - Lo.y = l.y; - } + L = Location(l.x+1,l.y); else if(r==2) - { - Lo.x = l.x-1; - Lo.y = l.y; - } + L = Location(l.x-1,l.y); else if(r==3) - { - Lo.x = l.x; - Lo.y = l.y+1; - } + L = Location(l.x,l.y+1); else if(r==4) - { - Lo.x = l.x; - Lo.y = l.y-1; - } + L = Location(l.x,l.y-1); else if(r==5) - { - Lo.x = l.x+1; - Lo.y = l.y+1; - } + L = Location(l.x+1,l.x+1); else if(r==6) - { - Lo.x = l.x-1; - Lo.y = l.y-1; - } + L = Location(l.x-1,l.y-1); else if(r==7) - { - Lo.x = l.x+1; - Lo.y = l.y-1; - } + L = Location(l.x+1,l.y-1); else if(r==8) - { - Lo.x = l.x-1; - Lo.y = l.y+1; - } + L = Location(l.x-1,l.y+1); else - Lo = l; + stay = true; - if(check(Lo,men)) - move(Lo); + if (!stay) + if(check(L,men,impassable)) + move(L); } } -bool Character::check(Location L, vector <Character> men) +bool Character::check(Location L, vector <Character> men, vector <Location> impassable) { for(int i = 0; i < men.size(); i++) if(L.x == men[i].getLocation().x && L.y == men[i].getLocation().y) return false; - + + for(int i = 0; i < impassable.size(); i++) + if(L.x == impassable[i].x && L.y == impassable[i].y) + return false; + return true; } diff --git a/src/Frame.cpp b/src/Frame.cpp index c63aeb4..ca0e41e 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -4,7 +4,7 @@ Frame::Frame(string location, int nRow, int nCol) { hasSuper = FALSE; super = NULL; - + filled = false; int i, j=0; string line; ifstream file (location); @@ -31,6 +31,7 @@ Frame::Frame(string location, int nRow, int nCol) Frame::Frame(Frame &sw, int rows, int cols, int nRow, int nCol) { + filled = false; hasSuper = TRUE; super = sw.getWin(); w = derwin(super,rows,cols,nRow,nCol); @@ -103,28 +104,51 @@ void Frame::move(int nRow, int nCol) void Frame::fillWindow() { - if(!colored) - for(int i = 0; i < width; i++) - for(int j = 0; j < height; j++) + + for(int i = 0; i < width; i++) + for(int j = 0; j < height; j++) + { + if(m[j][i] == 'O' || m[j][i] == '0') { - if(m[j][i] == 'O' || m[j][i] == '0') - wattron(w,COLOR_PAIR(2)); - else - wattron(w,COLOR_PAIR(1)); - mvwaddch(w,j,i,m[j][i]); + wattron(w,COLOR_PAIR(2)); + if(!filled) + { + Location l(j,i); + impassable.push_back(l); + } } + else + wattron(w,COLOR_PAIR(1)); + + mvwaddch(w,j,i,m[j][i]); + } wattron(w,COLOR_PAIR(3)); for(int y = 0; y < height; ++y) { mvwaddch(w, y, 0, '-'); mvwaddch(w, y, width - 1, '-'); + if(!filled) + { + Location l1(y,0); + Location l2(y,width-1); + impassable.push_back(l1); + impassable.push_back(l2); + } } for(int x = 0; x < width; ++x) { mvwaddch(w, 0, x, '|'); mvwaddch(w, height - 1, x, '|'); + if(!filled) + { + Location l1(0,x); + Location l2(height-1,x); + impassable.push_back(l1); + impassable.push_back(l2); + } } wattroff(w,COLOR_PAIR(3)); + filled = true; } diff --git a/src/List.cpp b/src/List.cpp index d4bc796..fefb37d 100644 --- a/src/List.cpp +++ b/src/List.cpp @@ -1,8 +1,8 @@ #include "List.hpp" -List::List() +List::List(vector <Location> i) { - for(int i = 0; i < 50; i++) + for(int i = 0; i < 10; i++) { Location L; L.x = 150; @@ -10,6 +10,7 @@ List::List() Character x ('@',4,L); men.push_back(x); } + impassable = i; } void List::draw(WINDOW * w) @@ -21,5 +22,5 @@ void List::draw(WINDOW * w) void List::action() { for(int i = 0; i < men.size(); i++) - men[i].action(men); + men[i].action(men,impassable); } diff --git a/src/main.cpp b/src/main.cpp index c0d59af..8f5208f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,14 +6,13 @@ int main() Frame map("scripts/map.txt",0,0); Frame view(map,s.getHeight(),s.getWidth(),0,0); - List L; - Location l; - l.x =150; - l.y =150; + Location l(150,150); Character cursor('X',3,l); map.fillWindow(); + List L(map.getImpassable()); + L.draw(map.getWin()); cursor.draw(map.getWin()); |