弱智的猜数字游戏

· · 个人记录

不务正业中...

正常的猜数字游戏,会告知过大或过小。有一定概率电脑会说谎,说谎次数一定。

本游戏开源,不更新版本。更改源代码来获得更好的体验!

#include<windows.h>
#include<iostream>
#include<ctime>
using namespace std;
const int N=50;//数字将在1-N之间生成
const int M=6; //你可以猜数字的次数
const int C=1; //电脑说谎的次数
const int A=1;
const int B=5; //单次说谎的概率为A/B 
int x,a,i,c;
bool f;
int main(){
    SetConsoleTitle("——由BIGBUG乱搞而成!");
    srand(time(NULL));
    x=rand()%N+1;c=C;
    for(i=M;i>=1;--i){
        system("cls");
        cout<<"你还有"<<i<<"次机会!\n"; 
        cout<<"猜数字(1-"<<N<<"):";
        cin>>a;
        if(a!=x) f=a>x;
        else{cout<<"正确!";break;}
        if(c>0&&rand()%B<A) f=!f;
        printf("错误!%d过%s了!",a,f?"大":"小");
        Sleep(2000);
    }
    system("cls");
    if(i==0) cout<<"正解是"<<x<<"!";
    else cout<<"你成功使用"<<M-i+1<<"次机会猜出了答案!";
    return 0;
}