1
Hello, I have a problem that blow my head off:
I’m making a script in C++ with the goal of making a game. Everything was fine when I ended up in a case that, so I researched, I did not find a solution in the ST. 1º the script, then the problem itself:
#include "stdafx.h"
#include "finish.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <time.h>
#include <random>
#include "enemy.h"
#include "player.h"
using namespace std;
int main() {
finish d;
cout << "Welcome to the most epic game ever!" << "\n\n";
string action;
int rnd;
rnd = d.random_calc(1,2);
switch(rnd){
case 1:
Monster *enm;
enm->Encounter(enm->type);
break;
case 2:
Ninja *enm;
enm->Encounter(enm->type);
break;
}
cout << "Actual life:" /*<<*/ << endl;
Player p(10, 15, enm());
p.actionPrompt(&action, true);
cout << action;
d.end();
}
To not take up too much space, follow the link to the github repository for this project(With all classes, recommend seeing them to make it easier to answer me)
The problem, after all. I have to choose, in the program, between creating one of two classes: "Monster" and "Ninja", both derived from the class "Enemy". Now, I get compilation errors for the created classes because they are created as locales (inside the switch) and cannot be accessed outside the switch.
Please, in case you know, Give me a solution!
Downvoter, could you please explain the reason to Pedro?
– Anthony Accioly