📄 games_fallball_path.c
字号:
#ifdef __cplusplus
extern "C" {
#endif
/*==================================================================================================
MODULE NAME : GAMES_Fallball_path.c
GENERAL DESCRIPTION
Input Short Message content.
SEF Confidential Proprietary
(c) Copyright 2002 by SEF Corp. All Rights Reserved.
====================================================================================================
Revision History
Modification Tracking
Date Author Number Description of changes
---------- -------------- --------- -----------------------------------------------------------------------------------
10/28/2003 lixingbo crxxxxx Initail creation
04/24/2004 lixingbo p005089 Modify some bugs.
04/27/2004 lixingbo p005153 Modify a bug.
Self-documenting Code
Describe/explain low-level design of this module and/or group of funtions and/or specific
funtion that are hard to understand by reading code and thus requires detail description.
Free format !
====================================================================================================
INCLUDE FILES
==================================================================================================*/
#include "APP_include.h"
#include "TP_Operator.h"
#include "MENU_main.h"
#include "MENU_item.h"
#include "GAMES_main.h"
#include "GAMES_cargador_path.h"
#ifdef GAMES_FALLBALL
#include <stdlib.h>
#include "uhapi.h"
#include "SP_volume.h"
#include "SP_audio.h"
#include "GAMES_fallball.h"
#include "GAMES_cargador.h"
#include "product.h"
/*==================================================================================================
LOCAL MACROS FallballPath
==================================================================================================*/
#define FLOOR 0
#define SQUARELENGTH 16
/*==================================================================================================
GLOBAL VARIABLES
==================================================================================================*/
/*OP_UINT8 cur_box[MAX_LINE][MAX_COLUMN]; */
PathElem FallballPath[MAX_LINE*MAX_COLUMN]={0};
OP_INT8 FallballCurPath = MAX_LINE*MAX_COLUMN;
/*==================================================================================================
LOCAL VARIABLES
==================================================================================================*/
static OP_BOOLEAN mark[MAX_LINE][MAX_COLUMN]={OP_FALSE};
/*==================================================================================================
GLOBAL FUNCTION PROTOTYPES
==================================================================================================*/
OP_BOOLEAN SearchBallRoute(PosType start,PosType end);
/*==================================================================================================
LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
static OP_BOOLEAN FootMark(PosType pos);
static OP_INT8 GetChoice(PosType start,PosType end);
static OP_INT8 GetDistance(PosType start,PosType end);
static OP_BOOLEAN Pass(PosType pos);
static OP_BOOLEAN Add(PathElem *Path,OP_INT8 CurPath, PathElem *Elem);
static OP_BOOLEAN Del(PathElem *Path,OP_INT8 CurPath,PathElem *Elem);
static void OptimizeRoute();
static OP_BOOLEAN JudgeLinePath(PosType start, PosType end);
/*==================================================================================================
LOCAL FUNCTIONS
==================================================================================================*/
/*==================================================================================================
FUNCTION: FootMark
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
OP_BOOLEAN FootMark(PosType pos)
{
if(mark[pos.y][pos.x] == OP_FALSE)
{
mark[pos.y][pos.x] = OP_TRUE;
}
/*else
{
mark[pos.y][pos.x] = OP_FALSE;
}*/
return OP_SUCCESS;
}
/*==================================================================================================
FUNCTION: NextPos
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static OP_BOOLEAN NextPos(PosType CurPos,OP_INT8 di,OP_INT8 choice,PosType *NextPosi)
{
op_memcpy(NextPosi,&CurPos,sizeof(PosType));
switch(choice)
{
case 1:
switch(di)
{
case 1:
NextPosi->x++;
break;
case 2:
NextPosi->y++;
break;
case 3:
NextPosi->x--;
break;
case 4:
NextPosi->y--;
break;
default:
break;
}
break;
case 2:
switch(di)
{
case 1:
NextPosi->y++;
break;
case 2:
NextPosi->x++;
break;
case 3:
NextPosi->y--;
break;
case 4:
NextPosi->x--;
break;
default:
break;
}
break;
case 3:
switch(di)
{
case 1:
NextPosi->x++;
break;
case 2:
NextPosi->y--;
break;
case 3:
NextPosi->x--;
break;
case 4:
NextPosi->y++;
break;
default:
break;
}
break;
case 4:
switch(di)
{
case 1:
NextPosi->y--;
break;
case 2:
NextPosi->x++;
break;
case 3:
NextPosi->y++;
break;
case 4:
NextPosi->x--;
break;
default:
break;
}
break;
case 5:
switch(di)
{
case 1:
NextPosi->x--;
break;
case 2:
NextPosi->y++;
break;
case 3:
NextPosi->x++;
break;
case 4:
NextPosi->y--;
break;
default:
break;
}
break;
case 6:
switch(di)
{
case 1:
NextPosi->y++;
break;
case 2:
NextPosi->x--;
break;
case 3:
NextPosi->y--;
break;
case 4:
NextPosi->x++;
break;
default:
break;
}
break;
case 7:
switch(di)
{
case 1:
NextPosi->x--;
break;
case 2:
NextPosi->y--;
break;
case 3:
NextPosi->x++;
break;
case 4:
NextPosi->y++;
break;
default:
break;
}
break;
case 8:
switch(di)
{
case 1:
NextPosi->y--;
break;
case 2:
NextPosi->x--;
break;
case 3:
NextPosi->y++;
break;
case 4:
NextPosi->x++;
break;
default:
break;
}
break;
default:
break;
}
return OP_SUCCESS;
}
/*==================================================================================================
FUNCTION: GetChoice
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
OP_INT8 GetChoice(PosType start,PosType end)
{
OP_INT8 choice,distx,disty;
distx = end.x - start.x;
disty = end.y - start.y;
if(end.x - start.x > 0)
{
if(end.y - start.y > 0)
{
if(distx > disty)
{
choice = 1;
}
else
{
choice = 2;
}
}
else
{
if(distx > -disty)
{
choice = 3;
}
else
{
choice = 4;
}
}
}
else
{
if(end.y - start.y > 0)
{
if(-distx > disty)
{
choice = 5;
}
else
{
choice = 6;
}
}
else
{
if(-distx > -disty)
{
choice = 7;
}
else
{
choice = 8;
}
}
}
return choice;
}
/*==================================================================================================
FUNCTION: GetDistance
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static OP_INT8 GetDistance(PosType start,PosType end)
{
OP_INT8 distance = 0;
distance += end.x > start.x ? (end.x - start.x) : (start.x - end.x);
distance += end.y > start.y ? (end.y - start.y) : (start.y - end.y);
return distance;
}
/*==================================================================================================
FUNCTION: Pass
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
OP_BOOLEAN Pass(PosType pos)
{
OP_INT16 *box = OP_NULL;
box = GetBox();
if(pos.x < 0 || pos.x >= MAX_COLUMN || pos.y < 0 || pos.y >= MAX_LINE )
{
return OP_FAIL;
}
if(mark[pos.y][pos.x] == OP_TRUE)
{
return OP_FAIL;
}
if( *(box+pos.y*MAX_COLUMN+pos.x) == FLOOR )
{
return OP_SUCCESS;
}
return OP_FAIL;
}
/*==================================================================================================
FUNCTION: IsFloor
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -