summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.Frame.cpp.swpbin0 -> 12288 bytes
-rw-r--r--src/Character.cpp29
-rw-r--r--src/Frame.cpp200
-rw-r--r--src/Screen.cpp33
-rw-r--r--src/main.cpp38
5 files changed, 300 insertions, 0 deletions
diff --git a/src/.Frame.cpp.swp b/src/.Frame.cpp.swp
new file mode 100644
index 0000000..1e3e507
--- /dev/null
+++ b/src/.Frame.cpp.swp
Binary files differ
diff --git a/src/Character.cpp b/src/Character.cpp
new file mode 100644
index 0000000..71a47bb
--- /dev/null
+++ b/src/Character.cpp
@@ -0,0 +1,29 @@
+#include "Character.hpp"
+
+Character::Character(char nSymbol, int nRow, int nCol)
+{
+ symbol = nSymbol;
+ row = nRow;
+ col = nCol;
+}
+
+void Character::move(int nRow, int nCol)
+{
+ row = nRow;
+ col = nCol;
+}
+
+int Character::getRow()
+{
+ return row;
+}
+
+int Character::getCol()
+{
+ return col;
+}
+
+char Character::getSymbol()
+{
+ return symbol;
+}
diff --git a/src/Frame.cpp b/src/Frame.cpp
new file mode 100644
index 0000000..fa9adae
--- /dev/null
+++ b/src/Frame.cpp
@@ -0,0 +1,200 @@
+#include "Frame.hpp"
+
+/*
+Frame::Frame(int rows, int cols, int nRow, int nCol)
+{
+ hasSuper = FALSE;
+ super = NULL;
+ w = newwin(rows,cols,nRow,nCol);
+ height = rows;
+ width = cols;
+ row = nRow;
+ col = nCol;
+}
+*/
+
+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())
+ {
+ while(getline(file,line))
+ {
+ m.append(line);
+ j++;
+ }
+ i=line.length();
+ }
+}
+
+
+Frame::Frame(Frame &sw, int rows, int cols, int nRow, int nCol)
+{
+ hasSuper = TRUE;
+ super = sw.getWin();
+ w = derwin(super,rows,cols,nRow,nCol);
+ height = rows;
+ width = cols;
+ row = nRow;
+ col = nCol;
+}
+
+Frame::~Frame()
+{
+ delwin(w);
+}
+
+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))
+ {
+ erase(c);
+ mvwaddch(w,nRow,nCol,c.getSymbol());
+ c.move(nRow,nCol);
+ }
+}
+
+void Frame::center(Character &ch)
+{
+ if(hasSuper)
+ {
+ int rr = row;
+ int cc = col;
+ int hh, ww;
+ int r = ch.getRow() - height/2;
+ int c = ch.getCol() - width/2;
+
+ getmaxyx(super, hh, ww);
+
+ if(c + width >= ww)
+ {
+ int delta = ww - (c + width);
+ cc = c + delta;
+ }
+ else
+ cc = c;
+
+ if(r + height >= hh)
+ {
+ int delta = hh - (r + height);
+ rr = r + delta;
+ }
+ else
+ rr = r;
+
+ if(r < 0)
+ rr = 0;
+
+ if(c < 0)
+ cc = 0;
+
+ move(rr,cc);
+ }
+}
+
+void Frame::refresh()
+{
+ if(hasSuper)
+ touchwin(super);
+ wrefresh(w);
+}
+
+void Frame::move(int nRow, int nCol)
+{
+ if(hasSuper)
+ {
+ mvderwin(w,nRow,nCol);
+ row = nRow;
+ col = nCol;
+ refresh();
+ }
+}
+
+void Frame::fillWindow()
+{
+ int maxX = width/2;
+ int maxY = height/2;
+
+ for(int y = 0; y < maxY; ++y)
+ for(int x = 0; x < maxX; ++x)
+ mvwaddch(w, y, x, '0');
+
+ for(int y = 0; y < maxY; ++y)
+ for(int x = maxX; x < width; ++x)
+ mvwaddch(w, y, x, '1');
+
+ for(int y = maxY; y < height; ++y)
+ for(int x = 0; x < maxX; ++x)
+ mvwaddch(w, y, x, '2');
+
+ for(int y = maxY; y < height; ++y)
+ for(int x = maxX; x < width; ++x)
+ mvwaddch(w, y, x, '3');
+
+ for(int y = 0; y < height; ++y)
+ {
+ mvwaddch(w, y, 0, '-');
+ mvwaddch(w, y, width - 1, '-');
+ }
+
+ for(int x = 0; x < width; ++x)
+ {
+ mvwaddch(w, 0, x, '|');
+ mvwaddch(w, height - 1, x, '|');
+ }
+}
+
+WINDOW * Frame::getWin()
+{
+ return w;
+}
+
+WINDOW * Frame::getSuper()
+{
+ return super;
+}
+
+bool Frame::getHasSuper()
+{
+ return hasSuper;
+}
+
+int Frame::getHeight()
+{
+ return height;
+}
+
+int Frame::getWidth()
+{
+ return width;
+}
+
+int Frame::getRow()
+{
+ return row;
+}
+
+int Frame::getCol()
+{
+ return col;
+}
+
+
+
+
diff --git a/src/Screen.cpp b/src/Screen.cpp
new file mode 100644
index 0000000..c3977d6
--- /dev/null
+++ b/src/Screen.cpp
@@ -0,0 +1,33 @@
+#include "Screen.hpp"
+
+Screen::Screen()
+{
+ initscr();
+ clear();
+ noecho();
+ cbreak();
+ keypad(stdscr,TRUE);
+ curs_set(0);
+ getmaxyx(stdscr,height,width);
+}
+
+Screen::~Screen()
+{
+ endwin();
+}
+
+void Screen::ping(string msg)
+{
+ const char * cmsg = msg.c_str();
+ printw(cmsg);
+}
+
+int Screen::getHeight()
+{
+ return height;
+}
+
+int Screen::getWidth()
+{
+ return width;
+}
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..d6b26ea
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,38 @@
+#include "main.hpp"
+
+int main()
+{
+ Screen s;
+
+ //Frame map(2*s.getHeight(),2*s.getWidth(),0,0);
+ Frame map("../scripts/map",0,0);
+ Frame view(map,s.getHeight(),s.getWidth(),0,0);
+
+ Character cursor('X',map.getHeight()/2,map.getWidth()/2);
+
+ map.fillWindow();
+ map.add(cursor);
+ view.center(cursor);
+ view.refresh();
+
+ while(true)
+ {
+ 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;
+
+ view.center(cursor);
+ view.refresh();
+ }
+
+ return 0;
+}