c语言,有什么办法可以判断前面是否有箱子?(推箱子小游戏,c语言,不是c++)
- 提问者网友:活着好累
- 2021-02-17 15:09
- 五星知识达人网友:罪歌
- 2021-02-17 16:43
打个比方: 二维数组中某点的值为0, 表示地图上该点位置为空, 为1,表示地图上该点位置为墙, 为2,表示地图上该点位置为人, 为3,表示地图上该点位置为箱子
实际上要判断某点有无箱子或墙, 只要判断数组中该点的值
- 1楼网友:第幾種人
- 2021-02-17 17:23
#include <dos.h> #include <stdio.h> #include <ctype.h> #include <conio.h> #include <bios.h> #include <alloc.h> char ghouse[20][20];
char far *screen=(char far* )0xb8000000; void putchxy(int y,int x,char ch,char fc,char bc) { screen[(x*160)+(y<<1)+0]=ch; screen[(x*160)+(y<<1)+1]=(bc*16)+fc; }
typedef struct winer { int x,y; struct winer *p; }winer;
typedef struct boxs { int x,y; struct boxs *next; }boxs;
void printwall(int x,int y) { putchxy(y-1,x-1,219,magenta,black); ghouse[x][y]='w'; }
void printbox(int x,int y) { putchxy(y-1,x-1,10,white,black); ghouse[x][y]='b'; }
void printwhither1(int x,int y,winer **win,winer **pw) { winer *qw; putchxy(y-1,x-1,'*',yellow,black); ghouse[x][y]='m'; if(*win==null) { *win=*pw=qw=(winer* )malloc(sizeof(winer)); (*pw)->x=x;(*pw)->y=y;(*pw)->p=null; } else { qw=(winer* )malloc(sizeof(winer)); qw->x=x;qw->y=y;(*pw)->p=qw;(*pw)=qw;qw->p=null; } }
void printwhither(int x,int y) { putchxy(y-1,x-1,'*',yellow,black); ghouse[x][y]='m'; } void printman(int x,int y) { gotoxy(y,x); _al=02;_cx=01;_ah=0xa; geninterrupt(0x10); }
void printboxin(int x,int y) { putchxy(y-1,x-1,10,yellow,black); ghouse[x][y]='i'; }
void init() { int i,j; clrscr(); for(i=0;i<20;i++) for(j=0;j<20;j++) ghouse[i][j]=0; _al=3; _ah=0; geninterrupt(0x10); gotoxy(40,4); printf("welcome to push box world!"); gotoxy(40,6); printf("press up,down,left,right to play."); gotoxy(40,8); printf("press esc to quit it."); gotoxy(40,10); printf("press space to reset the game."); gotoxy(40,12); printf("april 30th 2004."); }
winer *inithouse1() { int x,y; winer *win=null,*pw; gotoxy(8,2); printf("level no.1"); for(x=1,y=5;y<=9;y++) printwall(x+4,y+10); for(y=5,x=2;x<=5;x++) printwall(x+4,y+10); for(y=9,x=2;x<=5;x++) printwall(x+4,y+10); for(y=1,x=3;x<=8;x++) printwall(x+4,y+10); for(x=3,y=3;x<=5;x++) printwall(x+4,y+10); for(x=5,y=8;x<=9;x++) printwall(x+4,y+10); for(x=7,y=4;x<=9;x++) printwall(x+4,y+10); for(x=9,y=5;y<=7;y++) printwall(x+4,y+10); for(x=8,y=2;y<=3;y++) printwall(x+4,y+10); printwall(5+4,4+10); printwall(5+4,7+10); printwall(3+4,2+10); printbox(3+4,6+10); printbox(3+4,7+10); printbox(4+4,7+10); printwhither1(4+4,2+10,&win,&pw); printwhither1(5+4,2+10,&win,&pw); printwhither1(6+4,2+10,&win,&pw); printman(2+4,8+10); return win; }