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

This commit is contained in:
DeLiss
2026-06-11 12:05:36 +05:00
parent cba2274630
commit 5d4940f754
12 changed files with 312 additions and 8 deletions

View File

@@ -1,7 +1,9 @@
#pragma once
#include "player.h"
#include "location.h"
#include "item.h"
#include <vector>
#include <string>
class Game {
public:
@@ -12,10 +14,15 @@ private:
Player player;
std::vector<Location> locations;
std::vector<Item> itemDatabase;
void showMainMenu();
void loadItems();
void loadLocations();
ItemType parseItemType(const std::string& type);
Location* getCurrentLocation();
void render();
@@ -24,5 +31,7 @@ private:
void movePlayer(int dx, int dy);
void handleTile(char tile);
void openChest(Location& location);
bool solveRiddle(Location& location);
};

21
include/inventory.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include <vector>
#include "Item.h"
struct InventorySlot {
int itemId = 0;
int count = 0;
};
class Inventory {
public:
void addItem(int itemId, int count = 1);
bool removeItem(int itemId, int count = 1);
void show(const std::vector<Item>& itemDatabase) const;
bool hasItem(int itemId) const;
private:
std::vector<InventorySlot> items;
};

18
include/item.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include <string>
enum class ItemType {
Potion,
Weapon,
Unknown
};
struct Item {
int id = 0;
std::string name;
std::string description;
ItemType type = ItemType::Unknown;
int heal = 0;
int damage = 0;
};

View File

@@ -9,8 +9,8 @@ struct Point {
struct Chest {
Point pos;
int gold = 0;
bool opened = false;
std::vector<int> itemIds;
};
struct Enemy {

View File

@@ -2,23 +2,27 @@
#include <string>
#include <vector>
#include "location.h"
#include "inventory.h"
#include "item.h"
class Player {
public:
std::string name = "Character Name";
int hp = 100;
int maxHp = 100;
int atk = 10;
int gold = 0;
int currentLocation = 1;
Point position;
int weaponId = 101;
std::vector<int> items;
Inventory inventory;
int equippedWeaponId = 0;
Player() = default;
Player(std::string name);
int getDamage(const std::vector<Item>& itemDatabase) const;
void usePotion(int itemId, const std::vector<Item>& itemDatabase);
void equipWeapon(int itemId, const std::vector<Item>& itemDatabase);
void showStats() const;
};