Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <conio.h>
- #include<windows.h>
- using namespace std;
- const int size_of_alphabet_array = 26;
- bool GetInput(char* buffer, size_t size, int time_out)
- {
- time_t start = time(0);
- size_t n = 0;
- while (true) {
- if (n == 0 && difftime(time(0), start) >= time_out)//waits for input in the said time. have used seconds. 1 seconds is the time it waits for
- return false;
- if (kbhit()) { //checks if key is pressed
- char ch = (int)getche(); //reads a single character from the keyboard and displays immediately
- if (ch == '\r') {//is a carriage return character; it tells your terminal emulator to move the cursor at the start of the line.
- buffer[n++] = '\n';
- break;
- }
- else
- buffer[n++] = ch;
- if (n == size - 1)
- break;
- }
- }
- buffer[n] = '\0';
- return true;
- }
- string RandomString(int n, char alphabet[]) //random string generator
- {
- string random_string = "";
- for (int i = 0; i < n; i++)
- random_string = random_string + alphabet[rand() % size_of_alphabet_array]; //part which genrates random strings
- return random_string;
- }
- // Driver code
- int main()
- {
- int tokens = 100;
- char f_fixed = 'x'; char s_fixed = 'x'; char t_fixed = 'x';
- int flagcounter = 0;
- int score = 1000;
- char alphabet[size_of_alphabet_array] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
- 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u',
- 'v', 'w', 'x', 'y', 'z' };
- int n = 3;
- int input = 0; int ms;
- cout << "Enter 100 tokens and pull the handle\n";
- Sleep(1000);
- string temp = RandomString(n, alphabet);
- cout << "Enter wait time(milliseconds):";//to increase/decrease difficulty
- cin >> ms;
- while (tokens >= 10)
- {
- temp = RandomString(n, alphabet);
- string temp2;
- int counter = 0;
- //Input
- char buffer[512] = { 0 };
- if (!GetInput(buffer, 512, 1)) {
- buffer[0] = '\n';
- }
- if (buffer[0] == 'a' | buffer[0] == 'A') { flagcounter += 1; }
- else if (buffer[0] == 's' | buffer[0] == 'S') { flagcounter = 0; }
- else if (buffer[0] == 'e' | buffer[0] == 'E') { system("cls"); break; }
- Sleep(ms);
- system("cls");
- //cout<<flagcounter;
- cout << "*Rewards:10 tokens*\nYou press a lever one stops, press a again lever b stops,press a again lever b stops.Press S to restart\n";
- cout << "Use Lever:a\n";
- cout << "Reset Game:s\n";
- cout << "Exit Game:e\n";
- //flagcounter+=input%10;
- //cout<<flagcounter;
- if (flagcounter == 0) {
- f_fixed = temp[0]; s_fixed = temp[1]; t_fixed = temp[2];
- //cout<<temp;
- cout << "=================================================\n";
- cout << "= = = =\n";
- cout << "= " << f_fixed << " = " << s_fixed << " = " << t_fixed << " =\n";
- cout << "= = = =\n";
- cout << "=================================================\n";
- }
- else if (flagcounter == 1) {
- s_fixed = temp[1]; t_fixed = temp[2];
- //cout<<temp;
- cout << "=================================================\n";
- cout << "= = = =\n";
- cout << "= " << f_fixed << " = " << s_fixed << " = " << t_fixed << " =\n";
- cout << "= = = =\n";
- cout << "=================================================\n";
- }
- else if (flagcounter == 2) {
- t_fixed = temp[2];
- //cout<<temp;
- cout << "=================================================\n";
- cout << "= = = =\n";
- cout << "= " << f_fixed << " = " << s_fixed << " = " << t_fixed << " =\n";
- cout << "= = = =\n";
- cout << "=================================================\n";
- }
- else if (flagcounter == 3)
- {
- system("CLS");
- char ch;
- if (f_fixed == s_fixed && s_fixed == t_fixed) {
- tokens = tokens + 10;
- cout << "Users Wins\t\t\t\t\t\t\t\t\t\t\t\t " << "Tokens:" << tokens << "\n"; cout << "You hit a jackpot.10 tokens were added to your account\nContinue Playing?(y/n)\n"; ch = getch(); if (ch == 'y') { system("CLS"); flagcounter = 0; }
- else
- break;
- }
- else {
- tokens = tokens - 10;
- cout << "Users Loses\t\t\t\t\t\t\t\t\t\t\t\t " << "Tokens:" << tokens << "\n"; cout << "You lost 10 tokens\nContinue Playing?(y/n)\n"; ch = getch(); if (ch == 'y') { system("CLS"); flagcounter = 0; }
- else
- break;
- }
- }
- cout << "Please enter your option:";
- }
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement