老版推箱子

    xiaoxiao2021-03-25  159

    /******************************************** 项    目: 推箱子 作    者: 零起点 编译环境:VS 2015 最后修改:2017年3月8日 *********************************************/ #include <stdio.h> #include<stdlib.h> #include <conio.h> #include<dos.h> int chart[8][8] = { {0,1,1,1,1,1,0,0}, {0,1,0,5,1,1,1,0}, {0,1,0,4,0,0,1,0}, {1,1,1,0,1,0,1,1}, {1,3,1,0,1,0,0,1}, {1,3,4,0,0,1,0,1}, {1,3,0,0,0,4,0,1}, {1,1,1,1,1,1,1,1} }; int  pox_x,pox_y; void  outlet(void); //输出图案 void The_key(void); //向上走的功能 void Left_key(void); //向左走的功能 void hand_button(void); //向下走的功能 void next_key(void); //向右走的功能 int judge(void); //判断箱子是否在指定位置 int main(void) { char ch; int sum; for (pox_x = 0; pox_x < 8; ++pox_x) { for (pox_y = 0; pox_y < 8; ++pox_y) if (chart[pox_x][pox_y] == 5) break; if (chart[pox_x][pox_y] == 5) break; }//找出  人 的 位置   必须用两个  if  不然会 出错 while (1) { outlet(); fflush(stdin);//更新窗口 switch (getch())//接受 键盘的值 { case 72://上键 The_key(); break; case 80://下键 hand_button(); break; case 75://左键 Left_key(); break; case 77: next_key(); break; } if ((sum = judge()) == 3) { printf("你赢了!!"); break; } } system("pause"); return 0; } void  outlet(void) { system("cls");//清屏 for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) switch (chart[i][j]) { case 0:printf("  "); break; case 1:printf("※"); break; case 3:printf("☆"); break; case 4:printf("□"); break; case 8: case 5:printf("♂"); break; case 7:printf("★"); break; } putchar('\n'); } return; } void The_key(void) { if ((chart[pox_x - 1][pox_y] == 0 || chart[pox_x - 1][pox_y] == 3) && pox_x - 1 != -1) { if(chart[pox_x-1 ][pox_y] == 3) chart[pox_x - 1][pox_y] = 8; else chart[pox_x - 1][pox_y] = 5; if(chart[pox_x ][pox_y] == 8) chart[pox_x][pox_y] = 3; else chart[pox_x][pox_y] = 0; pox_x -= 1; } else if (chart[pox_x - 1][pox_y] == 4 && (pox_x - 2 != -1 && chart[pox_x - 2][pox_y]  != 1)) { if(chart[pox_x - 2][pox_y] != 3) chart[pox_x - 2][pox_y] = 4; else { chart[pox_x - 2][pox_y] = 7; chart[pox_x - 1][pox_y] = 5; chart[pox_x][pox_y] = 3; } pox_x -= 1; else if (chart[pox_x - 1][pox_y] == 7 && (pox_x - 2 != -1 && chart[pox_x - 2][pox_y] != 1)) { if (chart[pox_x - 2][pox_y] == 3) { chart[pox_x - 2][pox_y] = 7; chart[pox_x - 1][pox_y] = 8; } if (chart[pox_x][pox_y] == 8) chart[pox_x][pox_y] = 3; else chart[pox_x][pox_y] = 0; pox_x -= 1; } return; } void hand_button(void) { if ((chart[pox_x + 1][pox_y] == 0 || chart[pox_x + 1][pox_y] == 3) && pox_x + 1 != 8) { if (chart[pox_x+1][pox_y] == 3) chart[pox_x + 1][pox_y] = 8; else chart[pox_x + 1][pox_y] = 5; if (chart[pox_x][pox_y] == 8) chart[pox_x][pox_y] = 3; else chart[pox_x][pox_y] = 0; pox_x += 1; } else if (chart[pox_x + 1][pox_y] == 4 && (pox_x + 2 != 8 && chart[pox_x + 2][pox_y] != 1)) { if (chart[pox_x + 2][pox_y] != 3) { chart[pox_x + 2][pox_y] = 4; chart[pox_x + 1][pox_y] = 5; chart[pox_x][pox_y] = 0; } else { chart[pox_x + 2][pox_y] = 7; chart[pox_x + 1][pox_y] = 5; chart[pox_x][pox_y] = 3; } pox_x += 1; } return; } void next_key(void) { if ((chart[pox_x][pox_y + 1] == 0 || chart[pox_x][pox_y + 1] == 3) && pox_y + 1 != 8) { if (chart[pox_x][pox_y + 1] == 3) chart[pox_x][pox_y +1] = 8; else chart[pox_x][pox_y + 1] = 5; if (chart[pox_x][pox_y] == 8) chart[pox_x][pox_y] = 3; else chart[pox_x][pox_y] = 0; pox_y += 1; } else if (chart[pox_x][pox_y + 1] == 4 && (pox_y + 2 != 8 && chart[pox_x][pox_y + 2] != 1)) { if (chart[pox_x][pox_y + 2] != 3) { chart[pox_x][pox_y + 2] = 4; chart[pox_x][pox_y + 1] = 5; chart[pox_x][pox_y] = 0; } else { chart[pox_x][pox_y +2] = 7; chart[pox_x][pox_y + 1] = 5; chart[pox_x][pox_y] = 0; } pox_y += 1; } return; } void Left_key(void) { if ((chart[pox_x][pox_y - 1] == 0 || chart[pox_x][pox_y - 1] == 3) && pox_y - 1 != -1) { if (chart[pox_x][pox_y - 1] == 3) chart[pox_x][pox_y - 1] = 8; else chart[pox_x][pox_y - 1] = 5; if (chart[pox_x][pox_y] == 8) chart[pox_x][pox_y] = 3; else chart[pox_x][pox_y] = 0; pox_y -= 1; } else if (chart[pox_x][pox_y - 1] == 4 && (pox_y - 2 != -1 && chart[pox_x][pox_y - 2] != 1)) { if (chart[pox_x][pox_y - 2] != 3) { chart[pox_x][pox_y - 2] = 4; chart[pox_x][pox_y - 1] = 5; chart[pox_x][pox_y ] = 0; } else  { chart[pox_x][pox_y -2] = 7; chart[pox_x][pox_y - 1] = 5; chart[pox_x][pox_y] = 0; } pox_y -= 1; } return; } int  judge(void) { int sum = 0; for(int i=0;i<8;i++) for (int j = 0; j < 8; ++j) { if (chart[i][j] == 7) ++sum; } return sum; }
    转载请注明原文地址: https://ju.6miu.com/read-4494.html

    最新回复(0)