⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pushboxs.c

📁 一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上
💻 C
📖 第 1 页 / 共 3 页
字号:


/*************************************************************************
 *
 *  Copyright (C) Asic Center. 2001
 *  All Rights Reserved
 *
 *  Filename : testcode.c
 *  Function : Some tasks for testing system prototype, such as SHELL, TIMER
 *			   TASK, IDLE TASK, TASK A,B,C, and so on.
 *  Revision :
 *          2001/10/9  Pessia      Create this file
 *
 ************************************************************************/
#include <stdio.h>
#include <string.h> 
#include <math.h>


#include <asixwin.h>
#include <asixapp.h>

#include <asixwin\asix_mn.h>
#include <asixwin\select.h>
#include <asixwin\asix_sb.h>
#include <asixwin\asix_lb.h>
#include <asixwin\disp.h>
#include <asixwin\asix_ed.h>
#include <asixwin\asix_key.h>

#include <resource\bitmap.h>
#include <resource\picture.h>





#define GPC_EXOR_STYLE GPC_XOR_STYLE
#define isusefun 1
/********************************************************************
*   Function temp_task()  
*	param in:	void		
*	param out: 	void	
*	description: 应用任务模板	
********************************************************************/

//define the basic unit of the game
#define BRICK    	0
#define BOX   		1
#define BOXPOSITION 	2
#define MAN 		3
#define SPACE    	4
#define MANINPOSITION   5
#define BOXINPOSITION	6
//define the status when moving-box
#define NOMOVE  	0
#define MANLEFTBOXRIGHT 1
#define MANRIGHTBOXLEFT 2
#define MANUPBOXDOWN	3
#define MANDOWNBOXUP	4
//these two variables are only used in man move animation
#define MOVEPATH        9
#define CANNOTMOVE      8



 
struct  room
        {
         U8      Xnumber; //the number of units in x direction   X  ____ len
         U8      Ynumber; //the number of units in y direction          |   //the length and width of the game room
         U8      manx;    //                                            |Y wid
         U8      many;//the initial position of the man
        }gameroom[]={
                    {8,8,3,4},
                    {8,8,5,2},
                    {10,10,1,2},
                    {8,8,5,1},
                    {8,8,6,3},
                    {8,8,2,1},
                    {8,8,4,6},
                    {8,8,3,3},
                    {8,8,3,6},
                    {8,8,2,6},
                    
                    {8,8,3,6},
                    {8,8,6,2},
                    {8,8,6,5},
                    {8,8,5,2},
                    {8,8,6,5},
                    {8,8,1,5},
                    {8,8,4,3},
                    {8,8,5,4},
                    {8,8,6,2},
                    {8,8,6,2},
                   
                    {10,10,1,2},
                    {8,10,3,1}, 
                    {10,8,4,1},
                    {10,10,2,7},
                    {10,8,4,5}, 
                    {8,8,5,3},
                    {8,8,4,2},
                    {8,8,4,6},
                    {8,8,4,4}, 
                    {10,8,7,3}
                  
                    
                   };
