Все мои классы были в одном файле cpp. Теперь я разделил их на несколько, они не работают. Что мне не хватает?C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Гость
 Все мои классы были в одном файле cpp. Теперь я разделил их на несколько, они не работают. Что мне не хватает?

Сообщение Гость »

Код: Выделить всё

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

// Enum for the types of rooms in the dungeon
enum class RoomType { Empty, Monster, Treasure };

class Room {
public:
RoomType type;
vector connectedRooms;

// Constructor to initialize a Room with a given type
Room(RoomType t) : type(t) {}

// Connects this room to another room
void connectTo(Room* other) {
connectedRooms.push_back(other);
other->connectedRooms.push_back(this);
}
};

class EmptyRoom : public Room {
public:
// Constructor for an EmptyRoom, setting its type to Empty
EmptyRoom() : Room(RoomType::Empty) {}

};

class MonsterRoom : public Room {
public:
int monsterHealth = 10;
int monsterAttack = 2;

// Constructor for a MonsterRoom, setting its type to Monster
MonsterRoom() : Room(RoomType::Monster) {}
};

class TreasureRoom : public Room {
public:
// Constructor for a TreasureRoom, setting its type to Treasure
TreasureRoom() : Room(RoomType::Treasure) {}
};

class Dungeon {
public:
vector rooms;

// Constructor to create a Dungeon with a set of rooms
Dungeon() {
// Initializing dungeon with a mix of room types
for (int i = 0; i < 5; i++) {
rooms.push_back(make_unique());
rooms.push_back(make_unique());
rooms.push_back(make_unique());
rooms.push_back(make_unique());
rooms.push_back(make_unique());
rooms.push_back(make_unique());
}
rooms.push_back(make_unique());

// Connecting each room to the next
for (size_t i = 0; i < rooms.size() - 1; ++i) {
rooms[i]->connectTo(rooms[i + 1].get());
}
}
};

class Monk {
public:
string name;
string description;
int healthPoints = 15;
int attackPoints = 3;
Room* currentRoom;

// Constructor for a Monk, initializing name, description, and starting room
Monk(const string& n, const string& d) : name(n), description(d), currentRoom(nullptr) {}

// Moves the Monk to a specified room
void moveToRoom(Room* room) {
currentRoom = room;
string roomType = (currentRoom->type == RoomType::Empty) ? "an Empty" :
(currentRoom->type == RoomType::Monster) ? "a Monster" : "the Treasure";
cout connectedRooms.empty()) {
player.moveToRoom(player.currentRoom->connectedRooms[0]);
}
else {
cout 

Источник: [url]https://stackoverflow.com/questions/78132683/i-had-all-of-my-classes-in-a-single-cpp-file-now-i-have-seperated-them-into-mul[/url]
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»