Advertisement
Easonchu777

Untitled

Mar 8th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. void Start();
  8. void GetResults();
  9.  
  10. int i, j, life, maxrand;
  11. char c;
  12.  
  13. void Start() {
  14. i = 0;
  15. j = 0;
  16. life = 0;
  17. maxrand = 6;
  18.  
  19. cout << "選擇遊玩難度:\n";
  20. cout << "1 : 簡單 (0-15萬)\n";
  21. cout << "2 : 中等 (0-30萬)\n";
  22. cout << "3 : 困難 (0-50萬)\n";
  23. cout << "輸入其他鍵以離開\n";
  24. c = 30;
  25.  
  26. cin >> c;
  27. cout << "\n";
  28.  
  29. switch (c) {
  30. case '1':
  31. maxrand = 150000;
  32. break;
  33. case '2':
  34. maxrand = 300000;
  35. break;
  36. case '3':
  37. maxrand = 500000;
  38. break;
  39. default:
  40. exit(0);
  41. break;
  42. }
  43.  
  44. life = 5;
  45. srand((unsigned)time(NULL));
  46. j = rand() % maxrand;
  47.  
  48. GetResults();
  49. }
  50.  
  51. void GetResults() {
  52. if (life <= 0) {
  53. cout << "輸了 笑你爛 哈哈哈!\n\n";
  54. Start();
  55. }
  56.  
  57. cout << "輸入數字: \n";
  58. cin >> i;
  59.  
  60. if((i>maxrand) || (i<0)) {
  61. cout << "數字不在0~\n" << maxrand;
  62. GetResults();
  63. }
  64.  
  65. if(i == j) {
  66. cout << "踩到狗屎猜到了!\n\n";
  67. Start();
  68. } else if(i>j) {
  69. cout << "太大了 不要\n";
  70. life = life - 1;
  71. cout << "殘餘生命: " << life << "\n\n";
  72. GetResults();
  73. } else if(i<j) {
  74. cout << "太小了 討厭\n";
  75. life = life - 1;
  76. cout << "殘餘生命: " << life << "\n\n";
  77. GetResults();
  78. }
  79. }
  80.  
  81. int main() {
  82. cout << "冷冷好愛你的遊戲\n";
  83. cout << "給我猜數字啦\n";
  84. cout << "我很好心告樹你數字是否太大或太小\n";
  85. cout << "但你可能還是笨到猜不出來\n\n";
  86. Start();
  87. return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement