C++部分游戏基础(有注释)
2023-08-25 10:24:49
发布于:浙江
#include<iostream>
#include<string>
#include<windows.h>
#include<conio.h>
using namespace std;
int main() {
int a[19][19];
for (int h = 0; h < 19; h++) {
for (int l = 0; l < 19; l++) {
a[h][l] = 0;//清空数组
}
}
int X = 9;
int Y = 9;
a[9][9] = 8;
for (int h = 0; h < 19; h++) {//先输出,要不然要等输入一次后才显示
for (int l = 0; l < 19; l++) {
if (a[h][l] == 8) {
cout << "㊣";
} else {
cout << "。";
}
}
cout << endl;
}
while (true) {
char xx = getch();//用这个函数获取键盘
if (xx == 'w') {//上
Y = Y - 1;
a[Y][X] = 8;
a[Y + 1][X] = 0;
}
if (xx == 's') {//下
Y = Y + 1;
a[Y][X] = 8;
a[Y - 1][X] = 0;
}
if (xx == 'a') {//左
X = X - 1;
a[Y][X] = 8;
a[Y ][X + 1] = 0;
}
if (xx == 'd') {//右
X = X + 1;
a[Y][X] = 8;
a[Y][X - 1] = 0;
}
if (xx == 'e') {//退出
break;
}
system("cls");//清屏
for (int h = 0; h < 19; h++) {
for (int l = 0; l < 19; l++) {
if (a[h][l] == 8) {
cout << "㊣";//有标记
} else {
cout << "。";//没标记
}
}
cout << endl;
}
}
}
这里空空如也
有帮助,赞一个