我在处理以下错误时遇到问题:
c2660: c:\users\lukas plaehn\desktop\oop\sokoban\sokoban\main.cpp(126): 错误 C2660: 'CPlayer::moveUp' : 函数不接受 1 个参数
c2061:c:\users\lukas plaehn\desktop\oop\sokoban\sokoban\player.h(10):错误 C2061:语法错误:标识符 'CMaze'
我想要做的是在头文件中将对象作为参数传递。我也尝试过通过引用来做,但它不起作用。不知何故,编译器不允许我CMaze
在头文件中声明任何类型的内容CPlayer
。
class CPlayer:public CBlocks
{
public:
CMaze * m;
CPlayer(void);
CPlayer(char sym, int x, int y, CMaze mz);
~CPlayer(void);
void moveUp(CMaze maze);
void moveDown(CMaze maze);
void moveLeft(CMaze maze);
void moveRight(CMaze maze);
};
#include "Player.h"
#include "Maze.h"
//#include "headers.h"
CPlayer::CPlayer(void)
{
}
CPlayer::CPlayer(char sym, int x, int y, CMaze mz)
{
m = &mz;
m_symbol = sym;
m_x = x;
m_y = y;
}
CPlayer::~CPlayer(void)
{
}
void CPlayer::moveDown(CMaze maze)
{
if(m->arr[m_y+1][m_x].m_symbol == ' ')
{
m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(m->arr[m_y+1][m_x].m_symbol == '#')
{
cout << "You cannot perform this move!"<<endl;
}
else if(m->arr[m_y+1][m_x].m_symbol == '$')
{
if(m->arr[m_y+2][m_x].m_symbol == ' ')
{
m->arr[m_y+2][m_x] = m->arr[m_y+1][m_x];
m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(m->arr[m_y+2][m_x].m_symbol == '.')
{
m->arr[m_y+2][m_x] = m->arr[m_y+1][m_x];
m->arr[m_y+2][m_x].m_symbol = '*';
m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(m->arr[m_y+2][m_x].m_symbol == '$')
{
cout << "You cannot perform this move!" << endl;
}
else if(m->arr[m_y+2][m_x].m_symbol == '#')
{
cout << "You cannot perform this move!" << endl;
}
else if(m->arr[m_y+2][m_x].m_symbol == '*')
{
cout << "You cannot perform this move!" << endl;
}
else
{
cout << "Unkown Error Occurred" << endl;
}
}
else if(m->arr[m_y+1][m_x].m_symbol == '.')
{
m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
m->arr[m_y+1][m_x].m_symbol = '+';
}
else if(m->arr[m_y+1][m_x].m_symbol == '*')
{
if(m->arr[m_y+2][m_x].m_symbol == ' ')
{
m->arr[m_y+2][m_x] = m->arr[m_y+1][m_x];
m->arr[m_y+2][m_x].m_symbol = '$';
m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
m->arr[m_y+1][m_x].m_symbol = '+';
m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(m->arr[m_y+2][m_x].m_symbol == '.')
{
m->arr[m_y+2][m_x] = m->arr[m_y+1][m_x];
m->arr[m_y+1][m_x] = m->arr[m_y][m_x];
m->arr[m_y+1][m_x].m_symbol = '+';
m->arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(m->arr[m_y+2][m_x].m_symbol == '$')
{
cout << "You cannot perform this move!" << endl;
}
else if(m->arr[m_y+2][m_x].m_symbol == '#')
{
cout << "You cannot perform this move!" << endl;
}
else if(m->arr[m_y+2][m_x].m_symbol == '*')
{
cout << "You cannot perform this move!" << endl;
}
else
{
cout << "Unkown Error Occurred" << endl;
}
}
}
void CPlayer::moveUp(CMaze maze)
{
if(maze.arr[m_y-1][m_x].m_symbol == ' ')
{
maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y-1][m_x].m_symbol == '#')
{
cout << "You cannot perform this move!"<<endl;
}
else if(maze.arr[m_y-1][m_x].m_symbol == '$')
{
if(maze.arr[m_y-2][m_x].m_symbol == ' ')
{
maze.arr[m_y-2][m_x] = maze.arr[m_y-1][m_x];
maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y-2][m_x].m_symbol == '.')
{
maze.arr[m_y-2][m_x] = maze.arr[m_y-1][m_x];
maze.arr[m_y-2][m_x].m_symbol = '*';
maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y-2][m_x].m_symbol == '$')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y-2][m_x].m_symbol == '#')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y-2][m_x].m_symbol == '*')
{
cout << "You cannot perform this move!" << endl;
}
else
{
cout << "Unkown Error Occurred" << endl;
}
}
else if(maze.arr[m_y-1][m_x].m_symbol == '.')
{
maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
maze.arr[m_y-1][m_x].m_symbol = '+';
}
else if(maze.arr[m_y-1][m_x].m_symbol == '*')
{
if(maze.arr[m_y-2][m_x].m_symbol == ' ')
{
maze.arr[m_y-2][m_x] = maze.arr[m_y-1][m_x];
maze.arr[m_y-2][m_x].m_symbol = '$';
maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
maze.arr[m_y-1][m_x].m_symbol = '+';
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y-2][m_x].m_symbol == '.')
{
maze.arr[m_y-2][m_x] = maze.arr[m_y-1][m_x];
maze.arr[m_y-1][m_x] = maze.arr[m_y][m_x];
maze.arr[m_y-1][m_x].m_symbol = '+';
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y-2][m_x].m_symbol == '$')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y-2][m_x].m_symbol == '#')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y-2][m_x].m_symbol == '*')
{
cout << "You cannot perform this move!" << endl;
}
else
{
cout << "Unkown Error Occurred" << endl;
}
}
}
void CPlayer::moveLeft(CMaze maze)
{
if(maze.arr[m_y][m_x-1].m_symbol == ' ')
{
maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x-1].m_symbol == '#')
{
cout << "You cannot perform this move!"<<endl;
}
else if(maze.arr[m_y][m_x-1].m_symbol == '$')
{
if(maze.arr[m_y][m_x-2].m_symbol == ' ')
{
maze.arr[m_y][m_x-2] = maze.arr[m_y][m_x-1];
maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x-1].m_symbol == '.')
{
maze.arr[m_y][m_x-2] = maze.arr[m_y][m_x-1];
maze.arr[m_y][m_x-2].m_symbol = '*';
maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x-2].m_symbol == '$')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y][m_x-2].m_symbol == '#')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y][m_x-2].m_symbol == '*')
{
cout << "You cannot perform this move!" << endl;
}
else
{
cout << "Unkown Error Occurred" << endl;
}
}
else if(maze.arr[m_y][m_x-1].m_symbol == '.')
{
maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
maze.arr[m_y][m_x-1].m_symbol = '+';
}
else if(maze.arr[m_y][m_x-1].m_symbol == '*')
{
if(maze.arr[m_y][m_x-2].m_symbol == ' ')
{
maze.arr[m_y][m_x-2] = maze.arr[m_y][m_x-1];
maze.arr[m_y][m_x-2].m_symbol = '$';
maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x-1].m_symbol = '+';
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x-2].m_symbol == '.')
{
maze.arr[m_y][m_x-2] = maze.arr[m_y][m_x-1];
maze.arr[m_y][m_x-1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x-1].m_symbol = '+';
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x-2].m_symbol == '$')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y][m_x-2].m_symbol == '#')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y][m_x-2].m_symbol == '*')
{
cout << "You cannot perform this move!" << endl;
}
else
{
cout << "Unkown Error Occurred" << endl;
}
}
}
void CPlayer::moveRight(CMaze maze)
{
if(maze.arr[m_y][m_x+1].m_symbol == ' ')
{
maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x+1].m_symbol == '#')
{
cout << "You cannot perform this move!"<<endl;
}
else if(maze.arr[m_y][m_x+1].m_symbol == '$')
{
if(maze.arr[m_y][m_x+2].m_symbol == ' ')
{
maze.arr[m_y][m_x+2] = maze.arr[m_y][m_x+1];
maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x+1].m_symbol == '.')
{
maze.arr[m_y][m_x+2] = maze.arr[m_y][m_x+1];
maze.arr[m_y][m_x+2].m_symbol = '*';
maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x+2].m_symbol == '$')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y][m_x+2].m_symbol == '#')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y][m_x+2].m_symbol == '*')
{
cout << "You cannot perform this move!" << endl;
}
else
{
cout << "Unkown Error Occurred" << endl;
}
}
else if(maze.arr[m_y][m_x+1].m_symbol == '.')
{
maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
maze.arr[m_y][m_x+1].m_symbol = '+';
}
else if(maze.arr[m_y][m_x+1].m_symbol == '*')
{
if(maze.arr[m_y][m_x+2].m_symbol == ' ')
{
maze.arr[m_y][m_x+2] = maze.arr[m_y][m_x+1];
maze.arr[m_y][m_x+2].m_symbol = '$';
maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x+1].m_symbol = '+';
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x+2].m_symbol == '.')
{
maze.arr[m_y][m_x+2] = maze.arr[m_y][m_x+1];
maze.arr[m_y][m_x+1] = maze.arr[m_y][m_x];
maze.arr[m_y][m_x+1].m_symbol = '+';
maze.arr[m_y][m_x] = CSpace(' ', m_x, m_y);
}
else if(maze.arr[m_y][m_x+2].m_symbol == '$')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y][m_x+2].m_symbol == '#')
{
cout << "You cannot perform this move!" << endl;
}
else if(maze.arr[m_y][m_x+2].m_symbol == '*')
{
cout << "You cannot perform this move!" << endl;
}
else
{
cout << "Unkown Error Occurred" << endl;
}
}
}
class CMaze
{
public:
friend class CPlayer;
int m_columns, m_rows;
string line;
CBlocks arr[32][48];
int i, j;
int k, count;
bool m_status;
ifstream mazeStream;
CMaze(void);
~CMaze(void);
void setStatus(CMaze maze);
CBlocks fillCharArr();
void displayMaze();
};