news 2026/8/26 16:15:34

C++数字炸弹小游戏(英文版)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
C++数字炸弹小游戏(英文版)

C++数字炸弹小游戏!(英文不好的不要玩!!!)

这是本蒟蒻的第一篇博客!

如果有其他想法,作者的私信和该文的评论区永远向您敞开!
在此鸣谢:XY_Lmf、XY_Yzy

附上友链(中文版,XY_Yzy制作):传送门

更新日:不固定(目前暂已完结,下个版本可能会加入人机对战)

那么……废话不多说,上代码!

Beta1.2.2(最新版)(修复了一些bug)

#include<bits/stdc++.h> #include<windows.h> using namespace std; struct player{ string name; int index; int score; }a[105]; bool cmp(player x,player y) { return x.score < y.score || x.score == y.score && x.index < y.index; } void Show(string s) { for(auto& e : s) { cout << e; Sleep(75); } } void punish() { int id = rand() % 5 + 1; switch(id) { case 1 : Show("Say to the winner: I hate you!");break; case 2 : Show("Drinking a cup of water now.");break; case 3 : Show("Randomly hit a certain player. (Bad laugh...^_^)");break; case 4 : Show("Please play this game again!"); break; default : Show("Say to each player:I am a little stupid."); } } int play_knock() { int bomb = (rand() % 100) + 1; int left = 1,right = 100; int cnt = 0; while(true) { Show("Min Number:"); cout << left; Show(" Max Number:"); cout << right << "\n"; int x; cin >> x; cnt ++; if(x == bomb) { system("cls"); Show("You are dead."); cout << endl; Sleep(1500); system("cls"); break; } else if(x > bomb) { Show("It is bigger than the bomb."); cout << endl; right = x <= right ? x : right; Sleep(500); system("pause"); system("cls"); } else if(x < bomb) { Show("It is lower than the bomb."); cout << endl; left = x >= left ? x : left; Sleep(500); system("pause"); system("cls"); } } cout << "The number of times you have used is:" << cnt; Sleep(2000); return cnt; } void play_Boom(int n) { int bomb = (rand() % 100) + 1; int left = 1,right = 100; int index = 1; while(true) { Show("Min Number:"); cout << left; Show(" Max Number:"); cout << right << "\n"; Show(a[index].name); Show("'s choice is:"); int x; cin >> x; cout << endl; if(x == bomb) { system("cls"); Show(a[index].name); Show(" is dead."); cout << endl; Sleep(1500); system("cls"); break; } else if(x > bomb) { Show("It is bigger than the bomb."); cout << endl; right = x <= right ? x : right; Sleep(500); system("pause"); system("cls"); } else if(x < bomb) { Show("It is lower than the bomb."); cout << endl; left = x >= left ? x : left; Sleep(500); system("pause"); system("cls"); } index ++; if(index > n) index = 1; } Show("The loser of this game is:"); Show(a[index].name); Sleep(2000); } int main(){ Show("Digital Bomb Game!"); cout << endl; Show(" By:Xy Studio"); cout << endl; cout << endl; cout << endl; Show("version Number: Beta 1.2.2"); cout <<endl; system("pause"); system("cls"); srand(time(0)); Show("Please input the number of players (1-50):"); int n; cin >> n; system("cls"); for(int i = 1;i <= n;i ++) { Show("Player"); cout << i << endl; Show("name:"); string s; cin >> s; a[i].index = i; a[i].name = s; cout << endl; } system("cls"); Show("Please choose the game mode(Knock or Boom):"); string mode; cin >> mode; if(mode == "Knock") { system("cls"); Sleep(500); for(int i = 1;i <= n;i ++) { Show(a[i].name); cout << endl; Show("Ready..........Start!"); system("cls"); a[i].score = play_knock(); system("cls"); } sort(a + 1,a + n + 1,cmp); Show(" Score List: "); cout << endl; for(int i = 1;i <= n;i ++) { cout << i << ':'; Show(a[i].name); int len = a[i].name.size(); int nulllen = 20 - len; for(int i = 1;i <= nulllen;i ++) { cout << ' '; Sleep(75); } cout << a[i].score << endl; } cout << "=======================\n"; system("pause"); system("cls"); } else if(mode == "Boom") { system("cls"); Show("Ready..........Start!"); system("cls"); play_Boom(n); system("cls"); Show("Start randomly choosing the punishment.........."); Sleep(500); system("cls"); Show("The punishment to the loser is:"); punish(); Sleep(2000); system("cls"); } else { system("cls"); Show("Input error!"); Sleep(2000); return 0; } Show("Thank you for your play.The next version is currently under development."); cout << endl; Sleep(2000); return 0; }

