Ask a question to Desklib · AI bot

Ask NowBETA

Static int maze.h

Added on -2019-09-20

#include "Maze.h" static int mazeStructure[500][500] = 0 ; static int numTotalKeys = 0; static int numKeysHeld = 0; static int maxRow = 0; static int maxCol = 0; static int playerRow = -1; static int playerCol = -1; static int exitRow = -1; static int exitCol = -1; static int readM
| 4 pages
| 1383 words
| 50 views

Trusted by 2+ million users,
1000+ happy students everyday

#include "Maze.h"static int mazeStructure[500][500] = { 0 };static int numTotalKeys = 0;static int numKeysHeld = 0;static int maxRow = 0;static int maxCol = 0;static int playerRow = -1;static int playerCol = -1;static int exitRow = -1;static int exitCol = -1;static int readMazeRan = 0;static int numSteps = 0;int getCurrentKeys(){ return numKeysHeld;}int getTotalKeys(){ return numTotalKeys;}int getNumSteps(){ return numSteps;}void getCurrentPosition(int * arr){ arr[0] = playerRow; arr[1] = playerCol;}int abs(int x){ if (x < 0) return 0-x; return x;}int dangerous(int x, int y){ return x < 0 || y < 0 || x >= 500 || y >= 500;}//fills the maze based on the file givenvoid readMaze(char* fileName){ if(readMazeRan){ printf("ERROR: Multiple calls to readMaze\n"); return; } readMazeRan = 1; //stuff too complicated to cover in class FILE *inputFile = fopen(fileName, "r"); char currentChar; int currentRow = 0; int currentCol = 0; while((currentChar = fgetc(inputFile)) != EOF){ if(currentChar == '\n'){ if(currentCol > maxCol){
maxCol = currentCol; } currentRow += 1; currentCol = 0; } else { //3 is a key if(currentChar == '3'){ numTotalKeys++; //2 is a player, but only one is allowed }else if(currentChar == '2'){ if(playerRow != -1){ printf("ERROR: You can't have more than one player! The instance at (%d, %d) was ignored in favor of the instance at (%d, %d).\n", currentRow, currentCol, playerRow, playerCol); currentChar = '1'; }else{ playerRow = currentRow; playerCol = currentCol; } //4 is an exit, but only one is allowed }else if(currentChar == '4'){ if(exitRow != -1){ printf("ERROR: You can't have more than one exit! The instance at (%d, %d) was ignored in favor of the instance at (%d, %d).\n", currentRow, currentCol, exitRow, exitCol); currentChar = '1'; }else{ exitRow = currentRow; exitCol = currentCol; } } if(currentChar >= '0' && currentChar <= '4'){ mazeStructure[currentRow][currentCol] = currentChar - 48; }else{ printf("ERROR: Unrecognized character at (%d, %d)\n", currentRow, currentCol); } currentCol+=1; } } if(playerRow == -1){ printf("ERROR: No player object was found\n"); } if(exitRow == -1){ printf("ERROR: No exit object was found\n"); } maxRow = currentRow;}void printMaze(){

Found this document preview useful?

You are reading a preview
Upload your documents to download
or
Become a Desklib member to get accesss

Students who viewed this