• 个人简介

    本人为C++新手,目前只会输入输出、变量、分支、循环结构、数组、字符串,与对编游戏重要的自学的取随机数

    想学取随机数代码的复制这个(中文为需要填的,如数量需在写时修改为数量值)

    srand(time(0));
    int 变量名称=rand()%取值范围最大数与最小数之差+取值范围最小数;
    
    

    比大小(没花多少时间,无bug)(规则写在游戏里了,会自己显示)(内有中文、英文两版,英语好的建议玩英文版)

    中文版

    using namespace std;
    int a[15];
    int main(){
    	srand(time(0));
    	int fir=rand()%15+1;
    	for(int i=1;i<=15;i++){
    		if(i<4){
    			a[i]=7;
    		}
    		else if(i>12){
    			a[i]=9;
    		}
    		else{
    			a[i]=8;
    		}
    	}
    	fir=a[fir];
    	cout<<"第一张牌是"<<fir<<endl;
    	cout<<"假如你猜第二张牌"<<endl;
    	cout<<"大于第一张牌请按'B';"<<endl;
    	cout<<"其他,请按 'S'"<<endl;
    	char gue;cin>>gue;
    	srand(time(0));
    	int sec=rand()%15+1;
    	if(sec==7 or sec==8 or sec==9){
    		srand(time(0));
    		int jud=rand()%2;
    		if(jud==0){
    			sec=6;
    		}
    		else{
    			sec=10;
    		}
    	}
    	cout<<"第二张牌是"<<sec<<endl;
    	if(gue=='S' or gue=='s'){
    		if(sec>fir){
    			cout<<"你输了!";
    		}
    		else{
    			cout<<"你赢了!";
    		}
    	}
    	else{
    		if(sec<fir){
    			cout<<"你赢了!";
    		}
    		else{
    			cout<<"你输了!";
    		}
    	}
    	return 0;
    } 
    
    
    
    

    英文版

    #include<bits/stdc++.h>
    using namespace std;
    int a[15];
    int main(){
    	srand(time(0));
    	int fir=rand()%15+1;
    	for(int i=1;i<=15;i++){
    		if(i<4){
    			a[i]=7;
    		}
    		else if(i>12){
    			a[i]=9;
    		}
    		else{
    			a[i]=8;
    		}
    	}
    	fir=a[fir];
    	cout<<"The first card is"<<fir<<endl;
    	cout<<"If you guess the second card"<<endl;
    	cout<<"is big than the first card,please press'B'"<<endl;
    	cout<<"Other,please press 'S'"<<endl;
    	char gue;cin>>gue;
    	srand(time(0));
    	int sec=rand()%15+1;
    	if(sec==7 or sec==8 or sec==9){
    		srand(time(0));
    		int jud=rand()%2;
    		if(jud==0){
    			sec=6;
    		}
    		else{
    			sec=10;
    		}
    	}
    	cout<<"The second card is"<<sec<<endl;
    	if(gue=='B' or gue=='b'){
    		if(sec>fir){
    			cout<<"You win!";
    		}
    		else{
    			cout<<"You lose...";
    		}
    	}
    	else{
    		if(sec<fir){
    			cout<<"You win!";
    		}
    		else{
    			cout<<"You lose...";
    		}
    	}
    	return 0;
    } 
    
    

    半成品(目前禁抄)

    #include<bits/stdc++.h>
    #include<unistd.h>
    using namespace std;
    int gun[5];
    int gu[5];
    char play[15];
    int tur[52];
    char card[52];
    int car[52];
    int main(){
    	srand(time(0));
    	for(int i=1;i<=15;i++){
    		if(i==10){
    			play[i]='J';
    		}
    		else if(i==11){
    			play[i]='Q';
    		}
    		else if(i==12){
    			play[i]='K';
    		}
    		else if(i==13){
    			play[i]='A';
    		}
    		else if(i==14){
    			play[i]='JOKER';
    		}
    		else if(i==15){
    			play[i]='???';
    		}
    		else{
    			play[i]=i+47;
    		}
    	} 
    	for(int i=1;i<=52;i++){
    		int a=i/4;
    		if(!(i%4==0)){
    			a++;
    		}
    		car[i]=a;
    	} 
    	for(int i=1;i<=52;i++){
    		int a=i/4;
    		a++;
    		if(a>1 and a<10){
    			card[i]=a+48;
    		}	
    		else if(a==11){
    			card[i]='J';
    		}
    		else if(a==12){
    			card[i]='Q';
    		}
    		else if(a==13){
    			card[i]='K';
    		}
    		else{
    			card[i]='A';
    		}
    	}
    	for(int i=1;i<=52;i++){
    		int a=rand()%52+1;
    		do{
    			a++;
    		}while(tur[a]==1);
    		card[i]=card[a];
    		tur[a]=1;
    	} 
    	int coi=50;
    	int ply=1;
    	char gon='e';
    	do{
    		cout<<"这里是21点"<<endl;
    		char AA;cin>>AA;
    		cout<<"你获得了50个金币!"<<endl;
    		cout<<"系统提示:将手指放在1、2、3、4、5上,体验更佳!"<<endl;
    		char AB;cin>>AB;
    		cout<<"请允许我为你讲解规则!"<<endl;
    		cout<<"(1->请讲解!/2->不了,谢谢!)"<<endl;
    		int AC;cin>>AC;
    		do{
    			cout<<"最初,我会给你与你的对手一人发两张牌,接着你们需要下注金币;"<<endl;
    			cout<<"你们按按键分别指:1(未分牌时按)->摸一张牌/2(只能在一开始按)->分牌/3或4(分牌后按)->分别给第一、二副牌摸牌/5->结束"<<endl;
    			cout<<"当双方都结束时,进行计算:"<<endl;
    			cout<<"点数:2~9为牌面点数;J,Q,K为10点;10如果总牌面点数>21算0,其余算10;A与10同理,前者算1,后者算0"<<endl;
    			cout<<"牌面点数如果大于21,则称为‘爆牌’,点数记为0;其他情况下按点数总和记"<<endl;
    			cout<<"需要我再次讲解吗?"<<endl;
    			cout<<"1->恳请讲解!/2->我听懂了!"<<endl;
    			int AD;cin>>AD;
    			AC=AD; 
    		} while(AC==1);
    		cout<<"请选择你的模式吧!"<<endl;
    		cout<<"1->随机匹配"<<endl; 
    		cout<<"2->闯关模式"<<endl;
    		int AE;cin>>AE;
    		if(AE==1){
    			
    		}
    		else{
    			if(ply==15){
    				cout<<"???:你发现了这?"<<endl;
    				cout<<"???:那么,我们玩个游戏吧…"<<endl;
    				cout<<"这是一把枪,里面装有3发虚弹,2发实弹;"<<endl;
    				for(int i=1;i<=5;i++){
    					if(i>2){
    						i=1;
    					}
    					else{
    						i=0;
    					}
    				} 
    				for(int i=1;i<=5;i++){
    					int AF=rand()%5+1;
    					do{
    						AF++;
    					}while(gu[AF]==101);
    					gun[i]=gun[AF];
    					gu[i]=101;
    				}
    				cout<<"你可以随时让我向你开枪!"<<endl;
    				int tu=1;
    				int AG=2;
    				do{
    					if(tur==5){
    						cout<<"那位神秘人拿出小刀,将你刺杀…"<<endl;
    						cout<<"???:墨迹的家伙…"<<endl;
    						cout<<"结局6:我不屈服!"<<endl;
    						cout<<"金币总量:0";
    						return 0; 
    					} 
    					cout<<"第"<<tu<<"发子弹:"<<endl;
    					cout<<"(1->开枪 2->不开)" <<endl;
    					int AH;cin>>AH;
    					tu++;
    					AG=AH;
    				}while(AG==2);
    				int AI=gun[tu];
    				if(gun[tu]==0){
    					cout<<"???:(鼓掌)拿着这把刀,杀了那个赌场老板!"
    					continue; 
    				}
    				else{
    					cout<<"你在一声巨大的枪响后,失去了意识…"<<endl;
    					cout<<"结局5:霉运之子"<<endl;
    					cout<<"金币数量:"<<coi;
    					return 0;
    				}
    			}
    			int pla=play[ply];
    			cout<<"当前关卡:第"<<ply<<"关"<<endl; 
    			cout<<"战斗对手:"<<pla<<endl;
    			cout<<"需要点数:";
    			int game;
    			if(ply==1 or ply==2 or ply==3){
    				game=15;
    			}
    			else if(ply==5 or ply==4 or ply==6){
    				game=16;
    			}
    			else if(ply==7 or ply==8 or ply==9){
    				game=17;
    			}
    			else if(ply==10 or ply==11 or ply==12){
    				game=18;
    			}
    			else if(ply==13){
    				game=19;
    			}
    		}
    	}while(gon=='g');
    }
    
    
    

    以上就是我的个人主页了,非常感谢你能看到这里!

  • 通过的题目

  • 最近活动

  • 最近编写的题解

    This person is lazy and didn't write any solutions.

题目标签

普及-
32
模拟
26
语言入门
15
循环结构
11
搜索
7
枚举
7
顺序结构
6
数组
5
其他
3
字符串
3
分支结构
3
计算几何
3
入门
3
选择语句
3
排序
2
一本通
2
二维数组
2
运算
2
素数判断
1
质数
1