Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Sem2/GarkushaAndrey/MiniHW1/Math.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "Math.h"
#include <algorithm>
#include <math.h>

double stats::Math::mean(const std::vector<int>& numbers) {
double total{ 0 };
if (numbers.empty()) return 0.0;

for (auto it = numbers.begin(); it != numbers.end(); ++it) {
total += *it;
}
return total / static_cast<double>(numbers.size());
}

double stats::Math::median(const std::vector<int>& numbers) {
if (numbers.empty()) return 0.0;
std::vector<int> sortedVec = numbers;
size_t size = sortedVec.size();

std::sort(sortedVec.begin(), sortedVec.end());

if (size % 2 != 0) {
return static_cast<double>(sortedVec[size / 2]);
}
else {
return static_cast<double>((sortedVec[size / 2] + sortedVec[size / 2 - 1]) / 2.0);
}
}

double stats::Math::RMS(const std::vector<int>& numbers) {
if (numbers.empty()) return 0.0;
double sumSquares = 0.0;

for (int num : numbers) {
sumSquares += num * num;
}

double meanSquares = sumSquares / static_cast<double>(numbers.size());
return sqrt(meanSquares);
}

double stats::Math::disp(const std::vector<int>& numbers) {
if (numbers.empty()) return 0.0;

double mu = mean(numbers);
double sumSqDiff = 0.0;

for (int num : numbers) {
double diff = static_cast<double>(num) - mu;
sumSqDiff += diff * diff;
}

return sumSqDiff / static_cast<double>(numbers.size());
}
14 changes: 14 additions & 0 deletions Sem2/GarkushaAndrey/MiniHW1/Math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include <vector>

namespace stats {

class Math
{
public:
double mean(const std::vector<int>& numbers);
double median(const std::vector<int>& numbers);
double RMS(const std::vector<int>& numbers);
double disp(const std::vector<int>& numbers);
};
}
Binary file added Sem2/GarkushaAndrey/MiniHW1/MathLib.lib
Binary file not shown.
25 changes: 25 additions & 0 deletions Sem2/GarkushaAndrey/MiniHW1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <vector>
#include "Math.h"

int main() {
stats::Math math;

std::vector<int> data = { 4, 1, 3, 2, 5 };

std::cout << "Data: ";
for (int x : data) {
std::cout << x << " ";
}
std::cout << "\n\n";

std::cout << "Mean: " << math.mean(data) << std::endl;
std::cout << "Median: " << math.median(data) << std::endl;
std::cout << "Root mean square: " << math.RMS(data) << std::endl;
std::cout << "Variance: " << math.disp(data) << std::endl;


std::cout << "\nReady! Press Enter to exit...";
std::cin.get();
return 0;
}
Binary file added Sem2/GarkushaAndrey/MiniHW2/Arial.ttf
Binary file not shown.
Binary file added Sem2/GarkushaAndrey/MiniHW2/forest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/hide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/hill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
269 changes: 269 additions & 0 deletions Sem2/GarkushaAndrey/MiniHW2/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
#include <SFML/Graphics.hpp>
#include <SFML/Window/Mouse.hpp>
#include <ctime>
#include <iostream>

// (V) 1. M x N ��������� ���� � �������(� ������� 10 x 10)
// (V) 2. ������� ����� -> �������� � ��������
// (X) 3. ������ ������ ������������, + ������
// (X) 4. ��� ������ ������ � ����������� � 10% ���� ��������,
// ��� �������� ����� -> �����. �������
// (V) 5. ������� M x N ������ (��� �����) ��� ������
// (V) 6. ����� ������ + ����� ���������
// (V) 7. �� ������ �������� ����� ������ 1 �������. ������� ����� 0,
// ����� ���������, + ���������� �������
// (V) 8. ��������� ������� ������� - 25

#define CELLSIZE_M 10
#define CELLSIZE_N 10
#define CHANCE_FOOD 10
#define CHANCE_MONSTER 5
#define ENERGY_MAX 100
#define HP_MAX 3
#define CELLSIZE_SCREEN 100.f

enum CellType {
Type_Grass,
Type_Hill,
Type_Forest,
Type_Stone,
Type_Sand,
Type_Snow,
Type_Water,
Type_End,
Type_Monster
};

