赞
踩
三个本人编的C++小游戏:
1.打怪小游戏
#include<bits/stdc++.h>
#include<windows.h>
#include<unistd.h>
using namespace std;
int chs,gld,ky,lqd,bld,ncn,wpn,num,bssbld,g,k,l,b,n,w,T,flag;
bool chk=true,pd;
string a[]={"","1000金币","2500金币","损失5555金币","5000金币","2个武器","1条咒语","损失3瓶药水","损失1把钥匙","5条咒语","20点血量","损失50点血量","损失3把钥匙"};
void init(){
gld=1000000;
ky=10;
lqd=3;
bld=100;
ncn=3;
wpn=5;
cout<<"玩家敬请慎重选择和输入,否则退出游戏\n";
Sleep(1500);
system("cls");
}
void cl(){
system("cls");
}
int main(){
init();
do{
cout<<"剩余金币:"<<gld<<"个\n";
cout<<"剩余钥匙:"<<ky<<"把\n";
cout<<"剩余药水:"<<lqd<<"瓶\n";
cout<<"剩余咒语:"<<ncn<<"条\n";
cout<<"剩余血量:"<<bld<<"点\n";
cout<<"剩余武器:"<<wpn<<"个\n\n";
cout<<"0 -- 商店\n";
cout<<"1 -- 抽奖\n";
cout<<"2 -- 打怪\n";
cout<<"其他数字 -- 退出游戏\n";
cin>>chs;
if(!chs){
cout<<"\n1000金币=1把钥匙\n";
cout<<"1000金币=1瓶药水\n";
cout<<"1000金币=15点血量\n";
cout<<"1000金币=1条咒语\n";
cout<<"1000金币=1个武器\n";
do{
cout<<"(成本)\n金币:";
cin>>g;
}while(g<1 || gld<g);
cout<<"(利润)\n钥匙:";
cin>>k;
cout<<"药水:";
cin>>l;
cout<<"血量:";
cin>>b;
T=b%15;
b/=15;
cout<<"咒语:";
cin>>n;
cout<<"武器:";
cin>>w;
if(!T && (k+l+b+n+w)*1000<=g){
b*=15;
gld-=g;
ky+=k;
lqd+=l;
bld+=b;
ncn+=n;
wpn+=w;
system("cls");
}
else
return 0;
}
else if(chs==1){
system("cls");
srand(time(NULL));
num=rand()%12+1;
if(num==3 || num==7 || num==8 || num==11 || num==12)
cout<<"好可惜!";
else
cout<<"恭喜你获得了";
cout<<a[num]<<"!\n";
switch(num){
case 1:gld+=1000;break;
case 2:gld+=2500;break;
case 3:gld-=5555;break;
case 4:gld+=5000;break;
case 5:wpn+=2;break;
case 6:ncn++;break;
case 7:lqd-=3;break;
case 8:ky--;break;
case 9:ncn+=5;break;
case 10:bld+=20;break;
case 11:bld-=50;break;
case 12:ky-=3;
}
if(gld<1 && wpn<1 && ncn<1 && lqd<1 && ky<1 && bld<1){
cout<<"很可惜!你因金币、钥匙、药水、咒语、血量、武器都不足而无法进行游戏!下次再见!";
return 0;
}
}
else if(chs==2)
break;
else
return 0;
}while(1);
do{
cout<<"打怪需消耗钥匙1把\n";
if(ky<1){
cout<<"你的钥匙不足!需要进入商店交易或者抽奖!\n";
cout<<"剩余金币:"<<gld<<"个\n";
cout<<"剩余钥匙:"<<ky<<"把\n";
cout<<"剩余药水:"<<lqd<<"瓶\n";
cout<<"剩余咒语:"<<ncn<<"条\n";
cout<<"剩余血量:"<<bld<<"点\n";
cout<<"剩余武器:"<<wpn<<"个\n\n";
cout<<"0 -- 商店\n";
cout<<"1 -- 抽奖\n";
cout<<"2 -- 打怪\n";
cout<<"其他数字 -- 退出游戏\n";
cin>>chs;
if(!chs){
cout<<"\n1000金币=1把钥匙\n";
cout<<"1000金币=1瓶药水\n";
cout<<"1000金币=15点血量\n";
cout<<"1000金币=1条咒语\n";
cout<<"1000金币=1个武器\n";
cout<<"(成本)\n金币:";cin>>g;
cout<<"(利润)\n钥匙:";cin>>k;
cout<<"药水:";cin>>l;
cout<<"血量:";cin>>b;
T=b%15;
b/=15;
cout<<"咒语:";cin>>n;
cout<<"武器:";cin>>w;
if(!T && (k+l+b+n+w)*1000<=g){
b*=15;
gld-=g;
ky+=k;
lqd+=l;
bld+=b;
ncn+=n;
wpn+=w;
system("cls");
}
else
return 0;
}
else if(chs==1){
system("cls");
srand(time(NULL));
num=rand()%12+1;
if(a[num][0]=='-')
cout<<"好可惜!";
else
cout<<"恭喜你获得了";
cout<<a[num]<<"!\n";
switch(num){
case 1:gld+=1000;break;
case 2:gld+=2500;break;
case 3:gld-=5555;break;
case 4:gld+=5000;break;
case 5:wpn+=2;break;
case 6:ncn++;break;
case 7:lqd-=3;break;
case 8:ky--;break;
case 9:ncn+=5;break;
case 10:bld+=20;break;
case 11:bld-=20;break;
case 12:ky-=3;
}
if(gld<1 && wpn<1 && ncn<1 && lqd<1 && ky<1 && bld<1){
cout<<"很可惜!你因金币、钥匙、药水、咒语、血量、武器都不足而无法进行游戏!下次再见!";
return 0;
}
}
}
bssbld=800;
ky--;
cout<<"开始打怪!\n怪物初始血量为:800点\n";
srand(time(NULL));
do{
cout<<"请使用下列方式进行攻击(每次攻击所造成的伤害与任何事物均无关,请做好心理准备):\n";
cout<<"0 -- 剧毒药水攻击(消耗药水1瓶)\n";
cout<<"1 -- 魔法咒语攻击(消耗咒语1条)\n";
cout<<"2 -- 超强武器攻击(消耗武器1个)\n";
cout<<"3 -- 消耗血量攻击(消耗血量20点)\n";
cout<<"其他数字 -- 退出游戏\n";
cin>>chs;
if(!chs)
num=rand()%21+4;
else if(chs==1)
num=rand()%58;
else if(chs==2)
num=rand()%73;
else if(chs==3)
num=rand()%110;
else
return 0;
cout<<"此关Boss受到"<<num<<"点伤害\n";
bssbld-=num;
cout<<"目前Boss血量为"<<bssbld<<"点\n";
cout<<"Boss要对你发起猛烈回击...\n";
sleep(1);
pd=true;
T=rand()%6+1;
switch(T){
case 1:if(gld>399){cout<<"金币-400!\n";sleep(1);gld-=400;}
else chk=false;break;
case 2:if(ky>0){cout<<"钥匙-1!\n";sleep(1);ky--;}
else chk=false;break;
case 3:if(bld>9){cout<<"血量-10!\n";sleep(1);gld-=10;}
else chk=false;break;
case 4:if(lqd>0){cout<<"药水-1!\n";sleep(1);lqd--;}
else chk=false;break;
case 5:if(ncn>0){cout<<"咒语-1!\n";sleep(1);ncn--;}
else chk=false;break;
case 6:if(wpn>0){cout<<"武器-1!\n";sleep(1);wpn--;}
else chk=false;
}
cout<<"剩余金币:"<<gld<<"个\n";
cout<<"剩余钥匙:"<<ky<<"把\n";
cout<<"剩余药水:"<<lqd<<"瓶\n";
cout<<"剩余咒语:"<<ncn<<"条\n";
cout<<"剩余血量:"<<bld<<"点\n";
cout<<"剩余武器:"<<wpn<<"个\n\n";
}while(bssbld>0 && chk);
if(chk){
cout<<"恭喜你打怪成功!接下来是随机奖励环节!\n";
num=rand()%50000+2000;
cout<<"获得金币"<<num<<"个\n";
gld+=num;
num=rand()%15+3;
cout<<"获得钥匙"<<num<<"把\n";
ky+=num;
num=rand()%10+3;
cout<<"获得药水"<<num<<"瓶\n";
lqd+=num;
num=rand()%200+25;
cout<<"获得血量"<<num<<"点\n";
bld+=num;
num=rand()%15+3;
cout<<"获得咒语"<<num<<"条\n";
ncn+=num;
num=rand()%10+3;
cout<<"获得武器"<<num<<"个\n";
wpn+=num;
}
else{
cout<<"很可惜,你打怪失败!接下来是安慰奖:\n获得金币300个\n获得血量20点\n";
gld+=500;
bld+=20;
}
cout<<"还想玩输入1,否则输入0\n";
for(cin>>flag;flag!=1 && flag;cin>>flag)
cout<<"只能输入1或0哦!\n";
}while(flag);
return 0;
}
2.2048小游戏(细心的人会发现跟我们平时玩的2048不太一样,不过不必介意)
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int a[5][5];
bool fw;
char m;
void init(){
srand(int(time(NULL)));
int tf1=rand()%2+1,tf2=rand()%2+1,fx=rand()%4+1,fy=rand()%4+1,sx,sy;
do{
sx=rand()%4+1;
sy=rand()%4+1;
}while(fx==sx && fy==sy);
a[fx][fy]=tf1*2;
a[sx][sy]=tf2*2;
}
int sc(){
int mx=0;
for(int i=1;i<5;i++)
for(int j=1;j<5;j++)
mx=max(a[i][j],mx);
return mx;
}
void put(){
system("cls");
cout<<"\t\tWelcome to 2048!\n";
cout<<" Enter 'w',move up.\n";
cout<<" Enter 's',move down.\n";
cout<<" Enter 'a',move to the left.\n";
cout<<" Enter 'd',move to the right.\n";
cout<<"Current status:\n";
for(int i=1;i<5;i++){
for(int j=1;j<5;j++){
if(!a[i][j])
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
else if(a[i][j]==2)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);
else if(a[i][j]==4)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
else if(a[i][j]==8)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN);
else if(a[i][j]==16)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
else if(a[i][j]==32)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN | FOREGROUND_BLUE);
else if(a[i][j]==64)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
else if(a[i][j]==128)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_BLUE);
else if(a[i][j]==256)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY FOREGROUND_RED);
else if(a[i][j]==512)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
else if(a[i][j]==1024)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
if(a[i][j]>=0 && a[i][j]<9)
cout<<" "<<a[i][j]<<" ";
else if(a[i][j]>15 && a[i][j]<65)
cout<<" "<<a[i][j]<<" ";
else if(a[i][j]>127 && a[i][j]<513)
cout<<" "<<a[i][j]<<" ";
else
cout<<a[i][j]<<" ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
cout<<endl;
}
}
inline int fn(int p,int q){
if(p && q)
return 1;
if(p && !q)
return 2;
return 0;
}
void MV(int p1,int q1,int p2,int q2){
switch(fn(a[p1][q1],a[p2][q2])){
case 1:if(a[p1][q1]==a[p2][q2]){a[p2][q2]*=2;a[p1][q1]=0;}break;
case 2:a[p2][q2]=a[p1][q1];a[p1][q1]=0;
}
}
void Up(){
for(int j=1;j<5;j++){
MV(2,j,1,j);
MV(3,j,2,j);
MV(2,j,1,j);
MV(4,j,3,j);
MV(3,j,2,j);
MV(2,j,1,j);
}
}
void Down(){
for(int j=1;j<5;j++){
MV(3,j,4,j);
MV(2,j,3,j);
MV(3,j,4,j);
MV(1,j,2,j);
MV(2,j,3,j);
MV(3,j,4,j);
}
}
void Left(){
for(int i=1;i<5;i++){
MV(i,2,i,1);
MV(i,3,i,2);
MV(i,2,i,1);
MV(i,4,i,3);
MV(i,3,i,2);
MV(i,2,i,1);
}
}
void Right(){
for(int i=1;i<5;i++){
MV(i,3,i,4);
MV(i,2,i,3);
MV(i,3,i,4);
MV(i,1,i,2);
MV(i,2,i,3);
MV(i,3,i,4);
}
}
int sp(){
int s=0;
for(int i=1;i<5;i++)
for(int j=1;j<5;j++)
if(!a[i][j])
s++;
return s;
}
int findx(int o){
int s=0;
for(int i=1;i<5;i++)
for(int j=1;j<5;j++){
if(!a[i][j])
s++;
if(s==o)
return i;
}
return -1;
}
int findy(int o){
int s=0;
for(int i=1;i<5;i++)
for(int j=1;j<5;j++){
if(!a[i][j])
s++;
if(s==o)
return j;
}
return -1;
}
void ge(){
srand(int(time(NULL)));
int th=rand()%(sp())+1,v=rand()%2+1;
a[findx(th)][findy(th)]=v*2;
}
bool win(){
for(int i=1;i<5;i++)
for(int j=1;j<5;j++)
if(a[i][j]==2048)
return true;
return false;
}
bool lose(){
for(int j=1;j<5;j++){
if(!a[2][j] || !a[1][j] || a[2][j]==a[1][j])
return false;
if(!a[3][j] || !a[2][j] || a[3][j]==a[2][j])
return false;
if(!a[4][j] || !a[3][j] || a[4][j]==a[3][j])
return false;
}
for(int i=1;i<5;i++){
if(!a[i][4] || !a[i][3] || a[i][4]==a[i][3])
return false;
if(!a[i][3] || !a[i][2] || a[i][3]==a[i][2])
return false;
if(!a[i][2] || !a[i][1] || a[i][2]==a[i][1])
return false;
}
return true;
}
int main(){
init();
put();
cout<<"\nCurrent score:";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<sc()<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
do{
fw=false;
if(lose()){
put();
cout<<"Oh!You lost the game!\nMaximum score:";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN | FOREGROUND_BLUE);
cout<<sc();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
return 0;
}
cout<<"Please enter an operation:";
m=_getch();
cout<<m<<endl;
while(m!='W' && m!='w' && m!='S' && m!='s' && m!='A' && m!='a' && m!='D' && m!='d'){
cout<<"'"<<m<<"' isn't a valid operation.Please enter again:";
m=_getch();
cout<<m<<endl;
}
switch(m){
case 'w':case 'W':Up();break;
case 's':case 'S':Down();break;
case 'a':case 'A':Left();break;
case 'd':case 'D':Right();
}
ge();
put();
if(win()){
fw=true;
put();
cout<<"Congratulation!\nYou won the game!\nMaximum score:";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
cout<<"2048";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
return 0;
}
cout<<"\nCurrent score:";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<sc()<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}while(!fw);
}
3.算数答题小游戏(个别难度有一点烧脑)
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int mode1/*運算*/,mode2/*難度*/,opr/*運算符*/,ans/*正確答案*/,ssol/*輸入的答案*/,quot/*商*/,rmder/*餘數*/,qsol/*輸入的商*/,rsol/*輸入的餘數*/;
void as(int m){
srand(int(time(NULL)));
int pw=pow(10,m+2)-1,x,y;
while(1){
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
x=rand()%pw+1;
y=rand()%pw+1;
if(m>=0 && m<3 && x<y)
swap(x,y);
opr=rand()%2;
ans=(opr?x+y:x-y);
cout<<"\t\t"<<x<<(opr?"+":"-")<<y<<"=";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
cin>>ssol;
if(ssol==ans){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<"答案正確!";
Sleep(1500);
}
else{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
cout<<"答案錯誤!\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout<<"正確答案:";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<ans;
Sleep(2500);
}
}
}
void md(int m){
srand(int(time(NULL)));
int pw=pow(10,m+2)-1,x,y;
while(1){
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
x=rand()%pw+1;
y=rand()%pw+1;
opr=rand()%2;
if(opr){
ans=x*y;
cout<<"\t\t"<<x<<"×"<<y<<"=";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
cin>>ssol;
if(ssol==ans){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<"答案正確!";
Sleep(1500);
}
else{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
cout<<"答案錯誤!\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout<<"正確答案:";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<ans;
Sleep(2500);
}
}
else{
quot=x/y;
rmder=x%y;
cout<<"\t\t"<<x<<"÷"<<y<<"=";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
cin>>qsol;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout<<"\t\t"<<x<<"%"<<y<<"=";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
cin>>rsol;
if(qsol==quot && rsol==rmder){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<"答案正確!";
Sleep(1500);
}
else{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
cout<<"答案錯誤!\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout<<"正確答案:";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<quot<<"\n "<<rmder;
Sleep(2500);
}
}
}
}
void asmd(int m){
srand(int(time(NULL)));
int pw=pow(10,m+2)-1,op,op2,x,xx,xxx,xxxx;
bool br;
while(1){
system("cls");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
br=false;
x=rand()%pw+1;
xx=rand()%pw+1;
xxx=rand()%pw+1;
xxxx=rand()%pw+1;
op=rand()%5;
switch(op){
case 0:cout<<"("<<x<<"+"<<xx;ans=x+xx;br=true;break;
case 1:cout<<"("<<x<<"-"<<xx;ans=x-xx;br=true;break;
case 2:cout<<x<<"×"<<xx;ans=x*xx;break;
case 3:cout<<x<<"÷"<<xx;ans=x/xx;break;
case 4:cout<<x<<"%"<<xx;ans=x%xx;
}
op=rand()%5;
if(!op){
cout<<"+"<<xxx;
if(!br){
cout<<"=";
ans+=xxx;
}
else{
cout<<")";
ans+=xxx;
op2=rand()%3;
switch(op2){
case 0:cout<<"×"<<xxxx<<"=";ans*=xxxx;break;
case 1:cout<<"÷"<<xxxx<<"=";ans/=xxxx;break;
case 2:cout<<"%"<<xxxx<<"=";ans%=xxxx;
}
}
}
else if(op==1){
cout<<"-"<<xxx;
if(!br){
cout<<"=";
ans-=xxx;
}
else{
cout<<")";
ans-=xxx;
op2=rand()%3;
switch(op2){
case 0:cout<<"×"<<xxxx<<"=";ans*=xxxx;break;
case 1:cout<<"÷"<<xxxx<<"=";ans/=xxxx;break;
case 2:cout<<"%"<<xxxx<<"=";ans%=xxxx;
}
}
}
else if(op==2){
if(br)
cout<<")";
cout<<"×"<<xxx<<"=";
ans*=xxx;
}
else if(op==3){
if(br)
cout<<")";
cout<<"÷"<<xxx<<"=";
ans/=xxx;
}
else{
if(br)
cout<<")";
cout<<"%"<<xxx<<"=";
ans%=xxx;
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
cin>>ssol;
if(ssol==ans){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<"答案正確!";
Sleep(1500);
}
else{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
cout<<"答案錯誤!\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout<<"正確答案:";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
cout<<ans;
Sleep(2500);
}
}
}
int main(){
cout<<"\t\t歡迎來到算數小遊戲!\n\n";
cout<<"\t\t 0 -- 加減法\n";
cout<<"\t\t 1 -- 乘除法\n";
cout<<"\t\t 2 -- 加減乘除法\n";
cout<<"\t\t其他序號 -- 退出遊戲\n";
cout<<" 遇到'÷'一律保留整數!\n";
cout<<"\t\t '%'表示取餘!\n";
cout<<"\t\t 請輸入序號:";
cin>>mode1;
if(mode1<0 || mode1>2){
system("cls");
cout<<"\t\t您已退出遊戲!";
return 0;
}
system("cls");
cout<<"\t\t歡迎來到算數小遊戲!\n\n";
cout<<"\t\t 0 -- 簡單\n";
cout<<"\t\t 1 -- 困難\n";
cout<<"\t\t 2 -- 大師\n";
cout<<"\t\t 3 -- 煉獄\n";
cout<<"\t\t 4 -- 非人\n";
cout<<"\t\t其他序號 -- 退出遊戲\n\n";
cout<<"\t\t 請輸入序號:";
cin>>mode2;
if(mode2<0 || mode2>4){
system("cls");
cout<<"\t\t您已退出遊戲!";
return 0;
}
switch(mode1){
case 0:as(mode2);break;
case 1:md(mode2);break;
case 2:asmd(mode2);
}
return 0;
}
————————————————
版权声明:本文为CSDN博主「mikenth」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/AGACEPG/article/details/127836456
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。