-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole_render.cpp
More file actions
186 lines (153 loc) · 6.87 KB
/
Copy pathconsole_render.cpp
File metadata and controls
186 lines (153 loc) · 6.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "console_render.h"
#include <cstdlib>
#include <cmath>
#include <iostream>
void ConsoleRenderer::drawGame(const GameMap& map, const EntityManager& entities, int level) {
system("clear");
std::cout << "=== LEVEL " << level << " ===\n";
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
Position pos(x, y);
const MapCell& cell = map.getCell(pos);
char symbol = '.';
if (cell.getType() == MapCell::Type::WALL) symbol = '#';
else if (entities.getPlayer().getPosition().equals(pos)) symbol = 'P';
else if (cell.getType() == MapCell::Type::LOW) symbol = '~';
else if (cell.getType() == MapCell::Type::TRAP) symbol = '^';
for (Enemy* enemy : entities.getEnemies()) {
if (enemy->getPosition().equals(pos)) { symbol = 'E'; break; }
}
for (EnemyTower* tower : entities.getTowers()) {
if (tower->getPosition().equals(pos)) { symbol = 'I'; break; }
}
for (EnemyBuilding* building : entities.getBuildings()) {
if (building->getPosition().equals(pos)) { symbol = 'B'; break; }
}
for (Follower* follower : entities.getFollowers()) {
if (follower->getPosition().equals(pos)) { symbol = 'F'; break; }
}
std::cout << symbol << " ";
}
std::cout << "\n";
}
std::cout << "\n=== Игрок ===\n";
std::cout << entities.getPlayer().getStatusString() << "\n";
std::cout << "\n=== Враги ===\n";
int enemyCount = 0;
for (Enemy* enemy : entities.getEnemies()) {
if (enemy->isAlive()) {
enemyCount++;
std::cout << "Враг " << enemyCount << ": " << enemy->getStatusString() << "\n";
}
}
std::cout << "\n=== Союзники ===\n";
int follCount = 0;
for (Follower* f : entities.getFollowers()) {
if (f->isAlive()) {
follCount++;
std::cout << "Союзник " << follCount << ": " << f->getStatusString() << "\n";
}
}
std::cout << "\n=== Башни ===\n";
for (EnemyTower* tower : entities.getTowers()) {
if (tower->isAlive()) std::cout << tower->getStatusString() << "\n";
}
std::cout << "\nУправление: " << getControlsString() << "\n";
}
std::string ConsoleRenderer::getControlsString() const {
if (!inputHandler) {
return "wasd-движение, t-режим боя, c-заклинание, v-сохранение, q-выход";
}
std::string controls;
const auto& keyBindings = inputHandler->getKeyBindings();
std::map<GameCommand::Type, char> reverseMap;
for (const auto& pair : keyBindings) {
reverseMap[pair.second] = pair.first;
}
auto addControl = [&](GameCommand::Type cmd, const std::string& desc) {
auto it = reverseMap.find(cmd);
if (it != reverseMap.end()) {
if (!controls.empty()) controls += ", ";
controls += char(std::toupper(it->second));
controls += "-";
controls += desc;
}
};
addControl(GameCommand::Type::MOVE_UP, "вверх");
addControl(GameCommand::Type::MOVE_DOWN, "вниз");
addControl(GameCommand::Type::MOVE_LEFT, "влево");
addControl(GameCommand::Type::MOVE_RIGHT, "вправо");
addControl(GameCommand::Type::TOGGLE_COMBAT, "режим боя");
addControl(GameCommand::Type::CAST_SPELL, "заклинание");
addControl(GameCommand::Type::SAVE_GAME, "сохранение");
auto quitIt = reverseMap.find(GameCommand::Type::QUIT);
if (quitIt != reverseMap.end()) {
if (!controls.empty()) controls += ", ";
controls += char(std::toupper(quitIt->second));
controls += "-выход";
}
return controls;
}
void ConsoleRenderer::drawTarget(const GameMap& map, const EntityManager& entities, const Position& cursor, int radius) {
system("clear");
for (int y = 0; y < map.getHeight(); y++) {
for (int x = 0; x < map.getWidth(); x++) {
Position pos(x, y);
char symbol = '.';
bool inRange = false;
const MapCell& cell = map.getCell(pos);
if (cell.getType() == MapCell::Type::WALL) symbol = '#';
else if (cell.getType() == MapCell::Type::LOW) symbol = '~';
else if (cell.getType() == MapCell::Type::TRAP) symbol = '^';
int dist = std::abs(entities.getPlayer().getPosition().getX() - x) +
std::abs(entities.getPlayer().getPosition().getY() - y);
if (dist <= radius) inRange = true;
if (entities.getPlayer().getPosition().equals(pos)) symbol = 'P';
for (Enemy* enemy : entities.getEnemies())
if (enemy->getPosition().equals(pos)) symbol = 'E';
for (Follower* f : entities.getFollowers())
if (f->getPosition().equals(pos)) symbol = 'F';
for (EnemyTower* tower : entities.getTowers())
if (tower->getPosition().equals(pos)) symbol = 'I';
if (cursor.equals(pos)) std::cout << "\033[41m" << symbol << "\033[0m ";
else if (inRange) std::cout << "\033[43m" << symbol << "\033[0m ";
else std::cout << symbol << " ";
}
std::cout << "\n";
}
std::cout << "\nУправление: " << getControlsString() << "\n";
std::cout << "\nВыберите цель: ";
}
void ConsoleRenderer::drawMainMenu() {
system("clear");
std::cout << "=== ГЛАВНОЕ МЕНЮ ===\n";
std::cout << "1. Новая игра\n";
std::cout << "2. Загрузить игру\n";
std::cout << "3. Выйти\n";
std::cout << "Выберите действие: ";
std::cout << std::flush;
}
void ConsoleRenderer::drawLevelUpMenu() {
system("clear");
std::cout << "=== УРОВЕНЬ ПОВЫШЕН ===\n";
std::cout << "1. Увеличить здоровье (+50 HP)\n";
std::cout << "2. Увеличить урон (+30 урона)\n";
std::cout << "3. Увеличить уровень заклинаний\n";
std::cout << "Ваш выбор: ";
}
void ConsoleRenderer::showMessage(const std::string& msg) {
std::cout << msg << "\n";
}
void ConsoleRenderer::deadPlayer() {
system("clear");
std::cout << "Нажмите 1, если хотите начать игру занаво";
std::cout << "Нажмите любую другую клавишу, чтобы выйти";
}
void ConsoleRenderer::showSpells(const PlayerHand& hand) {
std::cout << "=== Заклинания в руке ===\n";
for (int i = 0; i < hand.getSpellCount(); i++) {
ISpell* spell = hand.getSpell(i);
std::cout << i << ". " << spell->getName() << "\n";
}
std::cout << "Выберите заклинание: ";
}