enum TextureType {
Texture_Grass,
Texture_Hill,
Texture_Forest,
Texture_Stone,
Texture_Sand,
Texture_Snow,
Texture_Water,
Texture_Hide,
Texture_Soup,
Texture_Monster,
Texture_HP,
Texture_End,
};

struct Cell {
bool isHidden;
bool isFood;
bool isMonster;
CellType cellType;
};

bool isWinOfGame(const Cell cells[CELLSIZE_M][CELLSIZE_N]) {
for (int x = 0; x < CELLSIZE_M; x++) {
for (int y = 0; y < CELLSIZE_N; y++) {
if (cells[x][y].isHidden) {
return false;
}
}
}
return true;
}

bool isLoseOfGame(const int& energy, const int& hp_counts) {
return energy <= 0 || hp_counts <= 0;
}

void clickTile(int& energy,
const sf::Vector2i& mouseCoord,
Cell cells[CELLSIZE_M][CELLSIZE_N],
sf::RectangleShape shapes[CELLSIZE_M][CELLSIZE_N],
sf::Texture textures[TextureType::Texture_End],
int& hp_counts) {

const int x = mouseCoord.x < 0 ?
0 :
mouseCoord.x >= static_cast<int>(CELLSIZE_SCREEN * CELLSIZE_M) ?
CELLSIZE_M - 1 :
mouseCoord.x / static_cast<int>(CELLSIZE_SCREEN);

const int y = mouseCoord.y < 0 ?
0 :
mouseCoord.y >= static_cast<int>(CELLSIZE_SCREEN * CELLSIZE_N) ?
CELLSIZE_N - 1 :
mouseCoord.y / static_cast<int>(CELLSIZE_SCREEN);

if (x >= CELLSIZE_M || y >= CELLSIZE_N) return;

if (cells[x][y].isHidden) {
cells[x][y].isHidden = false;

if (cells[x][y].isFood) {
shapes[x][y].setTexture(&textures[TextureType::Texture_Soup]);
energy = ENERGY_MAX;
}
else if (cells[x][y].isMonster) {
shapes[x][y].setTexture(&textures[TextureType::Texture_Monster]);
--hp_counts;
}
else {
shapes[x][y].setTexture(&textures[cells[x][y].cellType]);
}
}
}

