Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
3.7 kB
2
Indexable
Never
#include <random>
#include <Windows.h>
#include <string>
#include <Mmdeviceapi.h>
#include <Endpointvolume.h>
#include <fstream>
#include <iostream>





BOOL ChangeVolume(float nVolume)
{
    HRESULT hr = NULL;
    IMMDeviceEnumerator* deviceEnumerator = NULL;
    hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER,
        __uuidof(IMMDeviceEnumerator), (LPVOID*)&deviceEnumerator);
    if (FAILED(hr))
        return FALSE;

    IMMDevice* defaultDevice = NULL;
    hr = deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice);
    deviceEnumerator->Release();
    if (FAILED(hr))
        return FALSE;

    IAudioEndpointVolume* endpointVolume = NULL;
    hr = defaultDevice->Activate(__uuidof(IAudioEndpointVolume),
        CLSCTX_INPROC_SERVER, NULL, (LPVOID*)&endpointVolume);
    defaultDevice->Release();
    if (FAILED(hr))
        return FALSE;

    hr = endpointVolume->SetMasterVolumeLevelScalar(nVolume, NULL);
    endpointVolume->Release();

    return SUCCEEDED(hr);
}


void send_message(std::string message, int delay) {
    for (int i = 0; i < message.length(); i++) {
        std::cout << message[i];
        Sleep(delay);
    }
    std::cout << "\n";
}

int main() {
    
    

    BlockInput(TRUE);
    const auto MAX = 1000000;
    const auto MIN = 1;

    const std::string smaller = "< bro, your number is smaller";
    const std::string bigger = "> men, your number is bigger";
    const std::string cheater = "Why are you chetting??";

    long long quessed_num;

    int trys = 0;
    int bigger_trys = 0;
    int smaller_trys = 0;

    std::random_device crypto_random_generator;
    std::uniform_int_distribution<int> int_distribution(MIN, MAX);

    int random_int = int_distribution(crypto_random_generator);

    std::cout << random_int << "\n";

    std::cout << "enter your number(from " << MIN << " to " << MAX << " ): ";

    std::cin >> quessed_num;


    do {
        if (quessed_num > MAX || quessed_num < MIN) {
            std::string message = "no no no";
            send_message(message, 84);
            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2);
            Sleep(5000);
            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)-1);
        }
        if (quessed_num < random_int) {
            send_message(smaller, 84);
            trys += 1;
            smaller_trys += 1;
        }
        else if (quessed_num > random_int) {
            send_message(bigger, 84);
            trys += 1;
            bigger_trys += 1;
        }
        else {
            send_message(cheater, 84);

            CoInitialize(NULL);
            ChangeVolume(1);
            CoUninitialize();
            
            ShellExecute(0, 0, L"https://www.youtube.com/watch?v=dQw4w9WgXcQ", 0, 0, SW_SHOW);
            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2);
            Sleep(5000);
            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)-1);
            break;
        }

        if (quessed_num % 2 == 0) {
            send_message("I'll give you 1 more chance ", 25);
        }
        else if (quessed_num % 3 == 0) {
            send_message("Oops, -1 try... ", 25);
        }
        else if (quessed_num % 13 == 0) {
            send_message("Be careful, this may be your last try... ", 50);
        }
        else if (quessed_num % 13 == 0) {
            send_message("Why are you trying? ", 50);
        }
        std::cin >> quessed_num;
    } while (quessed_num != random_int);

}