Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <random>
- #include <vector>
- #include <windows.h>
- using std::string;
- using std::cout;
- using std::endl;
- using std::cin;
- int main()
- {
- constexpr auto max = 10u;
- const std::vector<string> words = {"agrest", "bigos", "czara", "drewno", "ekipa", "figura", "gorycz", "hiena", "iskra", "junior"};
- std::mt19937 eng(std::random_device{}());
- std::uniform_int_distribution<> dis(0u, max-1);
- char play;
- cout << "Witaj w grze wisielec!" << endl;
- do
- {
- string target = words[dis(eng)];
- int len = target.length();
- string attempt(len,'-');
- string badchars;
- int guesses = 6;
- cout << "Slowo ma " << len << " liter." << endl;
- cout << "Mozesz pomylic sie " << guesses << " razy." << endl;
- cout << "POWODZENIA :)" << endl;
- cout << endl;
- while (guesses > 0 && attempt != target)
- {
- cout << "Twoje slowo: " << attempt << endl;
- if (badchars.length() > 0)
- {
- cout << "Niepoprawne litery: " << badchars << endl;
- }
- cout << "Mozesz pomylic sie jeszcze " << guesses << " razy" << endl;
- char letter;
- cout << "Podaj litere: ";
- cin >> letter;
- // system dependent
- system("cls");
- if (badchars.find(letter) != string::npos ||
- attempt.find(letter) != string::npos)
- {
- cout << "Ta litera juz byla. Sproboj innej." << endl;
- continue;
- }
- int pos = target.find(letter);
- if (pos == string::npos)
- {
- cout << "Nie ma takiej litery!" << endl;
- guesses--;
- badchars += letter;
- }
- else
- {
- cout << "Poprawna litera" << endl;
- do
- {
- attempt[pos] = letter;
- pos = target.find(letter, pos+1);
- } while(pos != string::npos);
- }
- }
- if (guesses > 0)
- cout << "To juz cale slowo! Brawo!" << endl;
- else
- cout << "Niestety, to slowo to " << target << endl;
- cout << "Chcesz zagrac jeszcze raz? (t/n)" << endl;
- cin >> play;
- } while (tolower(play)=='t');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement