Skip to content

Instantly share code, notes, and snippets.

@Xe
Created April 17, 2012 17:27
Show Gist options
  • Save Xe/2407632 to your computer and use it in GitHub Desktop.
Save Xe/2407632 to your computer and use it in GitHub Desktop.
Maze program
#include "maze.h"
void main() {
printf("Escape from the Everfree Forest!\n");
printf("Apple Bloom is stuck in the Everfree Forest trying to get the flowers to Zecora's house. Help her find her way through the scary forest! Be careful though, the Great and Powerful Trixie is hidden in the forest, and encountering her will surely cause your doom.\n");
//Force the code to call something from the maze module
move(TREE);
}
ZIP=dodrillshw2.zip
BIN=hw2
all:
clear
make clean
gcc -o ${BIN} -g *.c
test:
make
./${BIN} input.txt 1> output.txt
more output.txt
clean:
touch ${BIN} 4~
rm ${BIN} *~
package:
make clean
touch ${ZIP}
rm ${ZIP}
zip ${ZIP} *.c *.txt Makefile
#include "maze.h"
void printMaze(char maze[][COLS], int fow[][COLS]) {
//print all the fucking characters if you can see them
}
void printChar(char value, int visible) {
if(visible) {
putchar(value);
//do the file shit here
}
}
void move(char direction) {
//prompt for move and validate
}
int isValidMove(char grid[][COLS], int fow[][COLS], int nextx, int nexty) {
int xdiff = nextx - x;
int ydiff = nexty - y;
if(abs(xdiff) > 1) {
return false;
} else {
char mapVal = grid[nextx][nexty];
if(mapVal == TREE) {
//I would like to be a tree, but cannot :(
fow[nextx][nexty] = true;
} else if(mapVal == HAG) {
printf("You ran into The Great and Powerful Trixie, she bores you to death with her boasting. You're dead.\n");
return DEAD;
} else if(mapVal == FINISH) {
printf("Woohoo! You found Zecora's hut!\n");
return VICTORY;
} else {
x = nextx;
y = nexty;
fow[nextx][nexty] = true;
return NORML;
}
}
}
#ifndef MAZE_H
#define MAZE_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ROWS 20
#define COLS 25
#define FNAME 256
#define true 0
#define false 1
//Into definitions for the characters in this game
#define TREE 'T'
#define OPEN '.'
#define UNSHOWN 'U'
#define HAG 'H'
#define START 'S'
#define FINISH 'F'
#define NORTH 'N'
#define SOUTH 'S'
#define WEST 'W'
#define EAST 'E'
#define QUIT 'Q'
#define DUDEMAN 'M'
#define DEAD 666
#define VICTORY 42
#define NORML 8
//variables that we need
int x = 0, y = 0;
char * fname_in[FNAME];
char * fname_out[FNAME];
char maze[ROWS][COLS];
int fow[ROWS][COLS];
//Don't let this int type declaration decieve you, this is going to be treated as a bunch of boolean values.
void printMaze(char[][COLS], int[][COLS]);
void printChar(char, int);
void move(char);
int isValidMove(char[][COLS], int[][COLS], int, int);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment