当前位置:   article > 正文

C++小游戏合集_c++游戏

c++游戏

开局一个卒,士兵全靠买!

  1. // By School //
  2. #include <bits/stdc++.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5. using namespace std;
  6. void ccc(); // 匀速输出
  7. void c_slow(); // 缓慢输出
  8. void cls(); // 清屏
  9. void Error(); // 输出"Input Error"
  10. void zhuye(); // 主界面
  11. void inti(); // 初始化
  12. long long money;
  13. long long bing_1,bing_2 = 1,bing_3;
  14. long long my_shili;
  15. void ccc(string s) { // 匀速输出
  16. for(int i = 0; i < s.size(); i++) {
  17. cout << s[i];
  18. Sleep(25);
  19. }
  20. printf("\n");
  21. }
  22. void c_slow(string s) { // 缓慢输出
  23. for(int i = 0; i < s.size(); i++) {
  24. cout << s[i];
  25. Sleep(444);
  26. }
  27. printf("\n");
  28. }
  29. void cls() { // 清屏
  30. system("cls");
  31. }
  32. void Error() { // 输出"Input Error"
  33. cls();
  34. c_slow("Input Error!");
  35. zhuye();
  36. }
  37. void zhuye() { // 主界面
  38. cls();
  39. ccc("1.说明 2.商店 3.征战 4.我的资料 5.礼包码");
  40. char s = getch();
  41. if(s == '1') {
  42. cls();
  43. ccc("版本号: v.1.06 ");
  44. ccc("征战获得钱");
  45. ccc("钱买士兵");
  46. ccc("按任意键继续");
  47. char a = getch();
  48. zhuye();
  49. } else if(s == '2') {
  50. cls();
  51. ccc("1.普通士兵 10 元 一个 2. 中级士兵 66 元一个 3.高级士兵 111元一个 4.返回");
  52. char a = getch();
  53. if(a == '4') zhuye();
  54. if(a == '1') {
  55. ccc("输入个数");
  56. printf("你有%lld元",money);
  57. int num;
  58. cin >> num;
  59. if(money >= num * 10) {
  60. money -= num * 10;
  61. bing_1 += num;
  62. ccc("购买成功!");
  63. zhuye();
  64. } else Error();
  65. }
  66. if(a == '3') {
  67. ccc("输入个数");
  68. printf("你有%lld元",money);
  69. int num;
  70. cin >> num;
  71. if(money >= num * 111) {
  72. money -= num * 111;
  73. bing_3 += num;
  74. ccc("购买成功!");
  75. zhuye();
  76. } else Error();
  77. }
  78. if(a == '2') {
  79. ccc("输入个数");
  80. printf("你有%lld元",money);
  81. int num;
  82. cin >> num;
  83. if(money >= num * 66) {
  84. money -= num * 66;
  85. bing_2 += num;
  86. ccc("购买成功!");
  87. zhuye();
  88. } else Error();
  89. }
  90. } else if(s == '3') {
  91. cls();
  92. my_shili = bing_1 * 3 + bing_2 * 10 + bing_3 * 30;
  93. printf("我方战力:%lld\n",my_shili);
  94. ccc("输入敌人等级(1 ~ 50)");
  95. int num; cin >> num;
  96. if(num < 1 || num > 50) Error();
  97. long long di_shili = pow(2,num);
  98. while(1){
  99. if(di_shili <= 0) {
  100. cls();
  101. ccc("You Win!");
  102. money += pow(3,num);
  103. printf("你获得了");
  104. cout << pow(3,num);
  105. printf("元!\n");
  106. Sleep(1000);
  107. zhuye();
  108. } if(my_shili <= 0) {
  109. cls();
  110. ccc("你全军覆没了!");
  111. Sleep(1000);
  112. ccc("你在混乱中被杀");
  113. cls();
  114. c_slow("You Are Die!");
  115. Sleep(500);
  116. inti();
  117. }
  118. printf("敌方战力:%lld\n",di_shili);
  119. printf("我方战力:%lld\n",my_shili);
  120. ccc("1.攻击 2.逃跑");
  121. char a = getch();
  122. if(a == '2') zhuye();
  123. if(a == '1') {
  124. if(my_shili >= di_shili) {
  125. bing_1 = ceil(bing_1 * 1.0 / 1.5);
  126. bing_2 = ceil(bing_2 * 1.0 / 1.25);
  127. bing_3 = ceil(bing_3 * 1.0 / 1.125);
  128. my_shili = bing_1 * 3 + bing_2 * 10 + bing_3 * 30;
  129. di_shili /= 3;
  130. } else {
  131. bing_1 /= 2.5;
  132. bing_2 /= 2;
  133. bing_3 /= 1.5;
  134. my_shili = bing_1 * 3 + bing_2 * 10 + bing_3 *30;
  135. di_shili /= 1.5;
  136. }
  137. }
  138. }
  139. } else if(s == '4') {
  140. cls();
  141. printf("金币:%lld\n", money);
  142. printf("普通士兵:%lld\n", bing_1);
  143. printf("中级士兵:%lld\n", bing_2);
  144. printf("高级士兵:%lld\n", bing_3);
  145. printf("战力值:%lld\n", bing_1 * 3 + bing_2 * 10 + bing_3 * 30);
  146. ccc("按任意键继续");
  147. char a = getch(); zhuye();
  148. } else if(s == '5') {
  149. cls();
  150. ccc("输入兑换码");
  151. string a; getline(cin,a);
  152. if(a == "HAPPY666") {
  153. cls();
  154. ccc("恭喜获得:200元");
  155. money += 200;
  156. Sleep(500);
  157. zhuye();
  158. } if(a == "School666") {
  159. cls();
  160. ccc("恭喜获得:20名中级士兵");
  161. bing_2 += 20;
  162. Sleep(500);
  163. zhuye();
  164. } if(a == "C++666") {
  165. cls();
  166. ccc("恭喜获得:6名高级士兵");
  167. bing_3 += 6;
  168. Sleep(500);
  169. zhuye();
  170. } if(a == "DevC++666") {
  171. cls();
  172. ccc("恭喜获得:66名低级士兵");
  173. bing_1 += 66;
  174. Sleep(500);
  175. zhuye();
  176. } else Error();
  177. } else Error();
  178. }
  179. void inti() { // 初始化
  180. cls();
  181. system("color 09");
  182. c_slow("By School");
  183. Sleep(500);
  184. cls();
  185. c_slow("Loading……");
  186. Sleep(500);
  187. zhuye();
  188. }
  189. int main() { inti(); } // main()函数好像没用……

