使用静态方法时出错

时间:2015-11-22 19:34:15

标签: c++ visual-c++ system.drawing visual-c++-2012

我正在尝试修改矩阵" matriz"某个精灵移动屏幕时来自其他类。我得到的错误是" Juego不是一个类或命名空间"和" isVacio,isRompible等标识符未找到"。我尝试在另一个名为" Utilidades"但在尝试调用方法时仍然遇到相同的错误。我不知道该怎么做。

这是有错误的代码(类" Bomba"):

    if (Juego::isVacio(x - 35, y)){ /*Sprite explosion*/}
if (Juego::isVacio(x + 35, y)){/*Sprite explosion*/ }
if (Juego::isVacio(x, y + 35)){/*Sprite explosion*/ }
if (Juego::isVacio(x, y - 35)){/*Sprite explosion*/ }
if (x - 35 < 35 || x + 35 > gr->VisibleClipBounds.Width - 35 || Juego::isBloque(x + 35, y) || Juego::isBloque(x - 35, y)){}
if (y - 35 < 35 || y + 35 > gr->VisibleClipBounds.Height - 35 || Juego::isBloque(x, y + 35) || Juego::isBloque(x, y - 35)){}
if (Juego::Juego::isRompible(x - 35, y)){ Juego::romperBloque(x - 35, y, gr); }
if (Juego::isRompible(x + 35, y)){ Juego::romperBloque(x + 35, y, gr); }
if (Juego::isRompible(x, y + 35)){ Juego::romperBloque(x, y + 35, gr); }
if (Juego::isRompible(x, y - 35)){ Juego::romperBloque(x, y - 35, gr); }
//2bloques
if (Juego::isVacio(x - 70, y)){/*Sprite explosion*/ }
if (Juego::isVacio(x + 70, y)){/*Sprite explosion*/ }
if (Juego::isVacio(x, y + 70)){/*Sprite explosion*/ }
if (Juego::isVacio(x, y - 70)){/*Sprite explosion*/ }
if (x - 70 < 35 || x + 70 > gr->VisibleClipBounds.Width - 35 || Juego::isBloque(x + 70, y) || Juego::isBloque(x - 70, y)){}
if (y - 70 < 35 || y + 70 > gr->VisibleClipBounds.Height - 35 || Juego::isBloque(x, y + 70) || Juego::isBloque(x, y - 70)){}
if (Juego::isRompible(x - 70, y)){ Juego::romperBloque(x - 70, y, gr); }
if (Juego::isRompible(x + 70, y)){ Juego::romperBloque(x + 70, y, gr); }
if (Juego::isRompible(x, y + 70)){ Juego::romperBloque(x, y + 70, gr); }
if (Juego::isRompible(x, y - 70)){ Juego::romperBloque(x, y - 70, gr); }
//3bloques
if (Juego::isVacio(x - 105, y)){}
if (Juego::isVacio(x +105, y)){}
if (Juego::isVacio(x, y + 105)){}
if (Juego::isVacio(x, y - 105)){}
if (x - 105 < 35 || x + 105 > gr->VisibleClipBounds.Width - 35 || Juego::isBloque(x + 105, y) || Juego::isBloque(x-105, y)){}
if (y - 105 < 35 || y + 105 > gr->VisibleClipBounds.Height - 35 || Juego::isBloque(x, y + 105) || Juego::isBloque(x, y - 105)){}
if (Juego::isRompible(x - 105, y)){ Juego::romperBloque(x - 105, y, gr); }
if (Juego::isRompible(x + 105, y)){ Juego::romperBloque(x + 105, y, gr); }
if (Juego::isRompible(x, y + 105)){ Juego::romperBloque(x, y + 105, gr); }
if (Juego::isRompible(x, y - 105)){ Juego::romperBloque(x, y - 105, gr); }

这是Juego班:

#pragma once

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <fstream>
#include "Jugador.h"
#include "Enemigo.h"
#include "Bomba.h"


using namespace std;


