Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <conio.h>
  3. #include<windows.h>
  4. using namespace std;
  5. const int size_of_alphabet_array = 26;
  6.  
  7. bool GetInput(char* buffer, size_t size, int time_out)
  8. {
  9. time_t start = time(0);
  10. size_t n = 0;
  11. while (true) {
  12. 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
  13. return false;
  14.  
  15. if (kbhit()) { //checks if key is pressed
  16. char ch = (int)getche(); //reads a single character from the keyboard and displays immediately
  17. if (ch == '\r') {//is a carriage return character; it tells your terminal emulator to move the cursor at the start of the line.
  18. buffer[n++] = '\n';
  19. break;
  20. }
  21. else
  22. buffer[n++] = ch;
  23. if (n == size - 1)
  24. break;
  25. }
  26. }
  27. buffer[n] = '\0';
  28. return true;
  29. }
  30.  
  31. string RandomString(int n, char alphabet[]) //random string generator
  32. {
  33.  
  34. string random_string = "";
  35. for (int i = 0; i < n; i++)
  36. random_string = random_string + alphabet[rand() % size_of_alphabet_array]; //part which genrates random strings
  37.  
  38. return random_string;
  39. }
  40.  
  41. // Driver code
  42. int main()
  43. {
  44. int tokens = 100;
  45. char f_fixed = 'x'; char s_fixed = 'x'; char t_fixed = 'x';
  46. int flagcounter = 0;
  47. int score = 1000;
  48. char alphabet[size_of_alphabet_array] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  49. 'h', 'i', 'j', 'k', 'l', 'm', 'n',
  50. 'o', 'p', 'q', 'r', 's', 't', 'u',
  51. 'v', 'w', 'x', 'y', 'z' };
  52. int n = 3;
  53. int input = 0; int ms;
  54. cout << "Enter 100 tokens and pull the handle\n";
  55. Sleep(1000);
  56. string temp = RandomString(n, alphabet);
  57. cout << "Enter wait time(milliseconds):";//to increase/decrease difficulty
  58. cin >> ms;
  59. while (tokens >= 10)
  60. {
  61. temp = RandomString(n, alphabet);
  62. string temp2;
  63. int counter = 0;
  64.  
  65. //Input
  66. char buffer[512] = { 0 };
  67. if (!GetInput(buffer, 512, 1)) {
  68.  
  69. buffer[0] = '\n';
  70. }
  71. if (buffer[0] == 'a' | buffer[0] == 'A') { flagcounter += 1; }
  72. else if (buffer[0] == 's' | buffer[0] == 'S') { flagcounter = 0; }
  73. else if (buffer[0] == 'e' | buffer[0] == 'E') { system("cls"); break; }
  74.  
  75. Sleep(ms);
  76.  
  77. system("cls");
  78. //cout<<flagcounter;
  79.  
  80. 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";
  81. cout << "Use Lever:a\n";
  82. cout << "Reset Game:s\n";
  83. cout << "Exit Game:e\n";
  84. //flagcounter+=input%10;
  85. //cout<<flagcounter;
  86. if (flagcounter == 0) {
  87. f_fixed = temp[0]; s_fixed = temp[1]; t_fixed = temp[2];
  88.  
  89. //cout<<temp;
  90. cout << "=================================================\n";
  91. cout << "= = = =\n";
  92. cout << "= " << f_fixed << " = " << s_fixed << " = " << t_fixed << " =\n";
  93. cout << "= = = =\n";
  94. cout << "=================================================\n";
  95. }
  96.  
  97. else if (flagcounter == 1) {
  98. s_fixed = temp[1]; t_fixed = temp[2];
  99.  
  100. //cout<<temp;
  101. cout << "=================================================\n";
  102. cout << "= = = =\n";
  103. cout << "= " << f_fixed << " = " << s_fixed << " = " << t_fixed << " =\n";
  104. cout << "= = = =\n";
  105. cout << "=================================================\n";
  106. }
  107. else if (flagcounter == 2) {
  108. t_fixed = temp[2];
  109.  
  110. //cout<<temp;
  111. cout << "=================================================\n";
  112. cout << "= = = =\n";
  113. cout << "= " << f_fixed << " = " << s_fixed << " = " << t_fixed << " =\n";
  114. cout << "= = = =\n";
  115. cout << "=================================================\n";
  116. }
  117. else if (flagcounter == 3)
  118. {
  119. system("CLS");
  120. char ch;
  121. if (f_fixed == s_fixed && s_fixed == t_fixed) {
  122. tokens = tokens + 10;
  123. 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; }
  124. else
  125. break;
  126. }
  127. else {
  128. tokens = tokens - 10;
  129. 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; }
  130. else
  131. break;
  132. }
  133. }
  134. cout << "Please enter your option:";
  135.  
  136. }
  137. system("Pause");
  138. return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement