diff --git a/Task2.cpp b/Task2.cpp deleted file mode 100644 index 755f86a9..00000000 --- a/Task2.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Task2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы. -// -#include -using std::cin; -using std::cout; - -void TrapezoidArea() { - int base1 = 0; - int base2 = 0; - int height = 0; - cin >> base1; - cout << "Enter the length of the second base of the trapezoid"; - cin >> base2; - cout << "Enter the length of the trapezoid height"; - cin >> height; - cout << "Trapezoid area:"; - cout << (((base1 + base2)/2) * height); - return; - -} -int main() -{ - cout << "Enter the length of the first base of the trapezoid"; - TrapezoidArea(); -} - -// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки" -// Отладка программы: F5 или меню "Отладка" > "Запустить отладку" - -// Советы по началу работы -// 1. В окне обозревателя решений можно добавлять файлы и управлять ими. -// 2. В окне Team Explorer можно подключиться к системе управления версиями. -// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения. -// 4. В окне "Список ошибок" можно просматривать ошибки. -// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода. -// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл. diff --git a/enemy.png b/enemy.png new file mode 100644 index 00000000..514af0d5 Binary files /dev/null and b/enemy.png differ diff --git a/sem2_RomanovaSofya/miniHW_2.cpp b/sem2_RomanovaSofya/miniHW_2.cpp new file mode 100644 index 00000000..bf168ab6 --- /dev/null +++ b/sem2_RomanovaSofya/miniHW_2.cpp @@ -0,0 +1,235 @@ +// miniHW_2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы. +// + +#include +#include +#include +#include + +// (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_ENEMY 10 + +#define ENERGY_MAX 50 +#define HP_MAX 100 + +#define CELLSIZE_SCREEN 100.f + +enum CellType { + Type_enemy, + Type_Grass, + Type_Hill, + Type_Forest, + Type_Stone, + Type_Sand, + Type_Snow, + Type_Water, + Type_End +}; +enum TextureType { + Texture_Enemy, + Texture_Grass, + Texture_Hill, + Texture_Forest, + Texture_Stone, + Texture_Sand, + Texture_Snow, + Texture_Water, + Texture_Hide, + Texture_Soup, + Texture_End +}; + +struct Cell { + bool isEnemy; + 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) { + if (energy <= 0 or hp <= 0) { + return true; + } + return false; +} + +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].isEnemy) { + shapes[x][y].setTexture(&textures[TextureType::Texture_Enemy]); + hp -= 10; + } + 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; + cells[x][y].isEnemy = rand() % 100 < CHANCE_ENEMY; + cells[x][y].cellType = static_cast + (rand() % (CellType::Type_End - 1)); + } + } + + sf::RenderWindow window( + sf::VideoMode({ static_cast (CELLSIZE_SCREEN * CELLSIZE_M), + static_cast (CELLSIZE_SCREEN * CELLSIZE_N) }), + "NOT MINESWEEPER GAME", sf::State::Windowed); + sf::Vector2i mouseCoord; + + sf::Font font("arial.ttf"); + sf::Text textEnergy(font); + sf::Text textCondition(font); + sf::Text textHp(font); + textEnergy.setCharacterSize(CELLSIZE_SCREEN / 2); + textEnergy.setFillColor(sf::Color::Red); + textEnergy.setStyle(sf::Text::Bold | sf::Text::Underlined); + textCondition.setCharacterSize(CELLSIZE_SCREEN); + textCondition.setFillColor(sf::Color::Red); + textCondition.setStyle(sf::Text::Bold | sf::Text::Underlined); + textHp.setCharacterSize(CELLSIZE_SCREEN / 2); + textHp.setStyle(sf::Text::Bold | sf::Text::Underlined); + textHp.setFillColor(sf::Color::Green); + sf::RectangleShape shapes[CELLSIZE_M][CELLSIZE_N]; + sf::Texture textures[TextureType::Texture_End]; + textures[TextureType::Texture_Enemy] = sf::Texture("enemy.png"); + 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"); + + + 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()) + window.close(); + + if (const auto* keyPressed = event->getIf()) { + 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(std::to_wstring(energy)); + textHp.setString(L"\n" + std::to_wstring(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(textHp); + window.draw(textEnergy); + window.draw(textCondition); + window.display(); + } +} + + +// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки" +// Отладка программы: F5 или меню "Отладка" > "Запустить отладку" + +// Советы по началу работы +// 1. В окне обозревателя решений можно добавлять файлы и управлять ими. +// 2. В окне Team Explorer можно подключиться к системе управления версиями. +// 3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения. +// 4. В окне "Список ошибок" можно просматривать ошибки. +// 5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода. +// 6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл. diff --git a/task2.cpp b/task2.cpp deleted file mode 100644 index 398974e9..00000000 --- a/task2.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -void fun(int a) -{ - std::string num = ""; - - while (a > 0) - { - num = std::to_string(a % 8) + num; - a = a / 8; - } - - std::cout << num; -} - -int main() -{ - int a; - std::cin >> a; - fun(a); -} \ No newline at end of file diff --git "a/\320\235\320\276\320\262\321\213\320\271 \321\202\320\265\320\272\321\201\321\202\320\276\320\262\321\213\320\271 \320\264\320\276\320\272\321\203\320\274\320\265\320\275\321\202.txt" "b/\320\235\320\276\320\262\321\213\320\271 \321\202\320\265\320\272\321\201\321\202\320\276\320\262\321\213\320\271 \320\264\320\276\320\272\321\203\320\274\320\265\320\275\321\202.txt" new file mode 100644 index 00000000..e69de29b