diff options
-rw-r--r-- | src/Frame.cpp | 15 | ||||
-rw-r--r-- | src/Screen.cpp | 8 | ||||
-rw-r--r-- | src/main.cpp | 36 |
3 files changed, 33 insertions, 26 deletions
diff --git a/src/Frame.cpp b/src/Frame.cpp index 7da219c..6fa8d84 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -17,11 +17,11 @@ Frame::Frame(string location, int nRow, int nCol) { hasSuper = FALSE; super = NULL; - + int i, j=0; string line; ifstream file (location); - + if(file.is_open()) { getline(file,line); @@ -33,7 +33,7 @@ Frame::Frame(string location, int nRow, int nCol) j++; } } - + w = newwin(j,i,nRow,nCol); height = j; width = i; @@ -140,12 +140,16 @@ void Frame::fillWindow() for(int i = 0; i < width; i++) for(int j = 0; j < height; j++) { - attron(COLOR_PAIR(1)); + 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(3)); for(int y = 0; y < height; ++y) - { + { mvwaddch(w, y, 0, '-'); mvwaddch(w, y, width - 1, '-'); } @@ -155,6 +159,7 @@ void Frame::fillWindow() mvwaddch(w, 0, x, '|'); mvwaddch(w, height - 1, x, '|'); } + wattroff(w,COLOR_PAIR(3)); } WINDOW * Frame::getWin() diff --git a/src/Screen.cpp b/src/Screen.cpp index 40a31d1..54033f7 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -9,9 +9,11 @@ Screen::Screen() keypad(stdscr,TRUE); curs_set(0); getmaxyx(stdscr,height,width); - + start_color(); - init_pair(1, COLOR_GREEN, COLOR_RED); + init_pair(1, COLOR_GREEN, COLOR_BLACK); + init_pair(2, COLOR_YELLOW,COLOR_BLACK); + init_pair(3, COLOR_WHITE, COLOR_WHITE); } Screen::~Screen() @@ -20,7 +22,7 @@ Screen::~Screen() } void Screen::ping(string msg) -{ +{ const char * cmsg = msg.c_str(); printw(cmsg); } diff --git a/src/main.cpp b/src/main.cpp index 9dc48a4..5c550de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,35 +3,35 @@ int main() { Screen s; - - //Frame map(2*s.getHeight(),2*s.getWidth(),0,0); + Frame map("scripts/map.txt",0,0); Frame view(map,s.getHeight(),s.getWidth(),0,0); Character cursor('X',map.getHeight()/2,map.getWidth()/2); - - map.fillWindow(); + + map.fillWindow(); map.add(cursor); view.center(cursor); - view.refresh(); - + view.refresh(); + while(true) { - char c = getch(); + char c = getch(); + + if (c == 'h') + map.add(cursor,cursor.getRow(),cursor.getCol()-1); + else if (c == 'l') + map.add(cursor,cursor.getRow(),cursor.getCol()+1); + else if (c == 'k') + map.add(cursor,cursor.getRow()-1,cursor.getCol()); + else if (c == 'j') + map.add(cursor,cursor.getRow()+1,cursor.getCol()); + else if (c == 'q') + break; - if(c == 'h') - map.add(cursor,cursor.getRow(),cursor.getCol()-1); - else if(c == 'l') - map.add(cursor,cursor.getRow(),cursor.getCol()+1); - else if(c == 'k') - map.add(cursor,cursor.getRow()-1,cursor.getCol()); - else if(c == 'j') - map.add(cursor,cursor.getRow()+1,cursor.getCol()); - else if(c == 'q') - break; - view.center(cursor); view.refresh(); + map.fillWindow(); } return 0; |