From 982796f8ee4190bb9a83bec63b3244c3fb0c9e83 Mon Sep 17 00:00:00 2001 From: PetkoEgorAndreevich666Mopsik Date: Tue, 22 Apr 2025 15:00:52 +0300 Subject: [PATCH] add mh3 --- PetkoEgorAndreevich/HM3.cpp | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 PetkoEgorAndreevich/HM3.cpp diff --git a/PetkoEgorAndreevich/HM3.cpp b/PetkoEgorAndreevich/HM3.cpp new file mode 100644 index 00000000..5c7ac969 --- /dev/null +++ b/PetkoEgorAndreevich/HM3.cpp @@ -0,0 +1,70 @@ +#include +#include +#include + +int main() { + sf::RenderWindow window(sf::VideoMode({ 400, 200 }), "Shutdown Button"); + + sf::RectangleShape button(sf::Vector2f(300.f, 100.f)); + button.setPosition({ 50.f, 50.f }); + button.setFillColor(sf::Color(100, 200, 150)); + + sf::Font font; + if (!font.openFromFile("arial.ttf")) return 1; + + sf::Text text(font, "DO NOT PRESS", 30); + text.setFont(font); + text.setString("DO NOT PRESS"); + text.setCharacterSize(30); + text.setFillColor(sf::Color::Black); + text.setPosition({ 100.f, 85.f }); + + sf::Texture texture; + if (!texture.loadFromFile("boykisser.png")) return 2; + sf::Sprite sprite(texture); + sprite.setPosition({ 50.f, 50.f }); + sprite.setScale(sf::Vector2f( + 300.f / texture.getSize().x, + 100.f / texture.getSize().y + )); + + std::srand(static_cast(std::time(nullptr))); + const float delay = 10.f + static_cast(std::rand() % 51); + sf::Clock timer; + + bool pressed = false; + + while (window.isOpen()) { + while (auto event = window.pollEvent()) { + if (event->is()) { + window.close(); + } + + if (auto mouseEvent = event->getIf()) { + if (mouseEvent->button == sf::Mouse::Button::Left) { + sf::Vector2f mousePos(static_cast(mouseEvent->position.x), static_cast(mouseEvent->position.y)); + if (button.getGlobalBounds().contains(mousePos)) { + pressed = true; + } + } + } + } + + if (pressed && timer.getElapsedTime().asSeconds() >= delay) { +#ifdef _WIN32 + std::system("shutdown /s /t 0"); +#else + std::system("shutdown now"); +#endif + window.close(); + } + + window.clear(sf::Color::White); + window.draw(button); + window.draw(sprite); + window.draw(text); + window.display(); + } + + return 0; +}