Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <windows.h>
- using namespace std;
- void animatedPrint(const string &text)
- {
- for (int i = (int)text.size() - 1; i > 0; i--)
- {
- cout << &text[i];
- Sleep(20);
- string backspaces;
- for (int j = i; j < (int)text.size(); j++)
- backspaces += "\b";
- cout << backspaces;
- }
- cout << text;
- }
- int main()
- {
- while (true)
- {
- animatedPrint("Laten we galgje spelen!");
- cout << "\n\n";
- animatedPrint("Voor de uitdager...");
- cout << "\n\n";
- string oplossing;
- animatedPrint("Geef de oplossing: ");
- cin >> oplossing;
- int beurten;
- do {
- animatedPrint("Geef het aantal beurten: ");
- cin >> beurten;
- } while (beurten <= 0);
- system("cls");
- animatedPrint("Voor de speler...");
- cout << "\n\n";
- string woord;
- for (int i = 0; i < (int)oplossing.size(); i++)
- woord += ".";
- while (true)
- {
- animatedPrint("Woord: " + woord);
- cout << "\n";
- animatedPrint("Beurten: ");
- cout << beurten << "\n";
- string input;
- animatedPrint("Geef een letter of de oplossing: ");
- cin >> input;
- if (input.size() > 1)
- {
- if (input == oplossing)
- {
- animatedPrint("Juist!");
- cout << "\n\n";
- break;
- }
- else
- {
- animatedPrint("Fout!");
- cout << "\n\n";
- beurten--;
- }
- }
- else
- {
- bool juist = false;
- for (int i = 0; i < (int)oplossing.size(); i++)
- {
- if (oplossing[i] == input[0])
- {
- woord[i] = oplossing[i];
- juist = true;
- }
- }
- if (!juist)
- beurten--;
- if (woord == oplossing)
- {
- animatedPrint("Gewonnen!");
- cout << "\n\n";
- break;
- }
- }
- if (!beurten)
- {
- animatedPrint("Verloren!");
- cout << "\n\n";
- break;
- }
- }
- animatedPrint("Oplossing: " + oplossing);
- cout << "\n\n";
- string opnieuw;
- do {
- animatedPrint("Nog eens spelen (j/n)? ");
- cin >> opnieuw;
- } while ((opnieuw[0] != 'j') && (opnieuw[0] != 'n'));
- if (opnieuw[0] == 'n')
- {
- cout << "\n";
- animatedPrint("Ik hoop dat je het leuk vond. Ik althans wel!");
- cout << "\n\n";
- break;
- }
- system("cls");
- }
- }
Add Comment
Please, Sign In to add comment