diff options
author | Kamil Kaminski <kamilkss@gmail.com> | 2011-03-14 01:03:26 -0500 |
---|---|---|
committer | Kamil Kaminski <kamilkss@gmail.com> | 2011-03-14 01:03:26 -0500 |
commit | a06be0da905b493497749ebe8495a80e6ef26e32 (patch) | |
tree | ab08efee06a0e0581970e5f88e32ddbf5eeb2c99 | |
parent | 8c4f0c7d6020ca581b245012e687973a14a1947d (diff) | |
download | klotski-a06be0da905b493497749ebe8495a80e6ef26e32.tar.gz klotski-a06be0da905b493497749ebe8495a80e6ef26e32.tar.bz2 klotski-a06be0da905b493497749ebe8495a80e6ef26e32.zip |
kill all tabs
-rw-r--r-- | grid.cpp | 11 | ||||
-rw-r--r-- | grid.h | 33 | ||||
-rw-r--r-- | main.cpp | 57 | ||||
-rw-r--r-- | main.h | 1 | ||||
-rw-r--r-- | piece.cpp | 1 | ||||
-rw-r--r-- | piece.h | 15 |
6 files changed, 62 insertions, 56 deletions
@@ -20,17 +20,17 @@ Grid::Grid(const Grid &grid) : rows(grid.rows), cols(grid.cols), numOfMoves(grid int *Grid::getRows(void) { - return &rows; + return &rows; } int *Grid::getCols(void) { - return &cols; + return &cols; } int *Grid::getNumOfMoves(void) { - return &numOfMoves; + return &numOfMoves; } vector<Piece> *Grid::getPieces(void) @@ -40,12 +40,12 @@ vector<Piece> *Grid::getPieces(void) void Grid::setRows(int n) { - rows = n; + rows = n; } void Grid::setCols(int n) { - cols = n; + cols = n; } void Grid::addMove(string move) @@ -56,3 +56,4 @@ void Grid::addMove(string move) void Grid::markPiecesPos(void) { } + @@ -15,30 +15,31 @@ using std::vector; class Grid { private: - int rows; - int cols; - int numOfMoves; - int lastMoved; - int lastMoveDir; - vector<Piece> pieces; - vector<string> moves; - string *board; + int rows; + int cols; + int numOfMoves; + int lastMoved; + int lastMoveDir; + vector<Piece> pieces; + vector<string> moves; + string *board; public: Grid(void); /* we do not need a copy constructor since the deault shallow copy will be fine */ //Grid(const Grid &); - int *getRows(void); - int *getCols(void); - int *getNumOfMoves(void); - vector<Piece> *getPieces(void); + int *getRows(void); + int *getCols(void); + int *getNumOfMoves(void); + vector<Piece> *getPieces(void); - void setRows(int); - void setCols(int); - void addMove(string); + void setRows(int); + void setCols(int); + void addMove(string); - void markPiecesPos(void); + void markPiecesPos(void); }; #endif + @@ -70,11 +70,11 @@ string *fillBoard(Grid grid) { tmp = (*(grid.getPieces()))[ix]; name = tmp.getName(); - row = tmp.getRow(); - col = tmp.getCol(); - w = tmp.getW(); - h = tmp.getH(); - dir = tmp.getDir(); + row = tmp.getRow(); + col = tmp.getCol(); + w = tmp.getW(); + h = tmp.getH(); + dir = tmp.getDir(); int j; offset = (grid_w * (row-1)) + col; @@ -122,11 +122,11 @@ void printGrid(Grid grid) { tmp = (*(grid.getPieces()))[ix]; name = tmp.getName(); - row = tmp.getRow(); - col = tmp.getCol(); - w = tmp.getW(); - h = tmp.getH(); - dir = tmp.getDir(); + row = tmp.getRow(); + col = tmp.getCol(); + w = tmp.getW(); + h = tmp.getH(); + dir = tmp.getDir(); int j; offset = (grid_w * (row-1)) + col; @@ -159,32 +159,32 @@ void printGrid(Grid grid) /* load grid from a file */ Grid loadGrid(char **argv) { - FILE *fname = fopen(argv[1], "r"); + FILE *fname = fopen(argv[1], "r"); if (fname == NULL) { perror("fopen"); exit(EXIT_FAILURE); } - Grid grid; - Piece piece_tmp(""); + Grid grid; + Piece piece_tmp(""); /* used for line reading */ size_t line_sz = 0; char *line = NULL; int matched_inputs = 0; - if (getline(&line, &line_sz, fname) != -1) + if (getline(&line, &line_sz, fname) != -1) sscanf(line, "%d %d\n", grid.getRows(), grid.getCols()); - if (*grid.getRows() < 1 || *grid.getCols() < 1) - { - cout << "invalid grid dimensions, read in: " << *grid.getRows() << "h, " - << *grid.getCols() << "w" << endl; - exit(EXIT_FAILURE); - } + if (*grid.getRows() < 1 || *grid.getCols() < 1) + { + cout << "invalid grid dimensions, read in: " << *grid.getRows() << "h, " + << *grid.getCols() << "w" << endl; + exit(EXIT_FAILURE); + } - /* parse grid's dimensions */ + /* parse grid's dimensions */ int piece_row = -1; int piece_col = -1; int piece_w = -1; @@ -198,7 +198,7 @@ Grid loadGrid(char **argv) for (i = 0; getline(&line, &line_sz, fname) != -1; i++) { - matched_inputs = sscanf(line, "%d %d %d %d %c\n", &piece_row, + matched_inputs = sscanf(line, "%d %d %d %d %c\n", &piece_row, &piece_col, &piece_w, &piece_h, &piece_dir); if (matched_inputs != 5) @@ -564,11 +564,11 @@ int main(int argc, char *argv[]) /* seed rand() */ srand((unsigned int ) time(NULL)); - if (argc != 2) - { - cout << "usage: " << argv[0] << " <file>" << endl; - return -1; - } + if (argc != 2) + { + cout << "usage: " << argv[0] << " <file>" << endl; + return -1; + } Grid grid = loadGrid(argv); printGrid(grid); @@ -609,6 +609,7 @@ int main(int argc, char *argv[]) cout << "else" << endl; #endif - cout << "\n\tBye!" << endl; + cout << "\n\tBye!" << endl; return 0; } + @@ -32,3 +32,4 @@ string piece_tag[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c" string err_msg[4] = {"piece is correct", "piece has wrong dimensions", "piece has wrong direction", "piece is out of bounds"}; #endif + @@ -66,3 +66,4 @@ void Piece::setCol(int col_p) { col = col_p; } + @@ -20,13 +20,13 @@ typedef struct class Piece { private: - string name; - int row; - int col; - int w; - int h; - char dir; - vector<POINT> haveBeen; + string name; + int row; + int col; + int w; + int h; + char dir; + vector<POINT> haveBeen; public: Piece(void); @@ -46,3 +46,4 @@ class Piece }; #endif + |