Choose a direction to find your way to the end of a maze.


Choose a direction to find your way to the end of a maze.

How to run

Included is the main.cpp file of the program.  Load the file into any C++ complier to build and run the program.  There is also an executable that has already been compiled for the Windows operating system.


//  Maze Game created by Richie Leahey on 12/17/13.
//  Choose a direction to find your way to the end of a maze.

#include "stdafx.h"
#include <iostream>
#include "node.h"

using namespace std;

int main(int argc, const char * argv[]) {

	cout << "Welcome to the maze game!" << endl << endl;
	cout << "Enter a direction to find your way to the finish." << endl;
	cout << "Enter N for North, E for East, S for South, and W for West." << endl << endl;

	Node *A = new Node('A');
	Node *B = new Node('B');
	Node *C = new Node('C');
	Node *D = new Node('D');
	Node *E = new Node('E');
	Node *F = new Node('F');
	Node *G = new Node('G');
	Node *H = new Node('H');
	Node *I = new Node('I');
	Node *J = new Node('J');
	Node *K = new Node('K');
	Node *L = new Node('L');

	A->setConnections(NULL, E, B, NULL);
	B->setConnections(NULL, F, NULL, A);
	C->setConnections(NULL, G, D, NULL);
	D->setConnections(NULL, NULL, NULL, C);
	E->setConnections(A, I, NULL, NULL);
	F->setConnections(B, NULL, G, NULL);
	G->setConnections(C, K, H, F);
	H->setConnections(NULL, L, NULL, G);
	I->setConnections(E, NULL, J, NULL);
	J->setConnections(NULL, NULL, NULL, I);
	K->setConnections(G, NULL, NULL, NULL);
	L->setConnections(H, NULL, NULL, NULL);

	Node *current = A;

	while (current != L)
		cout << "You are in room " << current->getID() << " of the maze. " << "You can go: " << endl;
		if (current->getNorth() != NULL) cout << " North" << endl;
		if (current->getSouth() != NULL) cout << " South" << endl;
		if (current->getEast() != NULL) cout << " East" << endl;
		if (current->getWest() != NULL) cout << " West" << endl;
		char direction;
		cin >> direction;
		if ((direction == 'N') && (current->getNorth() != NULL))
			current = current->getNorth();
		if ((direction == 'S') && (current->getSouth() != NULL))
			current = current->getSouth();
		if ((direction == 'E') && (current->getEast() != NULL))
			current = current->getEast();
		if ((direction == 'W') && (current->getWest() != NULL))
			current = current->getWest();

	cout << endl << "Congratulations, you reached the finish!" << endl << endl;

	delete A;
	delete B;
	delete C;
	delete D;
	delete E;
	delete F;
	delete G;
	delete H;
	delete I;
	delete J;
	delete K;
	delete L;


	return 0;


#pragma once

class Node
	Node(char newID);
	void setConnections(Node *n, Node *s, Node *e, Node *w);
	Node* getNorth();
	Node* getSouth();
	Node* getEast();
	Node* getWest();
	char getID();
	char ID;
	Node *north, *south, *east, *west;


#include "stdafx.h"
#include "node.h"
#include <iostream>

Node::Node(void) : ID(' '), north(NULL), south(NULL), east(NULL), west(NULL)


Node::Node(char newID) : ID(newID), north(NULL), south(NULL), east(NULL), west(NULL)




char Node::getID()
	return ID;

void Node::setConnections(Node *n, Node *s, Node *e, Node *w)
	north = n;
	south = s;
	east = e;
	west = w;

Node* Node::getNorth()
	return north;

Node* Node::getSouth()
	return south;

Node* Node::getEast()
	return east;

Node* Node::getWest()
	return west;

char getID();