class Juego
{
    int nivel;
    EntidadViva* objJugador;
    //Enemigo* objEnemigo;
public:
    static bool isBloque(int px, int py);
    static bool isRompible(int px, int py);
    static bool isBomba(int px, int py);
    static bool isVacio(int px, int py);
    static void romperBloque(int px, int py, Graphics^ gr);
    static int ** matriz;
    static std::vector<Bomba*> bombas;
    ~Juego(void);
    Juego(void);
    void setDireccion_Jugador(Direccion dir);
    void Crear_Enemigo(int px, int py);
    void Crear_Jugador(int px, int py);
    void Mover_Entidades(Graphics^ gr);
    void Perseguir();
    Jugador* getJugador();
    int getNivel();
    void setNivel(int n);
    void cargarMatriz();
    void addBomba(Bomba* b);
    Point getPrimeraPosicionJugador();
};
/*---------------------Utilidades---------------*/
        //Check de bloque//
bool Juego::isBloque(int px, int py)
{
    if (matriz[px][py] == 0 || matriz[px][py] == 1)
    {
        return true;
    }
    else
    {
        return false;
    }
}
     // Check de rompible//
bool Juego::isRompible(int px, int py)
{
    if (matriz[px][py] == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
    // Check de bomba//
bool Juego::isBomba(int px, int py)
{
    for each(Bomba* bmb in bombas)
    {
        if (bmb->getX() == px && bmb->getY() == py)
        {
            return true;
        }
    }
    return false;
}

        //Rompe un bloque rompible//
void Juego::romperBloque(int px, int py, Graphics^ gr)
{
    matriz[px][py] = 3;
    //Animacion de explosion del bloque

}
    // Check de Vacio//
bool Juego::isVacio(int px, int py)
{
    if (matriz[px][py] == 3){ return true; }
    else{ return false; }
}

void Juego::addBomba(Bomba* b)
{
    bombas.push_back(b);
}
void Juego::cargarMatriz()
{
    ifstream fin;

    fin.open("Level1.txt");


    matriz = new int *[23];

    for (int i = 0; i < 23; i++)
    {
        matriz[i] = new int[23];
    }

    for (int i = 0; i < 23; i++)
    {
        for (int j = 0; j < 23; j++)
        {
            fin >> matriz[i][j];
        }
    }
}
void Juego::setNivel(int n){ nivel = n; }
int Juego::getNivel(){ return nivel; }
Juego::~Juego(void)
{
    delete objJugador;
    //delete objEnemigo;
}
Jugador* Juego::getJugador(){ return (Jugador*)objJugador; }
Juego::Juego(void)
{
    nivel = 1;
    cargarMatriz();
    //Crear_Enemigo(10, 10);
    Point p = this->getPrimeraPosicionJugador();
    Crear_Jugador(50, 50);
}
void Juego::setDireccion_Jugador(Direccion dir)
{
    objJugador->setMovimiento(dir);
    switch (dir)
    {
    case ABAJO:
        objJugador->setDx(0); objJugador->setDy(5);
        break;
    case ARRIBA:
        objJugador->setDx(0); objJugador->setDy(-5);
        break;
    case DERECHA:
        objJugador->setDx(5); objJugador->setDy(0);
        break;
    case IZQUIERDA:
        objJugador->setDx(-5); objJugador->setDy(0);
        break;
    }
}
Point Juego::getPrimeraPosicionJugador()
{
    for (int x = 0; x < 23; x++)
    {
        for (int y = 0; y < 23; y++)
        {
            if (matriz[x][y == 5])
            {
                return Point(x, y);
            }
        }
    }
}
void Juego::Crear_Jugador(int px, int py)
{
    objJugador = new Jugador(px, py);
}
void Juego::Crear_Enemigo(int px, int py)
{
    //objEnemigo = new Enemigo(px, py);
}
void Juego::Mover_Entidades(Graphics^ gr)
{
    //((Enemigo*)objEnemigo)->Mover(gr);
    ((Jugador*)objJugador)->Mover(gr);
}

1 个答案:

答案 0 :(得分:0)

也许我错过了一些东西,但看起来真的很琐碎: 你需要拆分Juego代码:Juego.hpp文件中的类声明,Juego.cpp文件中的成员实现,包括前一个。

然后#include你的Juego.hpp在需要&#34;知道&#34;的文件中。 JUEGO。

您为Juego类发布的代码似乎是在一个文件中(声明和实现),因此您似乎不太可能在另一个文件中#include它(并且不能在多个文件中包含它,它会给出链接器错误)