Ask a question from expert

Ask now

Static int maze.h

4 Pages1383 Words50 Views
   

Added on  2019-09-20

About This Document

#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

Static int maze.h

   Added on 2019-09-20

BookmarkShareRelated Documents
#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){
Static int maze.h_1
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(){
Static int maze.h_2

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
#include <stdio.h>.
|1
|263
|147

extern int getTotalKeys();.
|2
|405
|183

Maze Solver AI for Desklib
|2
|917
|172

Questions on Stack Program
|11
|1305
|31

Java Program to Draw Shapes - Desklib
|10
|1283
|284

Word Puzzle Generator in C++
|9
|2474
|149