const   U8      maxstage=30;
//the map data.when game beginning,the data will be copied to the 
//space dynamiclly created acording to the size given by gameroom.                   
const   U8       map[]= 
{
  
  0,0,0,0,0,0,0,0,
  0,0,0,0,2,0,0,0,
  0,0,0,0,4,0,0,0,
  0,2,1,4,1,0,0,0,
  0,0,0,3,1,4,2,0,
  0,0,0,1,0,0,0,0,
  0,0,0,2,0,0,0,0,
  0,0,0,0,0,0,0,0,
  
  0,0,0,0,0,0,0,0,
  0,0,4,4,4,0,0,0,
  0,0,0,4,1,3,0,0,
  0,0,0,4,1,0,0,0,
  0,0,4,1,4,0,0,0,
  0,0,4,4,1,2,0,0,
  0,0,2,4,2,2,0,0,
  0,0,0,0,0,0,0,0,
  
  
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,3,4,0,4,4,0,0,0,0,
0,4,4,0,4,4,4,0,0,0,
0,4,1,4,1,4,1,0,0,0,
0,4,4,0,0,1,4,0,0,0,
0,0,4,0,4,1,4,0,0,0,
0,0,4,4,2,2,2,2,2,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
  
  
  0,0,0,0,0,0,0,0,
  0,0,0,0,4,3,0,0,
  0,0,4,4,1,4,0,0,
  0,0,4,0,4,0,0,0,
  0,4,4,0,4,0,2,0,
  0,4,0,4,4,1,2,0,
  0,4,1,4,4,4,2,0,
  0,0,0,0,0,0,0,0,
  
  0,0,0,0,0,0,0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gameroomX=0;
const   U8		gameroomY=30;
//const   U8      gameroomLen=160;
//const   U8      gameroomWid=160;
const   U8      gameroomLen=LCD_WIDTH;
const   U8      gameroomWid=LCD_WIDTH;
//pos[] is used to record the man move track
struct position {
       char  x;
       char  y;
       } pos[100];
const U8  maxstep=100;
//the pointer to the map selected which points to a dynamicly allocated space
U8      *mapPtr;

//global variable for the now playing stage
U8      gStageNow;
U8      where=0;//where is used in man move animation
//for animate use
P_U8 	animationPtr;
//the undo chain
struct   chain
      {
	struct chain *next;
	char who;
	char oldx;
	char oldy;
	char newx;
	char newy;
      };
#define LEN sizeof(struct chain)   //the size of the struct
struct  chain *gamechain=NULL;     //the pointer of the undo chain
U8	gcandelete;                //if undo can be done or not
#define CANDELETE	1
#define CANNOTDELETE	0
#define NOTEND		0
#define SUCCESS		1
const   char  gamehelp[]=
{"\n[游戏玩法]:首先将小人移动到你想移动箱子旁的空位上,然后点击箱子,如果\
  沿着向前的方向上没有障碍物,那么人和箱子将移动到新的位置上\
  \n[胜利条件]:将所有的箱子移动到箱位上"
};

extern void PutBoxes( void );

TASKDESCRIPTION PushBoxesTskDesp = 
{"推推",	ASIX_APP,	1,	zi_tuitui,		4096,	1,	LCD_WIDTH,	LCD_HEIGHT,	PutBoxes,	APP_PRI};
	
U8   SelectStageNo(U8 No)//select the stage No. 
{
	return 0;
}
	
U8  *Stageinit()//return the matrix pointer of room that can be handled through all the programme
{
	U16     size;
	U8      i,j;	
	P_U8    ptr,gameSpace;
	U8      Width,Length;
	U16     base=0;
	
	for(i=0;i<gStageNow;i++)
	   base=base+gameroom[i].Xnumber*gameroom[i].Ynumber;//count the base number of the game matrix
	Width=gameroom[gStageNow].Ynumber;
	Length=gameroom[gStageNow].Xnumber;
	size=Width*Length;
	//the game matrix space is applied here,it must be freed when startting another
	//game or exit
	if ((ptr=Lmalloc(size))==NULL)  return 0;
	gameSpace=ptr;
	for(i=0;i<Width;i++)
	    for(j=0;j<Length;j++)
	        *ptr++=map[base+i*Length+j];   
	
	return gameSpace;        
}

U8 GetunitWidth()//get the width of the unit
{
	return gameroomWid/gameroom[gStageNow].Ynumber;
}	

U8 GetunitLength()//get the length of the unit
{
   	return gameroomLen/gameroom[gStageNow].Xnumber;
}

//get the unit's position in the array by returning the xPos yPos
void Getpos(U8 xScr,U8 yScr,P_U8 xPos,P_U8 yPos)
{   
	*xPos=(xScr-gameroomX)/GetunitLength();
	*yPos=(yScr-gameroomY)/GetunitWidth();
}
//get who is at the given place
U8 GetWho(U8 xPos,U8 yPos)
{
	return *(mapPtr+xPos+yPos*gameroom[gStageNow].Xnumber);
}	
//entry:the relative coordinate in the array
//exit: the absolute coordinate
void GetXY(U8 XPos,U8 YPos,P_U8 xScr,P_U8 yScr)
{
	*xScr=gameroomX+XPos*GetunitLength();
	*yScr=gameroomY+YPos*GetunitWidth();
}
void PositiontoXY(P_U8 xPos,P_U8 yPos)
{
	U8      unitLen,unitWid;
	U8	Xbase,Ybase;
	
	Xbase=gameroomX;
	Ybase=gameroomY;
	unitLen=GetunitLength();
	unitWid=GetunitWidth();
	*xPos=Xbase+*xPos*unitLen;
	*yPos=Ybase+*yPos*unitWid;
}		
void DrawBrick(U8 unitx,U8 unity)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -