Реструктуризация проекта

This commit is contained in:
DeLiss
2026-06-08 08:36:44 +05:00
parent ffca332646
commit 1e7bac87d3
10 changed files with 68 additions and 45 deletions

View File

@@ -123,13 +123,13 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="game.cpp" /> <ClCompile Include="src\game.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="src\main.cpp" />
<ClCompile Include="player.cpp" /> <ClCompile Include="src\player.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="game.h" /> <ClInclude Include="include\game.h" />
<ClInclude Include="player.h" /> <ClInclude Include="include\player.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@@ -15,21 +15,21 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp"> <ClCompile Include="src\game.cpp">
<Filter>Исходные файлы</Filter> <Filter>Исходные файлы</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="game.cpp"> <ClCompile Include="src\main.cpp">
<Filter>Исходные файлы</Filter> <Filter>Исходные файлы</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="player.cpp"> <ClCompile Include="src\player.cpp">
<Filter>Исходные файлы</Filter> <Filter>Исходные файлы</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="game.h"> <ClInclude Include="include\game.h">
<Filter>Исходные файлы</Filter> <Filter>Исходные файлы</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="player.h"> <ClInclude Include="include\player.h">
<Filter>Исходные файлы</Filter> <Filter>Исходные файлы</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>

View File

@@ -7,7 +7,7 @@ public:
private: private:
bool isRunning = true; bool isRunning = true;
Player* player = nullptr; Player player;
void showMainMenu(); void showMainMenu();
void processCommand(); void processCommand();

20
include/player.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include <string>
#include <vector>
class Player {
public:
std::string name = "Character Name";
int hp = 100;
int atk = 1;
int gold = 0;
int currentLocation = 1;
int weaponId = 101;
std::vector<int> items;
Player() {};
Player(std::string _name);
void showStats();
};
#pragma once

0
location.cpp Normal file
View File

17
location.h Normal file
View File

@@ -0,0 +1,17 @@
#pragma once
#include <string>
class Location {
public:
std::string title;
int id;
int sizeX;
int sizeY;
int gold = 0;
Location() {};
Location(std::string _name);
void showStats();
};
#pragma once

View File

@@ -1,15 +0,0 @@
#pragma once
#include <string>
class Player {
public:
std::string name;
int hp;
int atk;
int gold;
Player(std::string _name);
void showStats();
};
#pragma once

View File

@@ -1,5 +1,5 @@
#include "game.h" #include "../include/game.h"
#include "player.h" #include "../include/player.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
@@ -13,7 +13,7 @@ void Game::run() {
void Game::showMainMenu() { void Game::showMainMenu() {
while (true) { while (true) {
std::cout << "\n=== ASCII-G - The Cookies Edition ===\n"; std::cout << "=== ASCII-G - The Cookies Edition ===\n";
std::cout << "1. New Game\n"; std::cout << "1. New Game\n";
std::cout << "2. Load Game\n"; std::cout << "2. Load Game\n";
std::cout << "3. Exit\n"; std::cout << "3. Exit\n";
@@ -23,7 +23,7 @@ void Game::showMainMenu() {
std::getline(std::cin, str); std::getline(std::cin, str);
if (str.length() != 1) { if (str.length() != 1) {
std::cout << "It seems you've tried to input more than 1 digit... Just don't do this please!\n"; std::cout << "It seems you've tried to input more than 1 digit... Don't do this please.\n";
continue; continue;
} }
@@ -31,27 +31,33 @@ void Game::showMainMenu() {
if (select == '1') { if (select == '1') {
std::string name; std::string name;
std::cout << "Enter your character name: "; std::cout << ">>> Enter your character name: ";
std::cin >> name; std::getline(std::cin, name);
player = new Player(name); if (name == "") {
std::cout << "Created new character " << player->name << "! Amazing choice."; std::cout << ">>> Empty name? Damn... let's call you Zero!\n";
player = Player("Zero");
}
else {
player = Player(name);
}
std::cout << ">>> Created new character " << player.name << "!";
break; break;
} }
else if (select == '2') { else if (select == '2') {
std::cout << "I can't do this... yet."; std::cout << ">>> I can't do this... yet.";
} }
else if (select == '3') { else if (select == '3') {
isRunning = false; isRunning = false;
break; break;
} }
else { else {
std::cout << "I can't do this... yet? Let's try again!"; std::cout << ">>> I can't do this... yet? Let's try again!";
} }
} }
} }
void Game::render() { void Game::render() {
std::cout << "\n=== ASCII-G - The Cookies Edition ===\n"; std::cout << "\n\n=== ASCII-G - The Cookies Edition ===\n";
std::cout << "Commands: stats, exit\n"; std::cout << "Commands: stats, exit\n";
} }
@@ -64,12 +70,7 @@ void Game::processCommand() {
isRunning = false; isRunning = false;
} }
else if (command == "stats") { else if (command == "stats") {
if (player != nullptr) { player.showStats();
player->showStats();
}
else {
std::cout << "No character created yet.\n";
}
} }
else { else {
std::cout << "Unknown command.\n"; std::cout << "Unknown command.\n";

View File

@@ -1,4 +1,4 @@
#include "Game.h" #include "../include/game.h"
int main() { int main() {
Game game; Game game;

View File

@@ -1,4 +1,4 @@
#include "player.h" #include "../include/player.h"
#include <iostream> #include <iostream>
Player::Player(std::string _name) Player::Player(std::string _name)