⑴ 怎么用c语言编写推箱子的简单小游戏
http://blog.csdn.net/pastthewind/article/details/52456178,这里面有代码
⑵ 谁有推箱子的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;
}
⑶ c语言的推箱子程序,解释一下
共用体的内存是共享的,也就是说chKeyBit数组与iKeyInfo占用同一段内存
指定了iKeyInfo,实际上chKeyBit数组的元素也有值了
还需要注意的是对于一个类型的值,访问其内存时是先从高位地址到低位地址,比如,long型四个字节,若它读出的值是0x12345678那么它的地址空间对应是
12高位地址
34
56
78低位地址
而数组是顺序分配的,下标大的地址高,所以才有通过*(数组名+i)访问第i+1个元素。
对了TC或WinTC编译器里
unsigned int是两个字节的
⑷ C语言怎么做推箱子的移动
#include"stdio.h"
#include<conio.h>
#include"Windows.h"
voidgotoxy(intx,inty){
system("cls");
COORDcr;
cr.X=x;
cr.Y=y;
HANDLEhandle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(handle,cr);
printf("*");
}
intmain(){
staticintx=10,y=10;
gotoxy(x,y);
charc;
while(1){
c=getch();
switch(c){
case'w':
case'W':
y--;
gotoxy(x,y);
break;
case'a':
case'A':
x--;
gotoxy(x,y);
break;
case's':
case'S':
y++;
gotoxy(x,y);
break;
case'd':
case'D':
x++;
gotoxy(x,y);
break;
default:
break;
}
}
}
我只是给你举个简单的例子,你应该能明白这个程序了
⑸ c语言推箱子
//空:0墙:1箱子:3巢:4箱子与巢重合:5
[MAPCOUNT]
map_count=8
[MAP1]
w=8
h=8
nest_count=4
l1=00011100
l2=00013100
l3=11110100
l4=13202111
l5=11142031
l6=00121111
l7=00131000
l8=00111000
[MAP2]
w=9
h=9
nest_count=3
l1=111110000
l2=140010000
l3=102210111
l4=102010131
l5=111011131
l6=011000031
l7=010001001
l8=010001111
l9=011111000
[MAP3]
w=10
h=7
nest_count=4
l1=0111111100
l2=0100000111
l3=1121110001
l4=1040200201
l5=1033102011
l6=1133100010
l7=0111111110
[MAP4]
w=6
h=8
nest_count=5
l1=011110
l2=110010
l3=142010
l4=112011
l5=110201
l6=132001
l7=133531
l8=111111
//以上为地图数据文件,保存为boxdata.dat文件
//空:0墙:1箱子:3巢:4箱子与巢重合:5
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<windows.h>
#include<string.h>
typedefstruct
{
intx;
inty;
}PT;
int**s;
PTman;
PT*nest=NULL;
PTprev;
intnest_count=0;
intmap_count=0;
intgate=1;
intw,h;
charwork_dir[100]={'