Error when using static methods

39 Views Asked by At

I am trying to modify the matrix "matriz" from other classes when a certain sprite moves the screen. The errors I get are "Juego is not a class or namespace" and "isVacio, isRompible, etc identifier not found". I tried doing this in a separate class called "Utilidades" but still got the same errors when trying to call the methods. I don't know what to do.

This is the code that has the error(class "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); }

This is the class 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

There are 1 best solutions below

2
Gian Paolo On

Maybe I'm missing something but seems really trivial: You need to split Juego code: class declaration in a Juego.hpp file, member implementation in a Juego.cpp file including previous one.

And then #include your Juego.hpp in files requiring to "know" Juego.

The code you posted for Juego class seems to be in a single file (declaration & implementation), so it seems unlikely you did #include it in another file (and cannot #include it in more than one file, it would give a linker error)