简单的猜数字游戏

用简单的C++代码实现的猜数字游戏,保证对代码小白友好

#include<iostream>
#include<windows.h>
#include<stdio.h>
#include <ctime>
#include<conio.h>
#include<time.h>
#include<string>
#include"colour.h"
#include <stdlib.h>
#include <cmath>
#include<cstdlib>
using namespace std;
int main ()
{
    cout << " hi ,welcome to <guess the number> game \n before start the game ,could you please tell me what's your name?  (@-@) " << endl;
    string  name;
    getline(cin,name) ;
    cout << " hello " << name << endl;
    int a,points=20,p=5,rewards=0,max = 0,times=0,vi=0;
    start:
	 system ("cls");
	 	cout<< red; 
	 cout << " \b\bOh " << name << endl;
	 cout << white ;
	   printf ( " \b\byou have 20 points to start \n each round will spent 5 points \n please select a difficulty \n 1:easy \n 2: normal \n 3: hard \n 4: crazy\n 5: check your points \n press any other button to quit \n"); 
	cin >> a;
    cout << points <<endl;
    if (a==1 || a==2 || a==3 || a==4 || a==520|| a==5)
    {   
        points=points-5;
        ++times;
    	if (a==520) {
    		times=times-1;
    		system ("cls");
    		points=points+1000;
    		p=10;
    		cout << " i love you too  :)" ;
    		cout << "\nthis page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
    		system ("cls");
    		//printf ( "welcome to the guess the number\n you have 20 points to start \n each round will spent 5 points \n please select a difficulty \n 1:easy \n 2: normal \n 3: hard \n 4: impossible \n");
    		goto start;
		}
		if ( a== 5) {
			times=times-1;
			points=points+5;
			system ( "cls ");
			cout << "loading \n";
			Sleep (1000);
						system ( "cls ");
			cout << "loading. \n";
				Sleep (1000);
							system ( "cls ");
			cout << "loading..\n Hei try to input 520 at  the  start ";
				Sleep (1000);
							system ( "cls ");
			cout << "loading... ";
				Sleep (1000);
							system ( "cls ");
			cout << "loading.... \n trying to load in your access ";
				Sleep (1000);
							system ( "cls ");
			cout << "loading......\n trying to load in your memory  ";
				Sleep (1000);
							system ( "cls ");
			cout << "success!\n " << endl << "you have " << points << " points now " << endl;
			if (times == 0 ) {cout << " this model is locked " << endl;
			}
			if ( times!=0  ){
			cout << "you have played for " << times << " times here " << endl << "and you have won for " << vi << " times\n" << "your win rate is " << (100*vi)/times << "%"<< endl;}
			if ( points == 20 ) {
				cout << " Hi " << 	name  << "it is just a start ,right?" << endl ;
			}
			if ( points >20&& points <=100 ) {
				cout << " you are good ";
			}
			if ( points>100 && points <= 200 ) {
				cout << " you are the best player i have seen ";
			}
			if ( points > 1000) {
				cout << " you must have used 520 ,don't you  :)\n  ";
			}
			if ( points <20 ) {
				cout << "you are in dangerous station now " << endl;
			}
			Sleep ( 1000 );
			cout << " this page will close in 5 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 4 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 3 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
           	system ( " cls ");
			goto start;
			
		}
    	if (a==1){
    		system ("cls");
    		max=20;
    		cout << "win to get 10 points"<< endl;
    		rewards=10;
    		cout << "\nthis page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
    		goto game;
		}
		if (a==2){
			system ("cls");
			max=50+points;
			cout << "win to get 20 points "<< endl;
			rewards=20;
			cout << "\nthis page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
			goto game; 
		}
		if ( a==3 ) {
			system ("cls");
			max=100+2*points;
			cout << "win to get 50 points " << endl;
			rewards=50;
			cout << "\nthis page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
			goto game;
		}
		if (a==4) {
			system ("cls");
			max=200+3*points;
			cout << "good luck to you " << endl << " win to double your points " << endl;
			cout << "\nthis page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
			goto game;
		}
	}
	else {system("PAUSE");
	return 0;
	}
	game:
	system("cls");
	cout << "type a number " << endl;
	int in=0;
	srand((unsigned)time(0));
    long t;
	int c;
    c=p;
    int m;
    m = max;
    t = rand()%m;
    gaming:
    	cin >> in;
    if( c>=1 ) {
    	if ( c==1) {
    		cout << " attention ,be careful " << endl;
		}
	
	if ( in < t) {
    	--c;
    	cout <<"too small" << endl<< " with " << c << " chance left \n" ;
    	goto gaming;
	}
	if (in > t ) {
		--c;
		cout << " too big " << endl << " with " << c << " chance left \n" ;
		goto gaming ; 
	}
	if ( in == t ) {
		++vi;
		if ( a==1||a==2|| a==3){
		
		cout << " amazing ,you are smart  \n" << endl;
		points=points + 10* c + rewards;
		cout << "\nthis page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
		goto start;
		}
		if ( a==4){
		points = 2* points;
		cout << " that is impossible!!! " << endl;
		cout << "\nthis page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
		goto start;}
		
	}
}
if (c<= 0) {
		cout<< red; 
	cout << "\b\b you are defeated ,man\n  ";
		cout<< white;
	cout << "\b\bthis page will close in 2 seconds " ;
			Sleep ( 1000 );
			cout << "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b this page will close in 1 seconds " ;
           	Sleep ( 1000 );
		goto start;
	
}
	
		
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值