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
21 changes: 21 additions & 0 deletions sem2/Biktagirova_Diana_Rafikovna/minihomework1/MathClient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <iostream>
#include <vector>
#include "MathLibrary.h"

using std::vector;
using std::cout;
using std::endl;

int main() {
vector<double> numbers = { 1.0, 2.1, 3.0, 4.3, 5.0 };

double mean = CalculateMean(numbers);
cout << "Mean: " << mean << endl;
double median = CalculateMedian(numbers);
cout << "Median: " << median << endl;
double quadraticMean = CalculateQuadraticMean(numbers);
cout << "Quadratic Mean: " << quadraticMean << endl;
double variance = CalculateVariance(numbers);
cout << "Variance: " << variance << endl;
return 0;
}
25 changes: 25 additions & 0 deletions sem2/Biktagirova_Diana_Rafikovna/minihomework1/MathLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef MATHLIBRARY_H
#define MATHLIBRARY_H

#include <vector>

#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif

// ������� ��� �������� �������� ���������������
extern "C" MATHLIBRARY_API double CalculateMean(const std::vector<double>& numbers);

// ������� ��� �������� �������
extern "C" MATHLIBRARY_API double CalculateMedian(std::vector<double> numbers);

// ������� ��� �������� �������� ���������������
extern "C" MATHLIBRARY_API double CalculateQuadraticMean(const std::vector<double>& numbers);

// ������� ��� �������� ���������
extern "C" MATHLIBRARY_API double CalculateVariance(const std::vector<double>& numbers);


#endif // MATHLIBRARY_H
62 changes: 62 additions & 0 deletions sem2/Biktagirova_Diana_Rafikovna/minihomework1/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "pch.h"
#include "MathLibrary.h"
#include <algorithm> // для sort
#include <cmath> // для pow и sqrt

using std::sort;
using std::vector;
using std::pow;

// Функция для подсчета среднего арифметического
MATHLIBRARY_API double CalculateMean(const vector<double>& numbers)
{
if (numbers.empty()) return 0.0; // проверка на пустой вектор
double sum = 0.0;
for (double num : numbers)
{
sum += num;
}
return sum / numbers.size();
}

// Функция для подсчета медианы
MATHLIBRARY_API double CalculateMedian(vector<double> numbers)
{
if (numbers.empty()) return 0.0;
sort(numbers.begin(), numbers.end()); // Сортируем вектор
size_t n = numbers.size();
if (n % 2 == 0)
{
// если кол-во четное, возвращаем среднее двух средних
return (numbers[n / 2 - 1] + numbers[n / 2]) / 2.0;
}
else
{
// если кол-во нечетное, возвращаем средний элемент
return numbers[n / 2];
}
}

// Функция для подсчета среднего квадратического
MATHLIBRARY_API double CalculateQuadraticMean(const vector<double>& numbers)
{
if (numbers.empty()) return 0.0;
double sumOfSquares = 0.0;
for (double num : numbers) {
sumOfSquares += pow(num, 2);
}
return std::sqrt(sumOfSquares / numbers.size());
}

// Функция для подсчета дисперсии
MATHLIBRARY_API double CalculateVariance(const vector<double>& numbers)
{
if (numbers.empty()) return 0.0;
double mean = CalculateMean(numbers);
double sumOfSquares = 0.0;
for (double num : numbers)
{
sumOfSquares += std::pow(num - mean, 2);
}
return sumOfSquares / numbers.size();
}
236 changes: 236 additions & 0 deletions sem2/Biktagirova_Diana_Rafikovna/minihomework2/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
#include <SFML/Graphics.hpp>
#include <SFML/Window/Mouse.hpp>
#include <ctime>

// (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 ENERGY_MAX 100

#define CELLSIZE_SCREEN 100.f

#define HP_MAX 100

enum CellType {
Type_Grass,
Type_Hill,
Type_Forest,
Type_Stone,
Type_Sand,
Type_Snow,
Type_Water,
Type_Heal,
Type_Monster,
Type_End
};
enum TextureType {
Texture_Grass,
Texture_Hill,
Texture_Forest,
Texture_Stone,
Texture_Sand,
Texture_Snow,
Texture_Water,
Texture_Hide,
Texture_Soup,
Texture_Heal,
Texture_Monster,
Texture_End
};

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

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

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


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

const int x = mouseCoord.x < 0 ?
0 :
mouseCoord.x > CELLSIZE_SCREEN * CELLSIZE_M ?
CELLSIZE_M :
mouseCoord.x / CELLSIZE_SCREEN;

