更新日志:
- 0.0 代码成型;
- 0.1 修正了一些换行错误;
- 0.2 添加了again()函数;
- 0.3 修正了again()输入’Y’也无法重来的bug;
- 0.4 添加了rules()函数;
- 0.5 添加了BOOM特效,修正了变量混淆问题;
- 0.6 加入了3~50人游玩(先前只有2人模式)
- 0.7 修复了Sleep停止时间不理想问题;
- 0.8 添加了注释;
- 0.9 解决了部分时间int炸掉的问题(
)#define int long long - 1.0 在华师一编程班公开测试;
- 1.1 添加了modes()函数;
- 1.2 rand()返回值int,删去带long long的modes;
- 1.3 实测出mode 4有bug,封锁;
- 1.4 BOOM界面有shan·xia·yan的屏闪(注释掉了);
- 1.5 推出了1人模式:人机对
抗话模式; - 1.6 多人可与电脑玩;
- 1.7 修改了部分英文问题;
- 1.8 qiang·po·zheng犯了把代码分层,还把variables对齐了😂;可1~60人玩;炸了之后添加了
Outch!!!; - 1.9 游戏结束后加上显示bomb为多少的语句;将
Do you want to try man-computer mode删去;将复杂的if-else改为switch-case; - 2.0 加入了爆炸情况;(details see-down)
CODE:
//Number Boob - Version 2.0
//Playable, DO NOT COPY!!!!!!!!!!
//HYDRO 40536
//https://hydro.ac/user/40536/
//https://hydro.ac/user/40536/
//https://hydro.ac/user/40536/
//headers
#include<bits/stdc++.h>
#include<cstdlib>
#include<conio.h>
#include<windows.h>
//defines
#define int long long
#define fr(i,a,b) for(int i = a; i <= b; i ++)
#define cls system("cls")
#define slp(n) Sleep(n*1000)
//namespace
using namespace std;
//variables
unsigned int bomb /*random bomb*/ ;
unsigned int kkksc /*computer itslef's input's range*/;
unsigned int num /*real player*/ ;
unsigned int nuuuum /*all player(include computer)*/ ;
unsigned int mode /*game mode*/ ;
unsigned int iii /*the player that get bomb*/ ;
unsigned int mmm /*why game over*/ ;
unsigned int _round = 1 /*round*/ ;
unsigned int a /*input*/ ;
unsigned int rr /*right*/ ;
signed int ll /*left*/ ;
bool is = false /*is(n't) get bomb*/ ;
bool isC = false /*is computer*/ ;
char yorn /*play again: yes or no*/ ;
//voids
void again();
void modes();
void rules();
void game();
void boom();
//main
signed main(){
srand(time(0));
rand();//waste the first rand();
cout << "Number Boob - Version 2.0\n\nhttps://hydro.ac/user/40536/\n";
//players
cout << "Enter the number of players: ";
cin >> num;
if(num <= 0){
cout << "Too few!!!\n";
again();
}else if(num >= 61){
cout << "Too many!!!\n";
again();
}else if(num == 1){
cout << "LET'S GO!!!!!\nEnter any key to continue...\n\n(tips: You will play with computer!)";
isC = 1;
}else{
cout << "Do you want to play with computer? Y/N\n";
cin >> yorn;
if(yorn == 'Y'){
isC = 1;
cout << "LET'S GO!!!!!\nEnter any key to continue...\n\n(tips: You will play with computer!)";
}
else{cout << "LET'S GO!!!!!\nEnter any key to continue...";}
}
//rules && modes
getch();
cls;
modes();
cls;
//game!!
while(is == false){
int nuuuum;
if(isC == 1){nuuuum = num+1;}
else{nuuuum = num;}
fr(i,1,nuuuum){
cout << "ROUND " << _round << ": left: " << ll << ", right: " << rr << ".\n";
//ROUND ?: left: ??, right: ??.
if(isC==1 and i==nuuuum){cout << "Computer: ";}
else{cout << "Player" << i << ": ";}
//Player ?:
if(isC==1 and i==nuuuum){
while(1){
a = rand()%kkksc;
if(a < rr and a > ll){break;}
}
cout << a << "\n";
}
else{cin >> a;}//input a number
game();//see void game()
if(is){//if get a bomb
iii = i;
cout << "\n\nOutch!!!\n\n";
slp(5);
cls;
break;
}
}
_round++;
cout << "\n";
}
cls;
//game over
if(is){
boom();
cout << "\n\n";
switch(mmm){
case 111:{
if(isC==1 and iii==nuuuum){cout << "Computer encountered the bomb!!!";}
else{cout << "Player " << iii << " encountered the bomb!!!";}
break;
}
case 222:{
cout << "Player " << iii << " out of the `left` range!!!";
break;
}
case 333:{
cout << "Player " << iii << " out of the `right` range!!!";
break;
}
default:{break;}
}
}
cout << "\n\nThe bomb is: " << bomb << ".\n\nGAME OVER!";
cout << "\n\npress any key to return...\n";
getch();
cls;
is = 0;
_round = 1;
again();
}
//voids details
//play again
void again(){
cout << "Do you want to try again? Input Y/N\n";
cin >> yorn;
if(yorn == 'Y'){
cls;
main();
}
exit(0);
}
//game mode
void modes(){
cout << "Please choose a mode to play this game.\n\
https://hydro.ac/user/40536/\n\
---------------------------------------\n\
| GAME MODE |\n\
|left~right |\n\
|1.10~99 |\n\
|2.0~100 |\n\
|3.10~99999 |\n\
|/*mode 4 has some bug*/ |\n\
|5.0~2147483646 |\n\
| |\n\
|input 0 to see the rules. |\n\
---------------------------------------\nmode:\
";
cin >> mode;
switch(mode){
case 0:{
cls;
rules();
modes();
break;
}
case 1:{
ll = 10; rr = 99;
bomb = rand()%100;
kkksc = 100;
if(bomb <= 9){bomb += 10;}
break;
}
case 2:{
ll = 0; rr = 100;
bomb = rand()%101;
kkksc = 101;
break;
}
case 3:{
ll = 10; rr = 99999;
bomb = rand()%100000;
kkksc = 100000;
if(bomb <= 9){bomb += 10;}
break;
}
//case 4:{
//ll = -10000; rr = 10000;
//bomb = rand()%20001-10000;
//break;
//}
case 5:{
ll = 0; rr = INT_MAX-1;
bomb = rand()%(INT_MAX);
kkksc = INT_MAX;
break;
}
case 114514:{
ll = 1; rr = 3;
bomb = 2;
break;
}
default:{
fr(llllll,1,6){
cout << ".";
slp(1);
}
exit(0);
}
}
}
//told rules
void rules(){
cls;
cout << "\
https://hydro.ac/user/40536/\n\
--------------------------------------------------------------\n\
| RULE |\n\
|1.First, use `rand()` to get a `bomb number`. |\n\
|2.Then, all players input a number that in `left`~`right`. |\n\
|3.If a player's number equals the `bomb`, he/she lose!!! |\n\
|4.If a player's number less than `left`, he/she lose!!! |\n\
|5.If a player's number greater than `right`, he/she lose!!! |\n\
--------------------------------------------------------------\n\n\
press any key to back to the choose-mode-page...\
";
getch();
cls;
}
//while playing
void game(){
if(a == bomb){//get bomb
is = 1;
mmm = 111;
return;
}
if(a <= ll){//out of `left`
is = 1;
mmm = 222;
return;
}
if(a >= rr){//out of `right`
is = 1;
mmm = 333;
return;
}
if(a>ll and a<bomb){ll = a;}//left
else if(a<rr and a>bomb){rr = a;}//right
}
//get BOOM
void boom(){
cout << "\
BBBBBBBBBB OOOOOOOO OOOOOOOO MMMM MMMM !!\n\
BB BB OO OO OO OO MM MM MM MM !!!!\n\
BB BB OO OO OO OO MM MM MM MM !!!!\n\
BB BB OO OO OO OO MM MM MM MM !!\n\
BBBBBBBBBB OO OO OO OO MM MMM MM !!\n\
BB BB OO OO OO OO MM M MM !!\n\
BB BB OO OO OO OO MM MM\n\
BB BB OO OO OO OO MM MM !!\n\
BBBBBBBBBB OOOOOOOO OOOOOOOO MM MM !!\n\
https://hydro.ac/user/40536/\n\
";
/* //screen color(DON'T use!!!)
while(true){
system(n);
}
*/
}
//HYDRO 40536
//https://hydro.ac/user/40536/
//https://hydro.ac/user/40536/
//https://hydro.ac/user/40536/2.0 details
游戏中:
ROUND 3: left: 48733, right: 50477
Player 1:49785
Outch!!!Player 1 encountered the bomb!!!
The bomb is: 49785.
GAME OVER!
press any key to return...与
游戏中:
ROUND 3: left: 48733, right: 50477
Player 1:45555
Outch!!!Player 1 out of the `left` range!!!
The bomb is: 49785.
GAME OVER!
press any key to return...