-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
27 additions
and
156 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,65 @@ | ||
#include <unistd.h> | ||
#include <cstring> | ||
#include <iostream> | ||
#include <exception> | ||
|
||
#include <sqlite3.h> | ||
#include <ncurses.h> | ||
#include <libgrandmaze/colour.hpp> | ||
#include <libgrandmaze/mapfile.hpp> | ||
|
||
#include "main.hpp" | ||
|
||
int initialise(void) | ||
void initialise(void) | ||
{ | ||
int error = setCwd(); | ||
if (error) | ||
{ | ||
return error; | ||
} | ||
// set current working directory | ||
setCwd(); | ||
|
||
initHub(); | ||
// init db | ||
sqlite3_open((Cwd + "/db/game.db").c_str(), &Db); | ||
|
||
// init map | ||
GrandMaze::DbMapReader r(Db); | ||
CurrentMap = r.load("maps", "data", 1); | ||
|
||
// init ncurses | ||
initscr(); | ||
cbreak(); | ||
noecho(); | ||
|
||
start_color(); | ||
curs_set(0); | ||
keypad(stdscr, true); | ||
|
||
// init game colours | ||
GrandMaze::initColour(); | ||
|
||
return 0; | ||
} | ||
|
||
int initHub(void) | ||
{ | ||
GrandMaze::FileMapReader r; | ||
CurrentMap = r.load(Cwd + "/maps/final_map.map"); | ||
|
||
return 0; | ||
} | ||
|
||
int setCwd(void) | ||
void setCwd(void) | ||
{ | ||
// set the current working directory | ||
char *tmp = new char[1024]; | ||
if (getcwd(tmp, 1024) == NULL) | ||
{ | ||
return errno; | ||
throw strerror(errno); | ||
} | ||
|
||
Cwd = tmp; | ||
delete tmp; | ||
|
||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int error = initialise(); | ||
if (error) | ||
{ | ||
std::cerr << "An error occurred: " << strerror(error) << std::endl; | ||
return error; | ||
} | ||
// initialise global vars and ncurses | ||
initialise(); | ||
|
||
// draw map to stdscr | ||
CurrentMap->draw(stdscr); | ||
|
||
// pause execution to display map | ||
getch(); | ||
|
||
endwin(); | ||
|
||
delete CurrentMap; | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters