-
Errors in my program
I am writing a game program kind of like pac man.
As of now I am just trying to get my maze to display, but run into errors.
Could someone take a look at my code and see what i am doing wrong.
Thanks,
GJ
Code:
#include <ctime>
#include <conio.h>
#include <windows.h>
#include "Maze.h"
int main()
{
Status s = CONTINUE;
short kb;
char c;
bool b = false;
system("cls");
srand(time(0));
Maze mObj("Maze.dat");
mObj.displayMaze();
while(s == CONTINUE)
{
if(kbhit())
{
kb = getche();
kb = getche();
cout << "\b \b";
mObj.movePlayer(kb);
}
mObj.moveGhosts();
s = mObj.determineStatus();
mObj.displayMaze();
Sleep(250);
}
if(s == WIN)
cout << "Player found the treasure - you win! ";
else
cout << "Player was killed by ghost - you lose ";
system("pause");
return 0;
}
header file
my class and constructor
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
enum Status
{CONTINUE, WIN, LOSE};
const int mazeSize = 24;
const int numberOfGhosts = 10;
class Maze
{
private:
// data members
char maze[mazeSize][mazeSize];
char fileName[21];
struct location
{
int row;
int column;
};
location player;
location treasure;
location ghosts[numberOfGhosts];
public:
// constructor
Maze(char fn[])
{
strcpy(fileName,fn);
ifstream mazeFile;
mazeFile.open("Maze.dat");
for(int r = 0; r < mazeSize; ++r)
{
for(int c = 0; c < mazeSize; ++c)
{
mazeFile >> Maze[r][c];
if(Maze[r][c] == "#")
Maze[r][c] = '\xba';
else
Maze[r][c] = ' ';
}
}
mazeFile.close();
}
//member functions
void displayMaze()
{
}
void movePlayer()
{
}
void setPlayer()
{
}
void setTreasure()
{
}
void moveGhosts()
{
}
void setGhosts()
{
}
void setMazeSize()
{
}
Status determineStatus()
{
return CONTINUE;
}
};
-
Please post your compiler errors
-
My compiler errors.
GJ
Code:
In file included from C:\Documents and Settings\Workstation\My Documents\Program6\Program6.cpp:7:
C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h: In constructor `Maze::Maze(char*)':
C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:40: error: expected primary-expression before '[' token
C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:41: error: expected primary-expression before '[' token
C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:42: error: expected primary-expression before '[' token
C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:44: error: expected primary-expression before '[' token
C:\Documents and Settings\Workstation\My Documents\Program6\Program6.cpp: In function `int main()':
C:\Documents and Settings\Workstation\My Documents\Program6\Program6.cpp:28: error: no matching function for call to `Maze::movePlayer(short int&)'
C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:56: note: candidates are: void Maze::movePlayer()
Execution terminated
-
preprocessor directives?
Code:
#ifndef MAZE_H
#define MAZE_H
class Maze{
};
#endif
lets try and go through errors one at a time:
C:\Documents and Settings\Workstation\My Documents\Program6\Program6.cpp:28: error: no matching function for call to `Maze::movePlayer(short int&)'
your definition for movePlayer takes no arguments
also, do yourself a favor and separate your class implementation from your definition. You don't have to, but it is much easier to go through when the implementations are in a separate .cpp (IMO)