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

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

78
src/game.cpp Normal file
View File

@@ -0,0 +1,78 @@
#include "../include/game.h"
#include "../include/player.h"
#include <iostream>
#include <string>
void Game::run() {
showMainMenu();
while (isRunning) {
render();
processCommand();
}
}
void Game::showMainMenu() {
while (true) {
std::cout << "=== ASCII-G - The Cookies Edition ===\n";
std::cout << "1. New Game\n";
std::cout << "2. Load Game\n";
std::cout << "3. Exit\n";
std::cout << "> ";
std::string str;
std::getline(std::cin, str);
if (str.length() != 1) {
std::cout << "It seems you've tried to input more than 1 digit... Don't do this please.\n";
continue;
}
char select = str[0];
if (select == '1') {
std::string name;
std::cout << ">>> Enter your character name: ";
std::getline(std::cin, name);
if (name == "") {
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;
}
else if (select == '2') {
std::cout << ">>> I can't do this... yet.";
}
else if (select == '3') {
isRunning = false;
break;
}
else {
std::cout << ">>> I can't do this... yet? Let's try again!";
}
}
}
void Game::render() {
std::cout << "\n\n=== ASCII-G - The Cookies Edition ===\n";
std::cout << "Commands: stats, exit\n";
}
void Game::processCommand() {
std::string command;
std::cout << "> ";
std::cin >> command;
if (command == "exit") {
isRunning = false;
}
else if (command == "stats") {
player.showStats();
}
else {
std::cout << "Unknown command.\n";
}
}

8
src/main.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include "../include/game.h"
int main() {
Game game;
game.run();
return 0;
}

17
src/player.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include "../include/player.h"
#include <iostream>
Player::Player(std::string _name)
{
this->name = _name;
hp = 100;
atk = 10;
gold = 0;
}
void Player::showStats() {
std::cout << "\n === " << this->name << "'s STATS ===";
std::cout << "\nHP : " << this->hp;
std::cout << "\nATK : " << this->atk;
std::cout << "\nGOLD : " << this->gold;
}