const int y = mouseCoord.y < 0 ?
0 :
mouseCoord.y > CELLSIZE_SCREEN * CELLSIZE_N ?
CELLSIZE_N :
mouseCoord.y / CELLSIZE_SCREEN;

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].cellType == Type_Heal) {
shapes[x][y].setTexture(&textures[TextureType::Texture_Heal]);
hp = std::min(hp + 20, HP_MAX);
}
else if (cells[x][y].cellType == Type_Monster) {
shapes[x][y].setTexture(&textures[TextureType::Texture_Monster]);
hp -= 25;
}
else {
shapes[x][y].setTexture(&textures[cells[x][y].cellType]);
}
}

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

srand(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;

int rnd = rand() % 100;
if (rnd < 2) {
cells[x][y].cellType = Type_Heal;
}
else if (rnd < 5) {
cells[x][y].cellType = Type_Monster;
}
else {
cells[x][y].cellType = static_cast<CellType>(rand() % (Type_End - 2));
}
}
}

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::State::Windowed);
sf::Vector2i mouseCoord;

sf::Font font("arial.ttf");


sf::Text textEnergy(font);
textEnergy.setCharacterSize(CELLSIZE_SCREEN / 2);
textEnergy.setFillColor(sf::Color::Red);
textEnergy.setStyle(sf::Text::Bold | sf::Text::Underlined);
textEnergy.setString("E: " + std::to_string(energy) + " HP: " + std::to_string(hp));

sf::Text textCondition(font);
textCondition.setCharacterSize(CELLSIZE_SCREEN);
textCondition.setFillColor(sf::Color::Red);
textCondition.setStyle(sf::Text::Bold | sf::Text::Underlined);






sf::RectangleShape shapes[CELLSIZE_M][CELLSIZE_N];
sf::Texture textures[TextureType::Texture_End];
textures[TextureType::Texture_Grass] = sf::Texture("grass.png");
textures[TextureType::Texture_Hill] = sf::Texture("hill.png");
textures[TextureType::Texture_Forest] = sf::Texture("forest.png");
textures[TextureType::Texture_Stone] = sf::Texture("stone.png");
textures[TextureType::Texture_Sand] = sf::Texture("sand.png");
textures[TextureType::Texture_Snow] = sf::Texture("snow.png");
textures[TextureType::Texture_Water] = sf::Texture("water.png");
textures[TextureType::Texture_Hide] = sf::Texture("hide.png");
textures[TextureType::Texture_Soup] = sf::Texture("soup.png");
textures[TextureType::Texture_Heal] = sf::Texture("heal.png");
textures[TextureType::Texture_Monster] = sf::Texture("monster.png");


for (int x = 0; x < CELLSIZE_M; x++) {
for (int y = 0; y < CELLSIZE_N; y++) {

// TODO ������� � �� ��������
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({ CELLSIZE_SCREEN, CELLSIZE_SCREEN });
}
}

bool mousepressed = false;
while (window.isOpen()) {

while (const std::optional event = window.pollEvent()) {
if (event->is<sf::Event::Closed>())
window.close();

if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>()) {
if (keyPressed->scancode == sf::Keyboard::Scancode::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, hp, mouseCoord, cells, shapes, textures);
energy--;

textEnergy.setString("E: " + std::to_string(energy) + " HP: " + std::to_string(hp));

if (isWinOfGame(cells))
textCondition.setString("WINNER!!!");
if (isLoseOfGame(energy,hp))
textCondition.setString("LOSER!!!");
}
}

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(textEnergy);
window.draw(textCondition);
window.display();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\\u0423\u0447\u0435\u0431\u0430\\C\u002B\u002B\\2 \u0441\u0435\u043C\\MiniHomeWork3\\MagicButton\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{EE66973F-576F-418E-9930-1D7179F46D53}|MagicButton\\MagicButton.vcxproj|D:\\\u0423\u0447\u0435\u0431\u0430\\C\u002B\u002B\\2 \u0441\u0435\u043C\\MiniHomeWork3\\MagicButton\\MagicButton\\main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
"RelativeMoniker": "D:0:0:{EE66973F-576F-418E-9930-1D7179F46D53}|MagicButton\\MagicButton.vcxproj|solutionrelative:MagicButton\\main.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 0,
"Children": [
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "main.cpp",
"DocumentMoniker": "D:\\\u0423\u0447\u0435\u0431\u0430\\C\u002B\u002B\\2 \u0441\u0435\u043C\\MiniHomeWork3\\MagicButton\\MagicButton\\main.cpp",
"RelativeDocumentMoniker": "MagicButton\\main.cpp",
"ToolTip": "D:\\\u0423\u0447\u0435\u0431\u0430\\C\u002B\u002B\\2 \u0441\u0435\u043C\\MiniHomeWork3\\MagicButton\\MagicButton\\main.cpp*",
"RelativeToolTip": "MagicButton\\main.cpp*",
"ViewState": "AgIAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
"WhenOpened": "2025-06-07T17:10:28.945Z",
"EditorCaption": ""
}
]
}
]
}
]
}
Loading