最强指挥官

  1. // By School //
  2. #include <bits/stdc++.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5. using namespace std;
  6. void ccc(string s);
  7. void c_slow(string s);
  8. void cls();
  9. void Error();
  10. void zhuye();
  11. void inti();
  12. long long lvl = 1;
  13. long long sum;
  14. long long money = 50;
  15. long long wuqi = 5;
  16. long long MAX_SUM = 10;
  17. void ccc(string s) {
  18. for(int i = 0; i < s.size(); i++) {
  19. cout << s[i];
  20. Sleep(25);
  21. }
  22. cout << "\n";
  23. }
  24. void c_slow(string s) {
  25. for(int i = 0; i < s.size(); i++) {
  26. cout << s[i];
  27. Sleep(444);
  28. }
  29. cout << "\n";
  30. }
  31. void cls() {
  32. system("cls");
  33. }
  34. void Error() {
  35. cls();
  36. c_slow("Input Error!");
  37. Sleep(500);
  38. zhuye();
  39. }
  40. void zhuye() {
  41. cls();
  42. ccc("1.教程 2.征战 3.升级 4.招募 5.我的信息");
  43. char a = getch();
  44. if(a == '1') {
  45. cls();
  46. ccc("每次征战会获得财宝和武器");
  47. ccc("财宝和武器到达一定数量可以升级军队等级");
  48. ccc("军队等级的升级会大幅增加士兵上限和士兵战斗力");
  49. ccc("加油吧,指挥官!");
  50. ccc("请按任意键继续");
  51. char n = getch();
  52. zhuye();
  53. }
  54. else if(a == '2') {
  55. cls();
  56. ccc("输入等级 (<=50) 输入0返回");
  57. int n;
  58. cin >> n;
  59. if(n == 0) zhuye();
  60. cls();
  61. printf("敌方士兵数:");
  62. cout << pow(3,n) << "\n";
  63. printf("我方士兵数:%d\n",sum);
  64. printf("敌方等级:%d\n",n);
  65. printf("我方等级:%d\n",lvl);
  66. ccc("指挥官,是否发动进攻? 输入'Y'或'N' Y代表攻击 N代表逃跑");
  67. char num = getch();
  68. if(num == 'Y') {
  69. if((pow(3,n) * pow(2,lvl) < sum * pow(2,lvl))) {
  70. cls();
  71. c_slow("You Win!");
  72. ccc("恭喜收获:");
  73. printf("\t"); cout << pow(5,n + 1) << "元\n";
  74. printf("\t"); cout << pow(10,n - 1) << "把武器\n";
  75. printf("\t"); cout << floor(pow(3,n) / 5) << "名俘虏\n";
  76. ccc("请按任意键继续");
  77. char s = getch();
  78. money += pow(5,n + 1);
  79. wuqi += pow(10,n - 1);
  80. sum += pow(3,n) / 5;
  81. zhuye();
  82. } else { ccc("You Lose!"); zhuye(); }
  83. }
  84. else if(num == 'N') {
  85. cls();
  86. ccc("你损失了一些军费!");
  87. printf("损失了:"); cout << pow(10,n) << "元"; money -= pow(10,n);
  88. Sleep(1000);
  89. zhuye();
  90. }
  91. else Error();
  92. }
  93. else if(a == '3') {
  94. cls();
  95. printf("你的当前等级是%d,升级需要",lvl);
  96. cout << pow(20,lvl + 1);
  97. printf("元和");
  98. cout << pow(3,lvl + 1);
  99. printf("把武器\n");
  100. ccc("是否购买? Please Input 'Y' or 'N'");
  101. char n = getch();
  102. if(n == 'Y') {
  103. if(money < pow(20,lvl + 1)) {
  104. cls();
  105. ccc("You Don't Have Enough Money!");
  106. zhuye();
  107. } else if(wuqi < pow(3,lvl + 1)) {
  108. cls();
  109. ccc("You Don't Have Enough Weapon!");
  110. zhuye();
  111. } else {
  112. money -= pow(20,lvl + 1);
  113. wuqi -= pow(10,lvl);
  114. lvl++;
  115. MAX_SUM *= 5;
  116. ccc("OK!");
  117. Sleep(500);
  118. zhuye();
  119. }
  120. }
  121. else if(n == 'N') zhuye();
  122. else Error();
  123. }
  124. else if(a == '4') {
  125. cls();
  126. printf("招募一个士兵需要");
  127. cout << pow(10,lvl);
  128. printf("元,一把武器\n");
  129. ccc("你要多少? 输入数字 输入-1可以购买最大上限个士兵");
  130. int n;
  131. cin >> n;
  132. if(n == -1) {
  133. int n1 = (money / (pow(10,lvl))), n2 = wuqi;
  134. int num = min(n1,n2); int k = MAX_SUM - sum; if(num > k) num = k;
  135. money -= num * pow(10,lvl);
  136. wuqi -= num;
  137. sum += num;
  138. cls();
  139. ccc("OK!");
  140. printf("购买了%d个士兵",num);
  141. Sleep(500);
  142. zhuye();
  143. }
  144. else if(money < pow(10,lvl) * n) {
  145. cls();
  146. ccc("You Don't Have Enough Money!");
  147. zhuye();
  148. }
  149. else if(wuqi < n) {
  150. cls();
  151. ccc("You Don't Have Enough Weapon!");
  152. zhuye();
  153. }
  154. else if(sum + n > MAX_SUM) {
  155. cls();
  156. ccc("It Is So Big! Please add your level");
  157. zhuye();
  158. }
  159. else {
  160. sum += n;
  161. money -= pow(10,lvl) * n;
  162. cls();
  163. ccc("OK!");
  164. Sleep(500);
  165. zhuye();
  166. }
  167. }
  168. else if(a == '5') {
  169. cls();
  170. printf("等级:%d\n",lvl);
  171. printf("士兵数量:%d\n",sum);
  172. printf("士兵上限:%d\n",MAX_SUM);
  173. printf("钱:%d\n",money);
  174. printf("武器数量:%d\n",wuqi);
  175. ccc("请按任意键继续");
  176. char n = getch();
  177. zhuye();
  178. }
  179. else Error();
  180. }
  181. void inti() {
  182. system("color 09");
  183. c_slow("By School");
  184. cls();
  185. c_slow("Loading……");
  186. cls();
  187. zhuye();
  188. }
  189. int main() { inti(); }

