Untitled
unknown
c_cpp
4 years ago
2.1 kB
11
Indexable
#include "ConsoleApplication1.h" char map[100][100] = { 0 }; // 全局初始化地图 void printmap(char map[100][100], int high) { for (int i = 0; i < high; i++) { puts(map[i]); } } extern void class1(char map[100][100], int* h, int* x, int* y); void move(char map[100][100], int* x, int* y) { char ch; ch = getch(); // 读取操作 int tmpx, tmpy; tmpx = *x; tmpy = *y; switch (ch) { case 'w': tmpx -= 1; break; case 'a': tmpy -= 1; break; case 's': tmpx += 1; break; case 'd': tmpy += 1; break; default: break; } // 知道了下一步预计会走到的位置的坐标 int tmpx2, tmpy2; tmpx2 = tmpx + tmpx - *x; tmpy2 = tmpy + tmpy - *y; //定义下一步的后面是什么 // 这个地方是墙吗? if (map[tmpx][tmpy] != '#') { //这个地方是空气吗? if (map[tmpx][tmpy] != ' ') { // 这个地方是箱子吗? if (map[tmpx][tmpy] == 'O' || map[tmpx][tmpy] == '@') { // 箱子后面有空地方吗 if (map[tmpx2][tmpy2] == ' ' || map[tmpx2][tmpy2] == '*') { //既然有!那么就人和箱子一起移动! movePlayer(tmpx, tmpy); moveChest(tmpx2, tmpy2); } } } else { //既然是空气,那么就走! movePlayer(tmpx, tmpy); } } } void movePlayer(int tmpx, int tmpy) { } void moveChest(int tmpx2, int tmpy2) { } int main() { int high = 1; // 地图高度 int x = 1, y = 1; // 人的坐标 //载入地图 , 包括地图数组,高度,人物坐标 class1(map, &high, &x, &y); // 首次打印地图 printmap(map, high); //操作与反馈 while (1) { move(map, &x, &y); } printf("人物坐标为 %d %d", x, y); system("pause"); return 0; }
Editor is loading...