Correct field's initialization

This commit is contained in:
2025-07-07 02:33:19 +03:00
parent d4d3ade78b
commit f13bf95ba2
11 changed files with 265 additions and 14 deletions

5
include/BattleCap.h Normal file
View File

@@ -0,0 +1,5 @@
// или включаемые файлы для конкретного проекта.
#pragma once
// TODO: установите здесь ссылки на дополнительные заголовки, требующиеся для программы.

29
include/Game.h Normal file
View File

@@ -0,0 +1,29 @@
#pragma once
#include "Player.h"
#include <cstdlib>
#include <iostream>
constexpr auto SIZE = 10;
constexpr auto SIZE_FOR_ARRAY = SIZE - 1;
class Game {
private:
char field[SIZE][SIZE];
std::unique_ptr<Player[]> gamers;
public:
Game() : gamers(std::make_unique<Player[]>(2)) {
for (int i = 0; i < SIZE; ++i) {
for (int j = 0; j < SIZE; ++j) {
field[i][j] = '*';
}
}
};
void info();
void init();
void play();
private:
void clearScreen();
void print_field();
};

14
include/Infantry.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include "Soldier.h"
class Infantry : public Soldier {
public:
Infantry() : Soldier() {};
int step() override
{
return 10;
}
void fire() override
{
return;
}
};

21
include/Player.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include <string>
#include <vector>
#include "stdafx.h"
class Player {
private:
char name;
std::vector<std::unique_ptr<Soldier>> army;
double score;
public:
Player() {
score = 0.;
for (auto i = 0; i < 4; ++i) {
army.push_back(std::make_unique<Infantry>());
}
}
std::vector<std::unique_ptr<Soldier>>& get_army() {
return army;
}
};

14
include/Soldier.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
class Soldier {
private:
double HP;
double attack;
double defence;
char type;
protected:
Soldier() : HP(100), attack(1), defence(1) {};
Soldier(double _HP, double _attack, double _defence) : HP(_HP), attack(_attack), defence(_defence) {};
public:
virtual int step() = 0;
virtual void fire() = 0;
};

31
include/stdafx.h Normal file
View File

@@ -0,0 +1,31 @@
#pragma once
#include <iostream>
#include <cstdbool>
#ifdef WINDOWS
#include <conio.h>
#else
#include "curses.h"
#endif // WINDOWS
#include "Soldier.h"
#include "Infantry.h"
#include "Game.h"
#include "Player.h"
enum KEY_CODES
{
ESC_KEY = 27,
UP_KEY = 119,
DOWN_KEY = 115,
LEFT_KEY = 97,
RIGHT_KEY = 100,
ENTER = 13
};
enum CELL_CHARS {
EMPTY_CELL = '*',
CURSOR_CELL = '?',
ENEMY_CELL = 'E',
PLAYER_CELL = 'I'
};