147 lines
3.5 KiB
Plaintext
147 lines
3.5 KiB
Plaintext
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
void readPlayer(char *arr);
|
|
void readZombie(char *arr);
|
|
void readTreasure(char *arr);
|
|
|
|
// read maze file in to the array
|
|
void readMaze(char *arr, int r, int c);
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
printf("Hello, World!\n");
|
|
FILE* mazeFile; /* Maze Input File */
|
|
char c; /* Holds character for line input from file */
|
|
int row; /* Holds number of rows for input from file */
|
|
int col; /* Holds number of cols for input from file */
|
|
char shold[2000]; /* Holds lines for input from file */
|
|
|
|
if (argc != 2)
|
|
{
|
|
printf("An error has ocurred no input file was given.\n");
|
|
return 1;
|
|
}
|
|
mazeFile = fopen(argv[1], "r");
|
|
if (mazeFile == NULL)
|
|
{
|
|
printf("Error in opening the file.\n");
|
|
return 1;
|
|
}
|
|
fgets(shold, 2, mazeFile);
|
|
while ( !feof(mazeFile) )
|
|
{
|
|
|
|
switch(shold[0])
|
|
{
|
|
case 'M':
|
|
printf ("Maze encountered\n");
|
|
fscanf(mazeFile, "%d %d", &row, &col);
|
|
printf("%d\n", row);
|
|
// possible dynamic allocation of 2D array
|
|
int i = 0, j = 0;
|
|
char **maze = malloc(row * sizeof(char *));
|
|
for(i = 0; i < row; i++)
|
|
maze[i] = malloc(col * sizeof(char));
|
|
for (i = 0; i < row; i++)
|
|
{
|
|
for (j = 0; j < col; j++)
|
|
{
|
|
fscanf(mazeFile, "%c", &maze[i][j]);
|
|
printf("%c", maze[i][j]);
|
|
}
|
|
|
|
}
|
|
printf("%c", maze[0 * col + 0]);
|
|
for(i = 0; i < row; i++)
|
|
free(maze[i]);
|
|
free(maze);
|
|
//int (*maze)[col] = malloc(sizeof(int[row][col]));
|
|
//readMaze(maze, row, col);
|
|
break;
|
|
case 'P':
|
|
//case for player
|
|
printf ("Player\n");
|
|
fscanf(mazeFile, "%d %d", &row, &col);
|
|
printf("%d\n", row);
|
|
// possible dynamic allocation of 2D array
|
|
char* player = malloc((row * col) * sizeof(char));
|
|
readPlayer(player);
|
|
break;
|
|
|
|
case 'Z':
|
|
//case for zombie
|
|
printf ("Zombie\n");
|
|
fscanf(mazeFile, "%d %d", &row, &col);
|
|
printf("%d\n", row);
|
|
// possible dynamic allocation of 2D array
|
|
char* zombie = malloc((row * col) * sizeof(char));
|
|
readZombie(zombie);
|
|
break;
|
|
|
|
case 'T':
|
|
//case for treasure
|
|
printf ("Treasure\n");
|
|
fscanf(mazeFile, "%d %d", &row, &col);
|
|
printf("%d\n", row);
|
|
// possible dynamic allocation of 2D array
|
|
char* treasure = malloc((row * col) * sizeof(char));
|
|
readTreasure(treasure);
|
|
break;
|
|
default:
|
|
//printf ("Basic error\n");
|
|
break;
|
|
};
|
|
|
|
for(int i=0;i<row;i++)
|
|
{
|
|
for(int j=0;j<col;j++)
|
|
{
|
|
if(fscanf == #) //if file has #
|
|
{
|
|
maze[i][j] = #;
|
|
}
|
|
else
|
|
{
|
|
maze[i][j] = " ";
|
|
}
|
|
}
|
|
}
|
|
|
|
fgets(shold, 2, mazeFile);
|
|
if (feof(mazeFile))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
fclose(mazeFile);
|
|
//printf ("So this line won't print without an argument.\n");
|
|
|
|
//free the memory
|
|
free(maze);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void readMaze(char *arr, int row, int col)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
void readPlayer(char *arr)
|
|
{
|
|
|
|
}
|
|
|
|
void readZombie(char *arr)
|
|
{
|
|
|
|
}
|
|
void readTreasure(char *arr)
|
|
{
|
|
|
|
}
|