0
我需要在其他類的粒子中包含兩個類:Maze和Screen。我需要他們來實現moveEast操作。 迷宮是一個隨機生成的迷宮和屏幕有我要畫人物的屏幕的分辨率。我使用的是opengl和glut。在另一個類中使用類
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
的想法是,我有稱爲米(迷宮)這些全局變量,S(屏幕)和p(吃豆子,這是另一種類),在main.cpp中。編號需要調用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[]){
...
}
任何想法將apreciated。
我們可以看到的內容maze.h,screen.h?你有沒有在這兩個中包含particle.h?如果你在屏幕或迷宮的類定義中使用了粒子對象,那麼你有一個雙重包含,這將是你的問題的原因? – Dese
什麼是'Screen'聲明? particle.h能看到它嗎?它可能在命名空間嗎? – Unimportant
看起來像編譯文件Ghost.cpp時遇到問題,所以我認爲我們需要看到的是您的Ghost.h/.cpp –