推箱子小游戏代码多少
① 谁有推箱子的C语言游戏代码
#include <dos.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <bios.h>
#include <alloc.h>
/* 定义二维数组ghouse来记录屏幕上各点的状态,
其中:0表示什么都没有,'b'表示箱子,'w'表示墙壁,'m'表示目的地,'i'表示箱子在目的地。 */
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;
}
② 求推箱子小游戏的VB代码
网络“推箱子 dim”
③ Java推箱子怎么写啊
这是我之前写的一篇java实现推箱子算法的文章,简单的给你看一下:
《推箱子游戏》是一款益智游戏,游戏目标是搬运工自己来找出到某个位置的最短路径,然后自己走过去。
最后完成地图显示问题,每个节点存储自己父亲节点的地址,当节点发现自己已经完成之后根据地址向上查找直到树顶,望采纳,谢谢。
④ 本人需要用JAVA编写一个推箱子的小游戏 源代码有了 但是缺少做推箱子这小游戏的图片
package com.txz1;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Txz {
public static void main(String[] args) {
JFrame frame = new JFrame("������1.0");//����
frame.setBounds(100, 20, 20 * 48 + 16, 14 * 48 + 38);//���ý���λ�úʹ�С
JPanel panel = new JPanel();//��壬�൱������
panel.setBackground(Color.red);//������ɫ
frame.setContentPane(panel);
panel.setLayout(null);//�Զ��壬���λ��
//�������
ImageIcon boxImg = new ImageIcon("box2.PNG");
JLabel box = new JLabel(boxImg);//��ǩ���൱������
panel.add(box);
box.setBounds(5 * 48, 3 * 48, 48, 48);
//��ӹ���
ImageIcon workerImg = new ImageIcon("workerDown2.png");
JLabel worker = new JLabel(workerImg);
panel.add(worker);
worker.setBounds(8 * 48, 8 * 48, 48, 48);
//����ϰ���
ImageIcon goalImg = new ImageIcon("goal2.png");
JLabel goal = new JLabel(goalImg);
panel.add(goal);
goal.setBounds(7 * 48, 6 * 48, 48, 48);
//���Χǽ
ImageIcon wallImg = new ImageIcon("wall2.PNG");
JLabel[] walls = new JLabel[100];
for (int i = 0; i < walls.length; i++) {
walls[i] = new JLabel(wallImg);
}
int index = 0;//������������ͳ��Χǽ����
for (int i = 0; i < 20; i++) {
panel.add(walls[index]);
walls[index].setBounds(i * 48, 0, 48, 48);
index++;
panel.add(walls[index]);
walls[index].setBounds(i * 48, 13 * 48, 48, 48);
index++;
}
for (int i = 0; i < 12; i++) {
panel.add(walls[index]);
walls[index].setBounds(0, (i + 1) * 48, 48, 48);
index++;
panel.add(walls[index]);
walls[index].setBounds(19 * 48, (i + 1) * 48, 48, 48);
index++;
}
for (int i = 0, j = 0; i < 5; i++, j += 2) {
panel.add(walls[index]);
walls[index].setBounds((i + 2) * 48, j * 48, 48, 48);
index++;
}
for (int i = 0, j = 10; i < 5; i++, j--) {
panel.add(walls[index]);
walls[index].setBounds((i + 12) * 48, j * 48, 48, 48);
index++;
}
//����Ϊ�ɼ��
frame.setVisible(true);
}
}
⑤ 用汇编语言编写一个推箱子游戏
出来了,代码如下:
data segment
car db 2,2,2,2,2,2,2,2,2,2
db 2,2,2,2,2,2,0,0,0,2
db 2,2,2,2,2,2,0,0,0,2
db 2,2,2,2,2,2,0,0,0,2
db 2,2,2,2,2,2,2,2,2,2
db 2,2,2,2,2,2,2,2,2,2
db 0,0,2,0,0,0,0,2,0,0
db 0,2,0,2,0,0,2,0,2,0
db 0,0,2,0,0,0,0,2,0,0
x dw 10
y dw 10
msg db 'car program finish!!$'
speed dw 5
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov ax,0a000h
mov es,ax
mov ax,13h
int 10h
call picture
ag: mov ah,7
int 21h
cmp al,'s'
jne ag
start1: in al,60h
cmp al,80h ;if release key
jae keyrelease
cmp al,2 ;1 key
jz upspeed
cmp al,3 ;2 key
jz downspeed
jmp keyrelease
upspeed:
mov si,speed
inc si
mov speed,si
jmp keyrelease
downspeed:
mov si,speed
dec si
mov speed,si
jmp keyrelease
keyrelease:
call clearpicture
mov si,speed
add si,x
mov x,si
call picture
call delay
mov si,x
cmp si,310
jc start1
mov ah,9
mov dx,offset msg
int 21h
mov ah,7
int 21h
mov ax,4c00h
int 21h
picture proc near
mov dx,y
mov bx,0
again: cmp dx,0
je over
add bx,320
dec dx
jmp again
over: mov dx,9
lea si,car
next1: mov cx,10
mov di,x
next: mov al,[si]
mov es:[bx+di],al
inc si
inc di
loop next
add bx,320
dec dx
jne next1
ret
picture endp
clearpicture proc near
mov dx,y
mov bx,0
again2: cmp dx,0
je over2
add bx,320
dec dx
jmp again2
over2: mov dx,9
next12: mov cx,10
mov di,x
next2: mov al,0
mov es:[bx+di],al
inc di
loop next2
add bx,320
dec dx
jne next12
ret
clearpicture endp
delay proc near
push bx
push cx
mov bx,1234
back:
mov cx,66
push ax
wait1:
in al,61h
and al,10h
cmp al,ah
je wait1
mov ah,al
loop wait1
pop ax
dec bx
jne back
pop cx
pop bx
ret
delay endp
code ends
end start
⑥ 求个推箱子的C++代码 要有注解 800到1000行
//*******************************************************
Sokoban.h:类定义Sokoban.c:类成员函数实现
Use_Sokoban.c:主函数
请用VC6(别编译器的也行)先运行Use_Sokoban.c文件,要编译该文件一下,
再点Project->AddToProject->Files选择Sokoban.c文件,
即将Sokoban.c加载到工程里,最后运行就OK拉。
//*******************************************************
Sokoban.h
//*******************************************************
#ifndefSOKOBAN_H_//防止文件重复包含
#defineSOKOBAN_H_
#include<queue>
usingstd::queue;
//每一步的数据类型
structnode
{
intbx,by;//箱子的坐标
intpx,py;//人的坐标
};
//推箱子类
classSokoban
{
private:
enum{L=15,H=7};
charGameMap[H][L];//地图
intPex,Pey;//人的位置
intBoxx,Boxy;//箱子的位置
intSucceed,Prove;//是否成功到目的地,是否可玩性
intdx[4],dy[4];//方向数组
protected:
charEmpty;
charPeople;
charBox;
charBlock;
charTarget;
intdir;//记录按键方向
nodes,e;
public:
Sokoban();//构建函数
~Sokoban(){}//析构函数,即为inline
//地图初始化函数
voidInitial();
//箱子路劲验证函数,参数为箱子坐标(bx,by),人坐标(px,py)
voidBox_Bfs(intbx,intby,intpx,intpy);
//人路劲验证函数,人所到的目的地(ex,ey)
boolPeople_Bfs(intex,intey);
//地图刷新函数
voidShow();
//按键判断函数
voidButton();
//箱子人移动函数
voidMove();
//验证越界函数
boolCheck(intx,inty);
};
#endif
//*******************************************************
Sokoban.cpp
//*******************************************************
#include"Sokoban.h"
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<conio.h>
usingstd::cout;
usingstd::endl;
Sokoban::Sokoban()//构建函数即对变量初始化
{
dir=-1;
Succeed=Prove=0;
memset(GameMap,'.',sizeof(GameMap));
Empty='.';
People='P';
Box='#';
Block='*';
Target='T';
//方向依次为上右下左
dx[0]=-1;dx[1]=0;dx[2]=1;dx[3]=0;
dy[0]=0;dy[1]=1;dy[2]=0;dy[3]=-1;
//随机种子,使程序每次运行时所产生的随机数不同
srand(time(0));
}
//地图初始化函数
voidSokoban::Initial()
{
intcount=0,x,y;
//对地图中随机产生25个阻碍物
while(count!=25)
{
x=rand()%H;
y=rand()%L;
if(GameMap[x][y]==Empty)
{
GameMap[x][y]=Block;
count++;
}
}
while(true)//随机产生人开始的位置
{
x=rand()%H;
y=rand()%L;
if(GameMap[x][y]==Empty)
{
GameMap[x][y]=People;
Pex=x;
Pey=y;
break;
}
}
while(true)//随机产生箱子开始的位置
{
x=rand()%H;
y=rand()%L;
//不让箱子在地图的边界处
if(GameMap[x][y]==Empty&&x!=0&&y!=0
&&x!=H-1&&y!=L-1)
{
GameMap[x][y]=Box;
Boxx=x;
Boxy=y;
break;
}
}
while(true)//随机产生目标的位置
{
x=rand()%H;
y=rand()%L;
if(GameMap[x][y]==Empty)
{
GameMap[x][y]=Target;
break;
}
}
//对游戏地图检查是否可将箱子推到目的地,即判断游戏可玩性
Sokoban::Box_Bfs(Boxx,Boxy,Pex,Pey);
//如游戏不可玩,即再随机产生地图
if(!Prove)
{
memset(GameMap,'.',sizeof(GameMap));
Sokoban::Initial();
}
else
Sokoban::Show();
}
//箱子路劲验证函数
//用BFS算法对箱子验证是否可到目的地
voidSokoban::Box_Bfs(intbx,intby,intpx,intpy)
{
queue<node>_Box;//创建箱子队列
//visit对上一步走到下一步的记录,防止箱子走重复路劲
//visit[i][j][z][k]表示箱子从点(i,j)到点(z,k)
//visit[][][][]为0时表示为走过,1时表示已走过
intvisit[H][L][H][L];
memset(visit,0,sizeof(visit));//visit数组初始化
s.bx=bx;s.by=by;//将起始的箱子、人位置放入队列
s.px=px;s.py=py;
_Box.push(s);
intpe_x,pe_y;
while(!_Box.empty())//队列为空时跳出
{
s=_Box.front();
_Box.pop();
if(GameMap[s.bx][s.by]==Target)//到达目的地
{
Prove=1;
break;
}
for(inti=0;i<4;i++)
{
e.bx=s.bx+dx[i];e.by=s.by+dy[i];
switch(i)//人推箱子的位置
{
case0:pe_x=s.bx+dx[2];pe_y=s.by+dy[2];break;
case1:pe_x=s.bx+dx[3];pe_y=s.by+dy[3];break;
case2:pe_x=s.bx+dx[0];pe_y=s.by+dy[0];break;
case3:pe_x=s.bx+dx[1];pe_y=s.by+dy[1];break;
}
//验证箱子和人的位置的合法性
if(!Check(e.bx,e.by)||!Check(pe_x,pe_y)
||GameMap[e.bx][e.by]==Block||GameMap[pe_x][pe_y]==Block
||visit[s.bx][s.by][e.bx][e.by])
continue;
//如人可推箱子即进入队列
if(Sokoban::People_Bfs(pe_x,pe_y))
{
//保存人推箱子后的位置
e.px=pe_x;e.py=pe_y;
_Box.push(e);
visit[s.bx][s.by][e.bx][e.by]=1;//箱子路劲的标记
}
}
}
}
//人路劲验证函数
//用BFS算法对人验证是否可推箱子
boolSokoban::People_Bfs(intex,intey)
{
queue<node>_People;
nodet,end;
//visit数组对人的路劲进行标记,0为未走过,1为走过
intvisit[H][L];
//visit数组初始化为0
memset(visit,0,sizeof(visit));
t.px=s.px;t.py=s.py;//人初始位置进入队列
_People.push(t);
visit[t.px][t.py]=1;
while(!_People.empty())//对立为空时跳出
{
t=_People.front();
_People.pop();
if(t.px==ex&&t.py==ey)//人可到达(ex,ey)该点
return1;
for(inti=0;i<4;i++)
{
end.px=t.px+dx[i];end.py=t.py+dy[i];
//检查人的位置合法性
if(!Check(end.px,end.py)||GameMap[end.px][end.py]==Block
||GameMap[end.px][end.py]==Box||visit[end.px][end.py])
continue;
//进入队列
_People.push(end);
visit[end.px][end.py]=1;//记录
}
}
return0;
}
//地图刷新函数
voidSokoban::Show()
{
inti,j;
while(true)
{
//每半秒刷新一次地图
clock_ts=clock();
while(clock()-s<CLOCKS_PER_SEC/2)
;
//先判断按键在移动
Sokoban::Button();
Sokoban::Move();
system("cls");
for(i=0;i<H;i++)
{
for(j=0;j<L;j++)
cout<<GameMap[i][j];
cout<<endl;
}
cout<<endl;
cout<<" **********************************"<<endl;
cout<<"*小小C++语言推箱子游戏*"<<endl;
cout<<"*游戏规则:*"<<endl;
cout<<"*P:人#:箱子*"<<endl;
cout<<"**:障碍物T:目的地*"<<endl;
cout<<"**********************************"<<endl;
cout<<"*每次游戏地图不一样*"<<endl;
cout<<"*人将箱子推到目的地即过关*"<<endl;
cout<<"*所给地图,一定可过关,请慎重移箱子*"<<endl;
cout<<"*箱子无路可走时,机器不会提示*"<<endl;
cout<<"**********************************"<<endl;
//箱子成功到达目的地
if(Succeed)
{
cout<<" ^_^>_<"<<endl;
cout<<"恭喜过关成功!再来一盘吧"<<endl;
getchar();
break;
}
}
}
//按键判断函数
voidSokoban::Button()
{
intkey;
if(kbhit()!=0)//检查当前是否有键盘输入,若有则返回一个非0值,否则返回0
{
while(kbhit()!=0)//可能存在多个按键,要全部取完,以最后一个为主
key=getch();//将按键从控制台中取出并保存到key中
switch(key)
{
//上
case72:dir=0;
break;
//右
case77:dir=1;
break;
//下
case80:dir=2;
break;
//左
case75:dir=3;
break;
}
}
}
//人推箱子移动函数
voidSokoban::Move()
{
intx,y;
//有按键时
if(dir!=-1)
{
//人所推向的位置坐标
x=Pex+dx[dir];y=Pey+dy[dir];
//人所推位置为空,即走向该位置
if(Check(x,y)&&GameMap[x][y]=='.')
{
GameMap[Pex][Pey]='.';//人的位置改变
GameMap[x][y]='P';
Pex=x;Pey=y;
dir=-1;//按键记录为无即-1
}
else//人所推位置为箱子,即将箱子推向该方向的前面这点
if(Check(x,y)&&GameMap[x][y]=='#'
&&Check(x+dx[dir],y+dy[dir])
&&GameMap[x+dx[dir]][y+dy[dir]]=='.')
{
GameMap[Boxx][Boxy]='.';//箱子的位置改变
GameMap[x+dx[dir]][y+dy[dir]]='#';
Boxx=x+dx[dir];Boxy=y+dy[dir];
GameMap[Pex][Pey]='.';//人的位置改变
GameMap[x][y]='P';
Pex=x;Pey=y;
dir=-1;
}
else//将箱子推向该方向的前面这点为目的地
if(Check(x,y)&&GameMap[x][y]=='#'
&&Check(x+dx[dir],y+dy[dir])
&&GameMap[x+dx[dir]][y+dy[dir]]=='T')
{
GameMap[Boxx][Boxy]='.';//箱子的位置改变
GameMap[x+dx[dir]][y+dy[dir]]='#';
Boxx=x+dx[dir];Boxy=y+dy[dir];
GameMap[Pex][Pey]='.';//人的位置改变
GameMap[x][y]='P';
Pex=x;Pey=y;
dir=-1;
Succeed=1;//记录成功到达目的地
}
}
}
//判断越界情况
boolSokoban::Check(intx,inty)
{
if(x<0||x>=H||y<0||y>=L)
return0;
else
return1;
}
//*************************************************
Use_Sokoban.cpp
//*************************************************
#include<iostream>
#include"Sokoban.h"
usingnamespacestd;
intmain()
{
Sokobans;
s.Initial();
return0;
}
//*************************************************
⑦ 求一些C语言小游戏的源代码,谢谢
“推箱子”C代码:
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
#include<windows.h>
int m =0; //m代表第几关
struct maps{short a[9][11]; };
struct maps map[5]={ 0,0,0,0,0,0,0,0,0,0,0, //共5关,每关9行11列
0,1,1,1,1,1,1,1,0,0,0,
0,1,0,0,0,0,0,1,1,1,0,
1,1,4,1,1,1,0,0,0,1,0, //0空地,1墙
1,5,0,0,4,0,0,4,0,1,0, //4是箱子,5是人
1,0,3,3,1,0,4,0,1,1,0, //3是目的地
1,1,3,3,1,0,0,0,1,0,0, //7是箱子在目的地(4+3)
0,1,1,1,1,1,1,1,1,0,0, //8是人在目的地(5+3)
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,1,1,1,1,0,0,0,0,0,
0,0,1,5,0,1,1,1,0,0,0,
0,0,1,0,4,0,0,1,0,0,0,
0,1,1,1,0,1,0,1,1,0,0,
0,1,3,1,0,1,0,0,1,0,0,
0,1,3,4,0,0,1,0,1,0,0,
0,1,3,0,0,0,4,0,1,0,0,
0,1,1,1,1,1,1,1,1,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,1,1,1,1,1,1,0,
0,0,1,1,0,0,1,0,5,1,0,
0,0,1,0,0,0,1,0,0,1,0,
0,0,1,4,0,4,0,4,0,1,0,
0,0,1,0,4,1,1,0,0,1,0,
1,1,1,0,4,0,1,0,1,1,0,
1,3,3,3,3,3,0,0,1,0,0,
1,1,1,1,1,1,1,1,1,0,0,
0,1,1,1,1,1,1,1,1,1,0,
0,1,0,0,1,1,0,0,0,1,0,
0,1,0,0,0,4,0,0,0,1,0,
0,1,4,0,1,1,1,0,4,1,0,
0,1,0,1,3,3,3,1,0,1,0,
1,1,0,1,3,3,3,1,0,1,1,
1,0,4,0,0,4,0,0,4,0,1,
1,0,0,0,0,0,1,0,5,0,1,
1,1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,1,1,1,1,1,0,0,
0,1,1,1,0,0,0,0,1,0,0,
1,1,3,0,4,1,1,0,1,1,0,
1,3,3,4,0,4,0,0,5,1,0,
1,3,3,0,4,0,4,0,1,1,0,
1,1,1,1,1,1,0,0,1,0,0,
0,0,0,0,0,1,1,1,1,0,0,
0,0,0,0,0,0,0,0,0,0,0 };
void DrMap( ) //绘制地图
{ CONSOLE_CURSOR_INFO cursor_info={1,0}; //隐藏光标的设置
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
printf(" 推箱子");
printf(" ");
for (int i = 0; i < 9; i++)
{for (int j = 0; j < 11; j++)
{switch (map[m].a[i][j])
{case 0: printf(" "); break;
case 1: printf("■"); break;
case 3: printf("◎");break;
case 4: printf("□"); break;
case 5: printf("♀"); break; //5是人
case 7: printf("□"); break; //4 + 3箱子在目的地中
case 8: printf("♀");break; // 5 + 3人在目的地中
}
}
printf(" ");
}
}
void gtxy(int x, int y) //控制光标位置的函数
{ COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void start( ) //开始游戏
{ int r, c; //人的下标
for (int i = 0; i < 9; i++)
{ for (int j = 0; j < 11; j++)
{if (map[m].a[i][j] == 5||map[m].a[i][j]==8) { r = i; c = j; } } //i j 人的下标
}
char key;
key = getch( );
switch (key)
{case 'W':
case 'w':
case 72:
if (map[m]. a[r - 1][c] == 0|| map[m]. a [r - 1][c] == 3)
{ gtxy(2*c+8,r-1+3); printf("♀"); // gtxy(2*c+8,r-1+3)是到指定位置输出字符
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r - 1][c] += 5; map[m]. a [r][c] -= 5; }
else if (map[m]. a [r - 1][c] == 4 || map[m]. a [r - 1][c] == 7)
{ if (map[m]. a [r - 2][c] == 0 || map[m]. a [r - 2][c] == 3)
{ gtxy(2*c+8,r-2+3); printf("□"); gtxy(2*c+8,r-1+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r - 2][c] += 4; map[m]. a [r - 1][c] += 1;
map[m]. a [r][c] -= 5; }
} break;
case 'S':
case 's':
case 80:
if (map[m]. a [r + 1][c] == 0 || map[m]. a [r + 1][c] == 3)
{ gtxy(2*c+8,r+1+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r + 1][c] += 5; map[m]. a [r][c] -= 5; }
else if (map[m]. a [r + 1][c] == 4 || map[m]. a [r+ 1][c] == 7)
{ if (map[m]. a [r + 2][c] == 0 || map[m]. a [r + 2][c] == 3)
{ gtxy(2*c+8,r+2+3); printf("□"); gtxy(2*c+8,r+1+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r + 2][c] += 4; map[m]. a [r + 1][c] += 1;
map[m]. a [r][c] -= 5; }
}break;
case 'A':
case 'a':
case 75:
if (map[m]. a [r ][c - 1] == 0 || map[m]. a [r ][c - 1] == 3)
{ gtxy(2*(c-1)+8,r+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r ][c - 1] += 5; map[m]. a [r][c] -= 5; }
else if (map[m]. a [r][c - 1] == 4 || map[m]. a [r][c - 1] == 7)
{if (map[m]. a [r ][c - 2] == 0 || map[m]. a [r ][c - 2] == 3)
{ gtxy(2*(c-2)+8,r+3); printf("□"); gtxy(2*(c-1)+8,r+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r ][c - 2] += 4; map[m]. a [r ][c - 1] += 1;
map[m]. a [r][c] -= 5; }
}break;
case 'D':
case 'd':
case 77:
if (map[m]. a [r][c + 1] == 0 || map[m]. a [r][c + 1] == 3)
{ gtxy(2*(c+1)+8,r+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8) {gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r][c + 1] += 5; map[m]. a [r][c] -= 5; }
else if (map[m]. a [r][c + 1] == 4 || map[m]. a [r][c + 1] == 7)
{ if (map[m]. a [r][c + 2] == 0 || map[m]. a [r][c + 2] == 3)
{ gtxy(2*(c+2)+8,r+3); printf("□"); gtxy(2*(c+1)+8,r+3); printf("♀");
if(map[m]. a[r ][c] == 5){gtxy(2*c+8,r+3); printf(" "); }
if(map[m]. a[r ][c] == 8){gtxy(2*c+8,r+3); printf("◎");}
map[m]. a [r][c + 2] += 4; map[m]. a [r][c + 1] += 1;
map[m]. a [r][c] -= 5; }
}break;
}
}
int ifwan( ) //是否完成(1是0否)
{ if(m==0){if(map[m].a[5][2]==7&& map[m].a[5][3]==7&&
map[m].a[6][2]==7&& map[m].a[6][3]==7) return 1;}
if(m==1){if(map[m].a[5][2]==7&& map[m].a[6][2]==7&&
map[m].a[7][2]==7) return 1;}
if(m==2){if(map[m].a[7][1]==7&& map[m].a[7][2]==7&& map[m].a[7][3]==7&&
map[m].a[7][4]==7&& map[m].a[7][5]==7) return 1;}
if(m==3){if(map[m].a[4][4]==7&& map[m].a[4][5]==7&& map[m].a[4][6]==7&&
map[m].a[5][4]==7&& map[m].a[5][5]==7&& map[m].a[5][6]==7) return 1;}
if(m==4){if(map[m].a[3][2]==7&& map[m].a[4][1]==7&& map[m].a[4][2]==7&&
map[m].a[5][1]==7&& map[m].a[5][2]==7) return 1;}
return 0;
}
int main( ) //主函数
{ while (1)
{ system("cls");
DrMap( );
while (1)
{ start( );
if(ifwan()){printf("