Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <algorithm>
- #include <cstdlib>
- #include <ctime>
- #include <stdlib.h>
- int main()
- {
- srand(time(NULL));
- std::cout << "Loading..." << std::endl;
- std::ifstream stream("words.txt");
- std::vector<std::string> words;
- std::string line;
- while (std::getline(stream, line))
- {
- words.push_back(line);
- }
- std::string solution = words.at((rand() * rand())%words.size());
- std::string current;
- current.assign(solution.length(), '-');
- std::string entered;
- int lives = 10;
- while (!(lives == 0 || solution == current))
- {
- system("cls");
- bool found = 0;
- std::cout << current << std::endl;
- std::cout << "enter a letter, you currently have: " << lives << " lives" << std::endl;
- std::cout<< "Wrong characters: " << entered << std::endl;
- std::string c;
- std::cin >> c;
- std::string old = current;
- if (c.size() > 1)
- {
- if (c == solution)
- {
- current = solution;
- }
- else
- {
- --lives;
- }
- }
- else
- {
- for (int i = 0; i < solution.length(); ++i)
- {
- char s = solution.at(i);
- if (s == c[0])
- {
- current[i] = s;
- }
- }
- if (old == current)
- {
- --lives;
- entered += c[0];
- }
- }
- }
- if (!(lives == 0))
- {
- std::cout << " You have finished the game, conGratz !!! *fireworks*" << std::endl;
- }
- else
- {
- std::cout << "You loose, BAKA" << std::endl;
- std::cout << "The word you were looking for was: " << solution << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement