summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Character.cpp87
-rw-r--r--src/Frame.cpp4
-rw-r--r--src/List.cpp15
-rw-r--r--src/main.cpp7
4 files changed, 55 insertions, 58 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;
}
diff --git a/src/Frame.cpp b/src/Frame.cpp
index 77c7063..a8403b7 100644
--- a/src/Frame.cpp
+++ b/src/Frame.cpp
@@ -49,12 +49,12 @@ void Frame::add(Character &c)
{
mvwaddch(w,c.getRow(),c.getCol(),c.getSymbol());
}
-*/
+
void Frame::erase(Character &c)
{
mvwaddch(w,c.getRow(),c.getCol(),' ');
}
-/*
+
void Frame::add(Character &c, int nRow, int nCol)
{
if((nRow >= 0 && nRow < height) && (nCol >= 0 && nCol < width))
diff --git a/src/List.cpp b/src/List.cpp
index 94506f4..ed09c5a 100644
--- a/src/List.cpp
+++ b/src/List.cpp
@@ -4,7 +4,10 @@ List::List()
{
for(int i = 0; i < 10; i++)
{
- Character x ('@',4,150,150+i);
+ Location L;
+ L.x = 150;
+ L.y = 150+i;
+ Character x ('@',4,L);
men.push_back(x);
occupied.push_back(x.getLocation());
}
@@ -19,9 +22,9 @@ void List::draw(WINDOW * w)
void List::action()
{
for(int i = 0; i < 10; i++)
- if(men[i].action(occupied))
- {
- //rows[i] = 0;
- //cols[i] = 0;
- }
+ {
+ Location L = men[i].action(occupied);
+ if (L.x != 0 && L.y != 0)
+ occupied[i]=L;
+ }
}
diff --git a/src/main.cpp b/src/main.cpp
index 2a33d65..df5a563 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -7,8 +7,11 @@ int main()
Frame map("scripts/map.txt",0,0);
Frame view(map,s.getHeight(),s.getWidth(),0,0);
List L;
-
- Character cursor('X',3,map.getHeight()/2,map.getWidth()/2);
+
+ Location l;
+ l.x =150;
+ l.y =150;
+ Character cursor('X',3,l);
map.fillWindow();
L.draw(map.getWin());