#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <windows.h>
using namespace std;
int main()
{//地图资源
int GameMap[2][4][4] = {
{ { 1, 2, 3, 4 },
{ 4, 3, 2, 1 },
{ 4, 3, 2, 1 },
{ 1, 2, 3, 4 } },
{{ 1, 2, 3, 4 },
{ 4, 3, 2, 1 },
{ 4, 3, 2, 1 },
{ 1, 2, 3, 4 } }
};
for (int i = 0; i < 2; i++)
{
while (true)
{
//刷新地图资源
for (int x = 0; x < 4; x++)
{
for (int y = 0; y < 4; y++)
{
switch (GameMap[i][x][y])
{
case 0:
cout << " ";
break;
case 1:
case 2:
case 3:
case 4:
cout << "▄" ;
}
}
cout << endl;
}
int PosX1, PosX2, PosY1, PosY2;//定义4个变量用来存储输入坐标
//对坐标进行赋值
cout << "请输入你想要验证的2个坐标,每一个坐标用空格隔开" << endl;
cout << "第一个:";
cin >> PosX1 >> PosY1;
cout << endl;
cout << "第二个:";
cin >> PosX2 >> PosY2;
cout << endl;
for (int i = 0; i < 100; i++)
{
if ((PosX1 == PosX2&&PosY1 == PosY2) || PosX1 < 0 || PosX2 < 0 || PosY1 < 0 || PosY2 < 0 || PosX1 >= 4 || PosX2 >= 4 || PosY1 >= 4 || PosY2 >= 4)//判断输入是否正确
{
cout << "输入错误,请重新输入!" << endl;
cout << "第一个:";
cin >> PosX1 >> PosY1;
cout << "第二个:";
cin >> PosX2 >> PosY2;
}
else
break;
}
system("CLS");//清屏
//如果它们相等
if (GameMap[i][PosX1][PosY1] == GameMap[i][PosX2][PosY2])
{
GameMap[i][PosX1][PosY1] = 0;
GameMap[i][PosX2][PosY2] = 0;
}
//如果它们不相等,告诉玩家这两个是什么
else
{
for (int x = 0; x < 4; x++)
{
for (int y = 0; y < 4; y++)
{
if ((PosX1 == x&&PosY1 == y) || (PosX2 == x&&PosY2 == y))
{
switch (GameMap[i][x][y])
{
case 0:
cout << " ";
break;
case 1:
cout << "◢" ;
break;
case 2:
cout << "◣" ;
break;
case 3:
cout << "◥" ;
break;
case 4:
cout << "◤" ;
break;
}
}
else
{
switch (GameMap[i][x][y])
{
case 0:
cout << " ";
break;
case 1:
case 2:
case 3:
case 4:
cout << "▄";
}
}
}
cout << endl;
}
Sleep(800);
system("CLS");//清屏
}
int num = 0;
//判断是否通过次关
for (int x = 0; x < 4; x++)
{
for (int y = 0; y < 4; y++)
{
if (0 != GameMap[i][x][y])
{
num++;
}
}
}
if (0 == num)
{
system("CLS");//清屏
cout << "恭喜闯过本关"<<endl;
i++;
}
//判断是否已经完全通关
if (2 == i)
{
goto lab1;
}
}
}
lab1:system("CLS");//清屏
cout << "闯关成功" << endl;
return 0;
}
c++对对碰
最新推荐文章于 2023-10-16 19:58:52 发布