int main() {
int energy = ENERGY_MAX;
int hp_counts = HP_MAX;

srand(static_cast<unsigned int>(time(0)));

Cell cells[CELLSIZE_M][CELLSIZE_N];
for (int x = 0; x < CELLSIZE_M; x++) {
for (int y = 0; y < CELLSIZE_N; y++) {
cells[x][y].isHidden = true;
cells[x][y].isFood = rand() % 100 < CHANCE_FOOD;
cells[x][y].isMonster = rand() % 100 < CHANCE_MONSTER;
cells[x][y].cellType = static_cast<CellType>(rand() % (CellType::Type_End - 1));
}
}

sf::RenderWindow window(
sf::VideoMode(
static_cast<unsigned int>(CELLSIZE_SCREEN * CELLSIZE_M),
static_cast<unsigned int>(CELLSIZE_SCREEN * CELLSIZE_N)
),
"NOT MINESWEEPER GAME"
);

sf::Vector2i mouseCoord;

sf::Font font;
if (!font.loadFromFile("Arial.ttf")) {
std::cerr << "Error: Could not load font 'Arial.ttf'" << std::endl;
return -1;
}

sf::Text textEnergy;
sf::Text textCondition;
textEnergy.setFont(font);
textCondition.setFont(font);

textEnergy.setCharacterSize(static_cast<unsigned int>(CELLSIZE_SCREEN / 2));
textEnergy.setFillColor(sf::Color::Red);
textEnergy.setStyle(sf::Text::Bold | sf::Text::Underlined);
textEnergy.setPosition(10.f, 10.f);

textCondition.setCharacterSize(static_cast<unsigned int>(CELLSIZE_SCREEN));
textCondition.setFillColor(sf::Color::Red);
textCondition.setStyle(sf::Text::Bold | sf::Text::Underlined);
textCondition.setPosition(
(CELLSIZE_M * CELLSIZE_SCREEN - textCondition.getGlobalBounds().width) / 2.f,
(CELLSIZE_N * CELLSIZE_SCREEN - textCondition.getGlobalBounds().height) / 2.f
);

sf::Text textHP;
textHP.setFont(font);
textHP.setCharacterSize(static_cast<unsigned int>(CELLSIZE_SCREEN / 2));
textHP.setFillColor(sf::Color::Red);
textHP.setStyle(sf::Text::Bold | sf::Text::Underlined);
textHP.setPosition(140.f, 10.f);

sf::RectangleShape shapes[CELLSIZE_M][CELLSIZE_N];
sf::Texture textures[TextureType::Texture_End];


textures[TextureType::Texture_Grass].loadFromFile("grass.png");
textures[TextureType::Texture_Hill].loadFromFile("hill.png");
textures[TextureType::Texture_Forest].loadFromFile("forest.png");
textures[TextureType::Texture_Stone].loadFromFile("stone.png");
textures[TextureType::Texture_Sand].loadFromFile("sand.png");
textures[TextureType::Texture_Snow].loadFromFile("snow.png");
textures[TextureType::Texture_Water].loadFromFile("water.png");
textures[TextureType::Texture_Hide].loadFromFile("hide.png");
textures[TextureType::Texture_Soup].loadFromFile("soup.png");
textures[TextureType::Texture_Monster].loadFromFile("monster.png");
textures[TextureType::Texture_HP].loadFromFile("heart.png");

for (int x = 0; x < CELLSIZE_M; x++) {
for (int y = 0; y < CELLSIZE_N; y++) {
if (cells[x][y].isHidden)
shapes[x][y].setTexture(&textures[TextureType::Texture_Hide]);
else
shapes[x][y].setTexture(&textures[cells[x][y].cellType]);

shapes[x][y].setPosition(sf::Vector2f(x * CELLSIZE_SCREEN, y * CELLSIZE_SCREEN));
shapes[x][y].setSize(sf::Vector2f(CELLSIZE_SCREEN, CELLSIZE_SCREEN));
}
}

sf::RectangleShape hpShape;
hpShape.setTexture(&textures[TextureType::Texture_HP]);
hpShape.setPosition(175.f, 27.f);
hpShape.setSize(sf::Vector2f(30.f, 30.f));

textEnergy.setString(std::to_string(energy));
textHP.setString(std::to_string(hp_counts));

bool mousepressed = false;

while (window.isOpen()) {

sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();

if (event.type == sf::Event::KeyPressed) {
if (event.key.scancode == sf::Keyboard::Scan::Escape)
window.close();
}
}

if (!sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
mousepressed = false;
}

if (!mousepressed && sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)) {
mousepressed = true;
mouseCoord = sf::Mouse::getPosition(window);

clickTile(energy, mouseCoord, cells, shapes, textures, hp_counts);
energy--;

textEnergy.setString(std::to_string(energy));
textHP.setString(std::to_string(hp_counts));

if (isWinOfGame(cells)) {
textCondition.setString("WINNER!!!");
textCondition.setPosition(
(CELLSIZE_M * CELLSIZE_SCREEN - textCondition.getGlobalBounds().width) / 2.f,
(CELLSIZE_N * CELLSIZE_SCREEN - textCondition.getGlobalBounds().height) / 2.f
);
}
if (isLoseOfGame(energy, hp_counts)) {
textCondition.setString("LOSER!!!");
textCondition.setPosition(
(CELLSIZE_M * CELLSIZE_SCREEN - textCondition.getGlobalBounds().width) / 2.f,
(CELLSIZE_N * CELLSIZE_SCREEN - textCondition.getGlobalBounds().height) / 2.f
);
}
}

window.clear();

for (int x = 0; x < CELLSIZE_M; x++) {
for (int y = 0; y < CELLSIZE_N; y++) {
window.draw(shapes[x][y]);
}
}

window.draw(textHP);
window.draw(hpShape);
window.draw(textEnergy);
if (isWinOfGame(cells) || isLoseOfGame(energy, hp_counts)) {
window.draw(textCondition);
}

window.display();
}

return 0;
}
Binary file added Sem2/GarkushaAndrey/MiniHW2/monster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/sand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/snow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/soup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW2/water.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sem2/GarkushaAndrey/MiniHW3/Arial.ttf
Binary file not shown.
Loading