我需要包含两个类:Maze和Screen在其他类粒子中。我需要它们来实现moveEast操作。 迷宫是随机生成的迷宫,屏幕具有我绘制角色的屏幕分辨率。我正在使用opengl和过剩。
ghost.h
#ifndef GHOST_H_
#define GHOST_H_
#include "Particle.h"
namespace RandomMaze {
class Ghost : public particle {
public:
Ghost();
virtual ~Ghost();
void drawGhost();
};
} /* namespace RandomMaze */
#endif /* GHOST_H_ */
ghost.cpp
#include "Ghost.h"
#include "Particle.h"
namespace RandomMaze {
Ghost::Ghost() {
// TODO Auto-generated constructor stubparticle::particle()
state=QUIET;
}
Ghost::~Ghost() {
// TODO Auto-generated destructor stub
}
void Ghost::drawGhost()
{
glColor3f(1,1,1);
glBegin(GL_QUADS);
glVertex2i(x-6,y-6);
glVertex2i(x+6,y-6);
glVertex2i(x+6,y+6);
glVertex2i(x-6,y+6);
glEnd();
}
} /* namespace RandomMaze */
maze.h
#ifndef MAZE_H_
#define MAZE_H_
#include <stdlib.h>
#include <time.h>
#include <set>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <stdexcept>
#include <GL/glut.h>
using namespace std;
//Definimos los posibles estados de una coordenada: WALL ( pared), PASSAGE(pasillo) o VISITED ( visitado)
#define WALL 0
#define PASSAGE 1
#define FOOD 2
#define VISITED 9
#define RATIO 0.4
//Personajes
#define PACMAN 10 //Comecocos, amarillo
#define BLINKY 11 //Fantasma Rojo ( cazador)
#define PINKY 12 //Fantasma Rosa( emboscador)
#define INKY 13 //Fantasma Azul, cian ( caprichoso)
#define POKEY 14 //Fantasma Naranja ( bobo)
namespace RandomMaze {
/** Esta clase genera y gestiona el laberinto del juego. */
class Maze {
//Atributos publicos
public:
int **map;
int rows, columns;
int level;
//Metodos privados
private:
void fillMaze();
void addBorders();
void centerWalls();
void addWalls();
void exploreMaze(int fila, int columna);
void checkWalls(int fila, int columna);
void checkWalls();
bool isConnected();
bool isCenter(int r, int c);
void getaway();
int isWall(int level);
void deleteBrick(int i, int j);
void addFood();
void addPacman();
void addBlinky();
void addPinky();
void addInky();
void addPokey();
//Metodos públicos
public:
Maze();
~Maze(void);
Maze(int filas, int columnas, int level);
double getN();
void setupMaze(int filas, int columnas, int level);
void moveGhost(int fila, int columna);
void printMaze();
void setRows(int filas);
void setColumns(int columnas);
void setLevel(int nivel);
int getRows();
int getColumns();
int getLevel();
int** getMaze();
// Pacman
int getPacmanX();
int getPacmanY();
void setPacman( int x,int j);
//Blinky
int getBlinkyX();
int getBlinkyY();
void setBlinky( int x,int j);
//Pinky
int getPinkyX();
int getPinkyY();
void setPinky( int x,int j);
//INKY
int getInkyX();
int getInkyY();
void setInky( int x,int j);
//POKEY
int getPokeyX();
int getPokeyY();
void setPokey( int x,int j);
void drawMaze(int width, int height);
bool isPassageOrFood( int x, int y);
void deleteFood(int x,int y);
};
} /* namespace RandomMaze */
#endif /* MAZE_H_ */
screen.h
#ifndef SCREEN_H_
#define SCREEN_H_
namespace RandomMaze {
class Screen {
int width;
int height;
public:
Screen();
Screen(int w, int h);
int getWidth();
int getHeight();
virtual ~Screen();
};
} /* namespace RandomMaze */
#endif /* SCREEN_H_ */
particle.h
#include "Maze.h"
#include "Screen.h"
class particle {
protected:
int i,j; // Current position in map
float x,y; //-- Current position
float vx,vy; //-- Velocity vector
int state;
long time_remaining;
public:
particle();
void set_positionScreen(int x,int y);
void set_positionMap(int i,int j);
int get_positionMapI();
int get_positionMapJ();
void moveEast(Maze m, Screen s);
void init_movement(int destination_x,int destination_y,int duration);
void init_movementAlongX(int destination_x,int destination_y,int duration);
void init_movementAlongY(int destination_x,int destination_y,int duration);
void integrate(long t);
int getState();
void draw();
virtual ~particle();
};
错误消息是:
../Particle.h:44:25: error: ‘Screen’ has not been declared
void moveEast(Maze m, Screen s);
^
make: *** [Ghost.o] Error 1
我的想法是,我在main.cpp中有这些全局变量,称为m(迷宫),s(屏幕)和p(pacman,它是另一个类)。我需要用以下内容调用moveEast操作:
Maze m;
Screen s;
Pacman p;
p.moveEast(m,s);
另外我把声明部分放在主文件中。
的main.cpp
#include "Maze.h"
#include "Screen.h"
#include "Particle.h"
#include <vector>
#include "Ghost.h"
#include "Pacman.h"
#define ROWS 19
#define COLUMNS 40
#define LEVEL 5
#define WIDTH 600
#define HEIGHT 400
#define WINDOW_X 50
#define WINDOW_Y 50
//THE TIME THAT CHARACTER TAKES FROM ONE "SCREEN UNIT TO ANOTHER". Pacman is slightly faster than ghosts.
#define PACMAN_SPEED 1
#define GHOST_SPEED 1000
//Se puede utilizar para correccion
#define CORRECTION 6
void display();
void keyboard(unsigned char c,int x,int y);
void specialkeyboard(int key,int x,int y);
void idle();
void goNorth();
void goWest();
void goEast();
void goSouth();
using namespace std;
using namespace RandomMaze;
//Definición de variables.
vector<Ghost> playingGhosts;
Maze m;
Screen s(WIDTH, HEIGHT);
Pacman myPacman;
long last_t=0;
int main (int argc, char *argv[]){
...
}
任何想法都会被贬低。
答案 0 :(得分:0)
Maze
和Screen
都在namespace RandomMaze
,但particle
不在。{/ p>
因此,您需要将particle
移动到该命名空间中,这样您就可以在没有任何限定的情况下引用它们,或者在使用它们时需要对这些名称进行限定 - RandomMaze::Maze
等。