Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 2.63 KB

File metadata and controls

65 lines (45 loc) · 2.63 KB

CS50 Final Project - Nuggets

Group jjen: Julian, Joanna, Eddie, Neo

grid

The grid module maintains a grid that the Nuggets game is played on. The grid is represented by an NC x NR array of characters and holds an integer array of gold piles. In the Nuggets game, the player is able to move around the map (which is stored as a grid) and collect gold.

Usage

The grid, defined in grid.h and implemented in grid.c, defines a grid_t structure and exports the following functions:

grid_t* grid_new(const char* map, const int totalGold, const int numPiles);
char grid_getPoint(grid_t* grid, int row, int col);
bool grid_setPoint(grid_t* grid, int row, int col, char value);
int grid_getRows(grid_t* grid);
int grid_getCols(grid_t* grid);
void grid_delete(grid_t* grid);
bool grid_isWall(grid_t* grid, int row, int col);
bool grid_isGold(grid_t* grid, int row, int col);
bool grid_isPlayer(grid_t* grid, int row, int col);
bool grid_isRoomSpot(grid_t* grid, int row, int col);
bool grid_isPassage(grid_t* grid, int row, int col);
char* grid_print(grid_t* grid);
bool grid_isVisible(grid_t* map, int prow, int pcol, int row, int col); 
grid_t* grid_visibleMap(grid_t* map, int prow, int pcol, bool spectator);
int grid_collectGold (grid_t* grid, int prow, int pcol);

Implementation

The grid_new function creates a new grid from a given map file and returns a pointer to it.

The grid_setPoint function is a standard setter method.

The grid_getPoint, grid_getRows and grid_getCols functions are standard getter methods.

The grid_delete function deletes a grid and frees any memory that has been allocated for it.

The grid_isWall, grid_isGold, grid_isPlayer, grid_isRoomSpot, and grid_isPassage functions check if a grid spot is a specific game element based on the character stored in the array.

The grid_print returns a string version of the grid that can then be printed using functions such as printf.

The grid_isVisible function uses Bresenham's line algorithm to check if a grid spot is visible from the player's current spot.

The grid_visibleMap function constructs a player's visible map by calling grid_isVisble on every grid point.

The grid_collectGold function handles the "collecting" of gold and returns the amount of gold collected.

Files

  • Makefile - compilation procedure
  • grid.h - the interface
  • grid.h - the implementation
  • gridtest.c - unit test driver

Compilation

To compile, simply make.

Testing

Testing uses a gridtest.c driver to run tests on primary grid functions and a testing.sh bash script to call it. To test, simply make test &> testing.out.