summaryrefslogtreecommitdiff
path: root/src/Character.cpp
blob: fd482a93afe9ce2a5fbcacd10fcd668d4b17e274 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "Character.hpp"

Character::Character(char nSymbol, int nColor, int nRow, int nCol)
{
    symbol = nSymbol;
    row = nRow;
    col = nCol;
    color = nColor;
    l.x = row;
    l.y = col;
}

void Character::move(Location L)
{
    l.x = L.x;
    l.y = L.y;
}

void Character::draw(WINDOW * w)
{
    wattron(w,COLOR_PAIR(color));
    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)
{
        if(order == "wander")
        {
            Location L;
            int r = rand()%15+1; 
            if(r==1)
            {
                L.x = l.x+1;
                L.y = l.y;
            }
            else if(r==2)
            {
                L.x = l.x-1;
                L.y = l.y;
            }
            else if(r==3)
            {
                L.x = l.x; L.y = l.y+1;
            }
            else if(r==4)
            {
                L.x = l.x; L.y = l.y-1;
            }
            else if(r==5)
            {
                L.x = l.x+1; L.y = l.y+1;
            }
            else if(r==6)
            {
                L.x = l.x-1; L.y = l.y-1;
            }
            else if(r==7)
            {
                L.x = l.x+1; L.y = l.y-1;
            }
            else if(r==8)
            {    L.x = l.x-1; L.y = l.y+1;
            
            }
            else
                return false;
            
            if(check(L,occupied))
                move(L);
            else
                return false;

            return true;
        }
}

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;
    return true;
}