?
?//我不理解为什么我点的写文章只能写这种,不能插入代码
#include<stdio.h> #include<stdlib.h> #include<conio.h> #define MAP_ROW 6?? ?//行 #define MAP_LIST 8?? ?//列
#define WALL 1?? ??? ?//墙 #define BOX 2?? ??? ?//箱子 #define BOURN 3?? ??? ?//目的地 #define PEOPLE 4?? ?//人 #define BOX_BOURN 5?? ?//箱子+目的地 #define PEOPLE_BOURN 7//人+目的地
//定义一个数组,用来输出我们的人,箱子,目的地等
int map[MAP_LIST][MAP_ROW] = { ?? ?0,1,1,1,1,0, ?? ?1,0,0,0,1,0, ?? ?1,4,2,0,1,0, ?? ?1,0,2,0,1,0, ?? ?1,1,0,2,0,1, ?? ?1,3,2,0,0,1, ?? ?1,3,3,5,3,1, ?? ?1,1,1,1,1,1 };
//初始化 void initmap() {
//用来遍历整个数组 ?? ?for (int i = 0; i < MAP_LIST; i++) ?? ?{ ?? ??? ?for (int k = 0; k < MAP_ROW; k++) ?? ??? ?{
//遇到对应的打印出来 ?? ??? ??? ?switch (map[i][k]) ?? ??? ??? ?{ ?? ??? ??? ?case 0:printf(" ?"); break; ?? ??? ??? ?case WALL:printf("■"); break; ?? ??? ??? ?case BOX:printf("□"); break; ?? ??? ??? ?case BOURN:printf("☆"); break; ?? ??? ??? ?case PEOPLE:printf("♂"); break; ?? ??? ??? ?case BOX_BOURN:printf("★"); break; ?? ??? ??? ?case PEOPLE_BOURN:printf("♀"); break; ?? ??? ??? ?} ?? ??? ?} ?? ??? ?printf(" "); ?? ?} }
void movepepel(int r,int c,int offr,int offc) { ?? ?if (map[r + offr][c + offc] == 0 || map[r + offr][c + offc] == 3) ?? ?{ ?? ??? ?map[r + offr][c + offc] += PEOPLE; ?? ??? ?map[r][c] -= PEOPLE; ?? ?} ?? ?else if (map[r + offr][c + offc] == 2 || map[r + offr][c + offc] == 5) ?? ?{ ?? ??? ?if (map[r + 2 * offr][c + 2 * offc] == 0 || map[r + 2 * offr][c + 2 * offc] == 3) ?? ??? ?{ ?? ??? ??? ?map[r + 2 * offr][c + 2 * offc] += 2; ?? ??? ??? ?map[r + offr][c + offc] += 2; ?? ??? ??? ?map[r][c] -= PEOPLE; ?? ??? ?} ?? ?} }
void move(int r,int c,bool isFind,int offr,int offc) { ?? ?for (int i = 0; i < MAP_LIST; i++) ?? ?{ ?? ??? ?for (int k = 0; k < MAP_ROW; k++) ?? ??? ?{ ?? ??? ??? ?if (map[i][k] == PEOPLE || map[i][k] == 7) ?? ??? ??? ?{ ?? ??? ??? ??? ?r = i; ?? ??? ??? ??? ?c = k; ?? ??? ??? ??? ?isFind = true; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ??? ?if (isFind) ?? ??? ??? ??? ?break; ?? ??? ?} ?? ?} ?? ?char key = _getch(); ?? ?switch (key) ?? ?{ ?? ?case 72:offr = -1, offc = 0; break; ?? ?case 80:offr = 1, offc = 0; break; ?? ?case 75:offr = 0, offc = -1; break; ?? ?case 77:offr = 0, offc = 1; break; ?? ?} ?? ?movepepel(r, c, offr, offc); }
void juden() { ?? ?int count = 0; ?? ?for (int i = 0; i < MAP_LIST; i++) ?? ?{ ?? ??? ?for (int k = 0; k < MAP_ROW; k++) ?? ??? ?{ ?? ??? ??? ?if (map[i][k] == 3) ?? ??? ??? ?{ ?? ??? ??? ??? ?count++; ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?if (count == 0) ?? ?{ ?? ??? ?printf("你赢了"); ?? ??? ?initmap(); ?? ??? ?exit(0); ?? ?} }
int main() { ?? ?int isFind = false; ?? ?int r = 0; ?? ?int c = 0; ?? ?int offr = 0, offc = 0; ?? ?while (1) { ?? ??? ?system("cls"); ?? ??? ?initmap(); ?? ??? ?move(r,c,isFind,offr, offc); ?? ??? ?juden(); ?? ?} ?? ?return 0; }
?
|