I recreated the game Hangman and I'm decently happy with it, but like always it would be preferable if anyone knew how to improve my code:

**main.cpp**

```
#ifndef UNICODE
#define UNICODE
#endif

#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <ctime>

#include "gameInfo.h"

// Function declares
std::wstring gen(gameInfo& info);
void clrscr();
void greet(gameInfo& info);
int ask(gameInfo& info, std::wstring& word, std::string& out);
void checklives(gameInfo& info);
void findindex(std::wstring& str, wchar_t character, std::vector<unsigned int>* vct);
void run(gameInfo& info);

// Main thread
int main() {

    srand((unsigned int)time(NULL));
    gameInfo info;

    greet(info);
    clrscr();

    // Runs the whole game  
    run(info);  
}

// Returns random word from word list
std::wstring gen(gameInfo& info) {
    return info.dictionary()[rand() % info.dictionary().size()];
}

/* Function to get input from user at start of app
   makes user choose if they want to play or quit */
void greet(gameInfo& info) {

    while (true) {
        int choice;
        std::wcout << L"1: Play" << std::endl;
        std::wcout << L"2: Quit" << std::endl;

        if ((std::cin >> choice) && (choice == 1 || choice == 2)) {
            if (choice == 1) {
                info.run(true);
                break;
            }
            else break;
        }
        else std::wcout << L"Failed to get input from user" << std::endl;
    }
}

/* Asks user for a character and if there is that
   character in the string then for each of that
   character push back an index and for each index 
   replace the blank character with the input character
   and in the end output the string */
int ask(gameInfo& info, std::wstring& word, std::wstring& out) {

    std::wcout << L"The word is " << word.size() << L" characters long." << std::endl;
    std::wcout << L"You have " << info.live() << L" lives." << std::endl;
    std::wcout << "Input a character: " << std::flush;

    wchar_t answer;

    std::vector<unsigned int> index = { };
    if (std::wcin >> answer) {

        for (int i = 0, n = word.size(); i < n; ++i) {
            if (out[i] == L' ')
                out[i] = L'_';
        }

        answer = std::tolower(answer);
        findindex(word, answer, &index);
        if (!index.size()) {
            info.live(info.live() - 1);
            std::wcout << out << std::endl;
            return 1; // Success
        }

        for (unsigned int i : index) {
            out[i] = answer;
        }

        if (out == word) {
            std::wcout << L"Correct! the word was " << word << "." << std::endl;
            info.run(false);
            return 1; // Success
        }

        std::wcout << out << std::endl;
    }
    else {
        std::wcout << L"Error getting user input" << std::endl;
        return 0; // Failure
    }

    return 1; // Returns success
}

// Shite but does the job
void clrscr() {
    for (int i = 0; i < 10; ++i)
        std::wcout << L"\n\n\n\n\n\n\n\n\n" << std::endl;
}

// Finds index of a word
void findindex(std::wstring& str, wchar_t character, std::vector<unsigned int>* vct) {

    for (int i = 0, n = str.size(); i < n; ++i)
        if (str[i] == character)
            vct->push_back(i);
}

// Checks, well, lives.
void checklives(gameInfo& info) {
    if (info.live() < 1) {
        info.run(false);
    }
}

/* Runs the whole game. For each game loop asks
   the user if they want to retry or quit the game */
void run(gameInfo& info) {

    while (true) {

        std::wstring word = gen(info);
        std::wstring out(word.size(), L' ');
        while (info.run()) {
            ask(info, word, out);
            checklives(info);

            Sleep(1000);

            clrscr();
        }

        info.live(5);

        unsigned int choice;        
        std::wcout << L"1: Retry" << std::endl;
        std::wcout << L"2: Quit" << std::endl;

        if ((std::cin >> choice) && (choice == 1 || choice == 2)) {
            if (choice == 1) {
                info.run(true);
                clrscr();
            }

            else break;
        }
        else {
            std::wcout << L"Couldn't process input. " << std::endl;
            clrscr();
        }
    }
}

```

**gameInfo.header**

```
#pragma once

#include <vector>
#include <string>

class gameInfo {

private:

    // Main variables
    bool bRun = false;
    unsigned int lives = 5;

    std::vector<std::wstring> vec = { 
        L"banana", L"apple", L"circus", L"baby", L"key",
        L"cooker", L"bottle", L"keyboard", L"head", L"book",
        L"robe", L"cup", L"mug", L"box", L"dog", L"horse",
        L"potato", L"desk", L"winter", L"life", L"death"
    };

public:

    // Getters
    std::vector<std::wstring> dictionary();
    bool run();
    unsigned int live();

    // Setters
    void run(bool opt);
    void live(unsigned int opt);

};

```

**gameInfo.cpp**

```
#include "gameInfo.h"

std::vector<std::wstring> gameInfo::dictionary() { return vec; }
bool gameInfo::run() { return bRun; }
unsigned int gameInfo::live() { return lives; }

void gameInfo::live(unsigned int opt) { lives = opt; }
void gameInfo::run(bool opt) { bRun = opt; }

```