Beta2.1.3版本(最新版)(加入了喜闻乐见的单人模式

需注意的是:在第一次打开单人游戏或电脑中不存在archive.txt(即无存档)时,不能在读档时选择“Yes”选项!!!

#include<bits/stdc++.h> #include<windows.h> using namespace std; struct players{ string name; int index; int score; }a[105]; struct Person{ string name; int rank; int score; }; bool cmp(players x,players y) { return x.score < y.score || x.score == y.score && x.index < y.index; } void Show(string s) { for(auto& e : s) { cout << e; Sleep(75); } } void punish() { int id = rand() % 5 + 1; switch(id) { case 1 : Show("Say to the winner: I hate you!");break; case 2 : Show("Drinking a cup of water now.");break; case 3 : Show("Randomly hit a certain player. (Bad laugh...^_^)");break; case 4 : Show("Please play this game again!"); break; default : Show("Say to each player:I am a little stupid."); } } int play_knock() { int bomb = (rand() % 100) + 1; int left = 1,right = 100; int cnt = 0; while(true) { Show("Min Number:"); cout << left; Show(" Max Number:"); cout << right << "\n"; int x; cin >> x; cnt ++; if(x == bomb) { system("cls"); Show("You are dead."); cout << endl; Sleep(1500); system("cls"); break; } else if(x > bomb) { Show("It is bigger than the bomb."); cout << endl; right = x <= right ? x : right; Sleep(500); system("pause"); system("cls"); } else if(x < bomb) { Show("It is lower than the bomb."); cout << endl; left = x >= left ? x : left; Sleep(500); system("pause"); system("cls"); } } cout << "The number of times you have used is:" << cnt; Sleep(2000); return cnt; } void play_Boom(int n) { int bomb = (rand() % 100) + 1; int left = 1,right = 100; int index = 1; while(true) { Show("Min Number:"); cout << left; Show(" Max Number:"); cout << right << "\n"; Show(a[index].name); Show("'s choice is:"); int x; cin >> x; cout << endl; if(x == bomb) { system("cls"); Show(a[index].name); Show(" is dead."); cout << endl; Sleep(1500); system("cls"); break; } else if(x > bomb) { Show("It is bigger than the bomb."); cout << endl; right = x <= right ? x : right; Sleep(500); system("pause"); system("cls"); } else if(x < bomb) { Show("It is lower than the bomb."); cout << endl; left = x >= left ? x : left; Sleep(500); system("pause"); system("cls"); } index ++; if(index > n) index = 1; } Show("The loser of this game is:"); Show(a[index].name); Sleep(2000); } string Ranks[11] = {"Ungrade" , "Newbie" , "Introductory" , "Better" , "Somewhat-Famous" , "Well-Known" , "Super" , "Famous-Forever" , "World's-No.1" , "Cosmic-Level" , "Transcend Reality"}; int need[11] = {0 , 100 , 200 , 300 , 400 , 500 , 600 , 700 , 800 , 900 , 1000}; void Play_DIFF1(Person &x) { int bomb = (rand() % 100) + 1; int left = 1,right = 100; int index = 1; string Name = ""; while(true) { Show("Min Number:"); cout << left; Show(" Max Number:"); cout << right << "\n"; int choice; if(index % 2 == 1) { Show(x.name); Name = x.name; Show("'s choice is:"); cin >> choice; if(choice <= left) choice = left + 1; if(choice >= right) choice = right - 1; cout << endl; } else { Show("Machine's choice is:"); Name = "Machine"; choice = (rand() % (right - left)) + left; Sleep(500); if(choice <= left) choice = left + 1; if(choice >= right) choice = right - 1; cout << choice; cout << '\n'; } if(choice == bomb) { system("cls"); Show(Name); Show(" is dead."); cout << endl; Sleep(1500); system("cls"); break; } else if(choice > bomb) { Show("It is bigger than the bomb."); cout << endl; right = choice <= right ? choice : right; Sleep(500); system("pause"); system("cls"); } else if(choice < bomb) { Show("It is lower than the bomb."); cout << endl; left = choice >= left ? choice : left; Sleep(500); system("pause"); system("cls"); } index ++; } if(Name == x.name) { Sleep(500); cout << "You Lose\n"; cout << "Your rank-score minus 5\n"; x.score = max(0 , x.score - 5); } else { Sleep(500); cout << " Congratulations!\n"; cout << " You Win!!!\n"; cout << "Your rank-score adds 10\n"; x.score = x.score + 10; } system("pause"); system("cls"); return; } void Play_DIFF2(Person &x) { int bomb = (rand() % 100) + 1; int left = 1,right = 100; int index = 1; string Name = ""; while(true) { Show("Min Number:"); cout << left; Show(" Max Number:"); cout << right << "\n"; int choice; if(index % 2 == 1) { Show(x.name); Name = x.name; Show("'s choice is:"); cin >> choice; cout << endl; if(choice <= left) choice = left + 1; if(choice >= right) choice = right - 1; } else { Show("Machine's choice is:"); Name = "Machine"; int len = right - left + 1; int mid = (left + right) / 2; int offset = rand() % (len / 4); int op = rand() % 2; if(op == 0) choice = mid - offset; else choice = mid + offset; if(choice <= left) choice = left + 1; if(choice >= right) choice = right - 1; Sleep(500); cout << choice; cout << '\n'; } if(choice == bomb) { system("cls"); Show(Name); Show(" is dead."); cout << endl; Sleep(1500); system("cls"); break; } else if(choice > bomb) { Show("It is bigger than the bomb."); cout << endl; right = choice <= right ? choice : right; Sleep(500); system("pause"); system("cls"); } else if(choice < bomb) { Show("It is lower than the bomb."); cout << endl; left = choice >= left ? choice : left; Sleep(500); system("pause"); system("cls"); } index ++; } if(Name == x.name) { Sleep(500); cout << "You Lose\n"; cout << "Your rank-score minus 10\n"; x.score = max(0 , x.score - 10); } else { Sleep(500); cout << " Congratulations!\n"; cout << " You Win!!!\n"; cout << "Your rank-score adds 25\n"; x.score = x.score + 25; } system("pause"); system("cls"); return; } void Play_DIFF3(Person &x) { int bomb = (rand() % 100) + 1; int left = 1,right = 100; int index = 1; string Name = ""; while(true) { Show("Min Number:"); cout << left; Show(" Max Number:"); cout << right << "\n"; int choice; if(index % 2 == 1) { Show(x.name); Name = x.name; Show("'s choice is:"); cin >> choice; cout << endl; if(choice <= left) choice = left + 1; if(choice >= right) choice = right - 1; } else { Show("Machine's choice is:"); Name = "Machine"; int mid = (left + right) / 2; choice = mid; if(choice <= left) choice = left + 1; if(choice >= right) choice = right - 1; Sleep(500); cout << choice; cout << '\n'; } if(choice == bomb) { system("cls"); Show(Name); Show(" is dead."); cout << endl; Sleep(1500); system("cls"); break; } else if(choice > bomb) { Show("It is bigger than the bomb."); cout << endl; right = choice <= right ? choice : right; Sleep(500); system("pause"); system("cls"); } else if(choice < bomb) { Show("It is lower than the bomb."); cout << endl; left = choice >= left ? choice : left; Sleep(500); system("pause"); system("cls"); } index ++; } if(Name == x.name) { Sleep(500); cout << "You Lose\n"; cout << "Your rank-score minus 20\n"; x.score = max(0 , x.score - 20); } else { Sleep(500); cout << " Congratulations!\n"; cout << " You Win!!!\n"; cout << "Your rank-score adds 50\n"; x.score = x.score + 50; } system("pause"); system("cls"); return; } void Up_To_Next_Level(Person &x) { x.rank ++; system("cls"); system("color f6"); Show(" Congratulations! ! !\n"); Show(" You have risen in rank ["); Show(Ranks[x.rank]); Show("]\n"); Show("Good job! Keep moving on to the next level! ! !\n"); system("pause"); system("cls"); system("color 07"); } void P_VS_M(Person &x) { while(true) { cout << "Name: " << x.name << '\n'; cout << "Your Rank: " << Ranks[x.rank]; cout << '\n'; cout << "Your Score: " << x.score; cout << '\n'; cout << "You still need " << need[x.rank + 1] - x.score << " scores to advance to the next level\n\n\n"; Show("Please choose(Input 1 ~ 4):\n"); cout << "1. Difficulty_#1 (Winning will add 10 scores)\n"; cout << "2. Difficulty_#2 (Winning will add 25 scores)\n"; cout << "3. Difficulty_#3 (Winning will add 50 scores)\n"; cout << "4. Exit and Settle\n"; int choice; cin >> choice; system("pause"); system("cls"); if(choice == 1) Play_DIFF1(x); else if(choice == 2) Play_DIFF2(x); else if(choice == 3) Play_DIFF3(x); else if(choice == 4) break; else { system("cls"); Show("Input Error!!!\n"); system("pause"); system("cls"); } while(x.score >= need[x.rank + 1]) Up_To_Next_Level(x); while(x.score <= need[x.rank]) x.rank --; } } int main(){ Show("Digital Bomb Game!"); cout << endl; Show(" By:Xy Studio"); cout << endl; cout << endl; cout << endl; Show("version Number: Beta 2.0.1"); cout << endl; system("pause"); system("cls"); srand(time(0)); Show("Please input the number of players (1-50):"); int n; cin >> n; system("cls"); if(n == 1) { Person x; system("cls"); Show("Load saved game? (Yes / No)\n"); string s; cin >> s; system("pause"); system("cls"); if(s == "Yes") { freopen("archive.txt" , "r" , stdin); cin >> x.name >> x.rank >> x.score; freopen("CON" , "r" , stdin); cin.clear(); cin.sync(); Show("........Login Successful\n"); system("pause"); system("cls"); } else { Show("Please input the name of your character:\n"); cin >> x.name; x.rank = 0; x.score = 0; system("pause"); system("cls"); } P_VS_M(x); system("cls"); Show("Do you want to archive? (Yes / No)\n"); string ar; cin >> ar; if(ar == "Yes") { ofstream outFile("archive.txt"); if (outFile.is_open()) { outFile << x.name << ' ' << x.rank << ' ' << x.score; outFile.close(); } } Sleep(1000); system("cls"); } else { for(int i = 1;i <= n;i ++) { Show("Player"); cout << i << endl; Show("name:"); string s; cin >> s; a[i].index = i; a[i].name = s; cout << endl; } system("cls"); Show("Please choose the game mode(Knock / Boom):"); string mode; cin >> mode; if(mode == "Knock") { system("cls"); Sleep(500); for(int i = 1;i <= n;i ++) { Show(a[i].name); cout << endl; Show("Ready..........Start!"); system("cls"); a[i].score = play_knock(); system("cls"); } sort(a + 1,a + n + 1,cmp); Show(" Score List: "); cout << endl; for(int i = 1;i <= n;i ++) { cout << i << ':'; Show(a[i].name); int len = a[i].name.size(); int nulllen = 20 - len; for(int i = 1;i <= nulllen;i ++) { cout << ' '; Sleep(75); } cout << a[i].score << endl; } cout << "=======================\n"; system("pause"); system("cls"); } else if(mode == "Boom") { system("cls"); Show("Ready..........Start!"); system("cls"); play_Boom(n); system("cls"); Show("Start randomly choosing the punishment.........."); Sleep(500); system("cls"); Show("The punishment to the loser is:"); punish(); Sleep(2000); system("cls"); } else { system("cls"); Show("Input error!"); Sleep(2000); return 0; } } system("cls"); Show("Thank you for your play.The next version is currently under development."); cout << endl; Sleep(2000); return 0; }

注意事项:

1.记得在编译器中加入代码

-std=c++11

-std=c++14

game.h

别忘了加上game.h哦!

#include<iostream> #include<windows.h> #include<string> #include<random> #include<climits>
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/8/26 16:14:44

梯载文化,步见初心 —— 企业楼梯文化氛围布置的深层价值

写字楼、产业园、厂区里&#xff0c;楼梯往往是最容易被忽略的空间。多数企业只把楼梯当作通行通道&#xff0c;墙面空白单调、过道平淡乏味&#xff0c;白白浪费了每日员工必经的流动场景。 殊不知&#xff0c;楼梯是高频、轻量化、沉浸式的天然文化阵地。员工上下班、午休走动…

作者头像 李华
网站建设 2026/8/26 16:14:10

Umi-OCR 离线OCR实操指南:5个技巧搞定扫描件

Umi-OCR 离线OCR实操指南&#xff1a;5个技巧搞定扫描件 【免费下载链接】Umi-OCR OCR software, free and offline. 开源、免费的离线OCR软件。支持截屏/批量导入图片&#xff0c;PDF文档识别&#xff0c;排除水印/页眉页脚&#xff0c;扫描/生成二维码。内置多国语言库。 项…

作者头像 李华
网站建设 2026/8/26 16:08:40

洛雪音乐助手 免费音乐播放器 5 分钟上手指南

洛雪音乐助手 免费音乐播放器 5 分钟上手指南 【免费下载链接】lx-music-desktop 一个基于 Electron 的音乐软件 项目地址: https://gitcode.com/GitHub_Trending/lx/lx-music-desktop 想听的歌在 A 家 App&#xff0c;无损版本在 B 家&#xff0c;歌词又藏在 C 家&…

作者头像 李华
网站建设 2026/8/26 16:06:49

离线OCR软件Umi-OCR:从截图到批量PDF的完整操作手册

离线OCR软件Umi-OCR&#xff1a;从截图到批量PDF的完整操作手册 【免费下载链接】Umi-OCR OCR software, free and offline. 开源、免费的离线OCR软件。支持截屏/批量导入图片&#xff0c;PDF文档识别&#xff0c;排除水印/页眉页脚&#xff0c;扫描/生成二维码。内置多国语言库…

作者头像 李华
网站建设 2026/8/26 16:04:45

医疗器械现场核查:获证前的实地把关

医疗器械注册申报中&#xff0c;质量管理体系现场核查是药品监督管理部门对质量体系运行状况进行的实地验证。核查人员深入企业生产一线&#xff0c;对厂房设施、设备条件、检验能力、人员配备等进行全面检查&#xff0c;逐项核实企业是否按照《医疗器械生产质量管理规范》建立…

作者头像 李华
网站建设 2026/8/26 16:03:26

起重吊装“Q-H-R”计算及臂杆避坑指南

起重吊装“Q-H-R”计算及臂杆避坑指南导语在施工现场&#xff0c;起重吊装是风险最高、技术最密集的环节之一。起重设备选错了、臂杆长度算短了、重心偏了&#xff0c;轻则构件磕碰&#xff0c;重则机毁人亡。吊装助理-履带吊选型计算今天&#xff0c;我们将《起重吊装计算及安…

作者头像 李华