记 忆 卡 牌!
2025-01-22 19:56:22
发布于:广东
又是新的游戏代码~
不过这一次游戏不一样哦~
这次是好久之前写的代码!
可能有亿点点bug
在游戏文件夹里翻到的
游戏代码
#include <bits/stdc++.h>
#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;
int main(){
bool boo=0;
cout << "记忆卡牌游戏规则" << endl;
cout << "现有16张数字卡牌,由数字1~8组成,每个数字只出现2次" << endl;
cout << "游戏者需要将卡牌翻至背面,找出所有相同的数字" << endl;
cout << "每一轮只允许翻两张卡牌" << endl;
cout << "如果卡牌数字相同,则将卡牌上有数字的一面显示出来" << endl;
cout << "否则将卡牌翻回正面,进行下一轮" << endl;
cout << "系统测量游戏者找出所有相同数字的卡牌所花费的步数(即进行多少轮)" << endl;
cout<<"懂了吗?";
cout<<"按任意键开始.....";
getch();
system("cls");
cout<<"----------------开始!----------------";
Sleep(1000);
system("cls");
int zhu[17];
for(int i=1;i<=8;i++){
zhu[(i)*2-2]=i;
zhu[(i)*2-1]=i;
}
srand(time(0));
int a[5][5],k;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
while(true){
k=rand()%16;
if(zhu[k]!=0){
break;
}
}
a[i][j]=zhu[k];
zhu[k]=0;
}
}
int arr[5][5];
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
arr[i][j]=0;
}
}
int ix,iy,jx,jy;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
cout<<'*'<<' ';
}
cout<<endl;
}
int X;
while(true){
cout<<"说吧,第一次翻第几行,第几列?:";
cin>>ix>>iy;
ix-=1;
iy-=1;
arr[ix][iy]+=1;
system("cls");
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(arr[i][j]>0) cout<<a[i][j]<<' ';
else cout<<'*'<<' ';
}
cout<<endl;
}
cout<<"说吧,第二次翻第几行,第几列?:";
cin>>jx>>jy;
jx-=1;
jy-=1;
arr[jx][jy]+=1;
system("cls");
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(arr[i][j]>0) cout<<a[i][j]<<' ';
else cout<<'*'<<' ';
}
cout<<endl;
}
Sleep(1000);
if(ix==jx and iy==jy){
cout<<"由于你卡bug了,所以我要让你强制休息2秒!!!!(真的哦)";
// Sleep(2000); 假的啦
}
else if(a[ix][iy]==a[jx][jy]){
X=MessageBox(0,"你对了!","恭喜!",0);
}
else{
arr[ix][iy]-=1;
arr[jx][jy]-=1;
}
system("cls");
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(arr[i][j]>0) cout<<a[i][j]<<' ';
else{
boo=1;
cout<<'*'<<' ';
}
}
cout<<endl;
}
if(boo==0){
X=MessageBox(0,"恭喜!","你完成了挑战!",0);
return 0;
}
boo=0;
}
return 0;
}
关注点赞别忘了哦~
全部评论 1
感谢支持!
2025-01-22 来自 广东
0
有帮助,赞一个