Number Bomb

· · 休闲·娱乐

更新日志:

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...
\text{actually(?) by\ \color{orange}{JSGF\_ArcPhi}\:\color{white}\colorbox{limegreen}{√}} \\ \text{the\ end.}

\color{#000000}{戳我返回导览}