猜数游戏

  1. // By School //
  2. #include <bits/stdc++.h>
  3. #include <windows.h>
  4. using namespace std;
  5. void cls() {
  6. system("cls");
  7. }
  8. int power(int n) {
  9. long long s = 1,i = 0;
  10. while(s < n) {
  11. s *= 2;
  12. i++;
  13. }
  14. return i;
  15. }
  16. void ccc(string s) {
  17. for(int i = 0; i < s.size(); i++) {
  18. cout << s[i];
  19. Sleep(25);
  20. }
  21. cout << "\n";
  22. }
  23. void c_slow(string s) {
  24. for(int i = 0; i < s.size(); i++) {
  25. cout << s[i];
  26. Sleep(444);
  27. }
  28. cout << "\n";
  29. }
  30. int main() {
  31. cls();
  32. ccc("输入范围 输入0关闭");
  33. int n;
  34. cin >> n;
  35. if(n == 0)
  36. return 0;
  37. cls();
  38. printf("范围为 1 ~ %d\n",n);
  39. long long s = power(n);
  40. long long ans = rand() % n + 1;
  41. printf("你最少要猜%d次,更少算我输!\n",s);
  42. ccc("猜吧");
  43. long long sum = 1;
  44. while(1) {
  45. int x;
  46. cin >> x;
  47. if(x > ans) {
  48. ccc("大了");
  49. sum++;
  50. }
  51. else if(x < ans) {
  52. ccc("小了");
  53. sum++;
  54. }
  55. else {
  56. cls();
  57. c_slow("Yes!");
  58. printf("你用了%d次!",sum);
  59. break;
  60. }
  61. }
  62. return 0;
  63. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/90906
推荐阅读