次のエラーの処理に問題があります。
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();
};