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

📄 games_huarong.c

📁 几个嵌入式手机平台小游戏c源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
 #ifdef __cplusplus
extern "C" {
#endif

/*==================================================================================================

    MODULE NAME : module-filename.c

    GENERAL DESCRIPTION
        General description of this grouping of functions.

    TECHFAITH Telecom Confidential Proprietary
    (c) Copyright 2002 by TECHFAITH Telecom Corp. All Rights Reserved.
====================================================================================================

    Revision History
   
    Modification                  Tracking
    Date         Author           Number      Description of changes
    ----------   --------------   ---------   -----------------------------------------------------------------------------------
    MM/DD/YYYY   name of author   crxxxxx     Brief description of changes made

    03/03/2002   Steven Lai      PP00132      Change some popup timer from absolute number to default value 
    03/01/2003   Steven Lai      PC00009      Restructure Games app
    03/13/2003   Steven Lai      PP00159      Removed some useless code
    04/25/2003   Steven Lai      P000166      Change the default focused item of the highscore list, to 
                                              let there is no item be highlighted

    05/27/2003   Chenyu          P000436      Fix sublcd & game display
    03-06-3      Chenyu          P00502       Fix game tetris

    07/02/2003   Steven Lai       C000662     Add a sound-switch for Games App
                                              replace all the App_change_state() with Games_change_state()
                                              fixed some bugs
    07/11/2003   Steven Lai       P000887     When user press any key, stop the audio
    03-09-10       lixingbo           C001812     Add touch function
    03-11-07       lixingbo           P001982     Modify the huarong game's movement rule.  
    02/24/2004   lixingbo           p002467    Modify the game for dolphin.
    06/04/2004    caoyanqing        p005953    modify two bugs for odin.
    06/18/2004   Lixingbo           p006238      Modify some display bugs about huarongdao.
    09/08/2004   Simba Lee          p008219      Modify a ds 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 "MENU_main.h"

#include "GAMES_main.h"

#ifdef GAMES_HUARONG

#include <stdlib.h>

#include "uhapi.h"
#include "Ds_lcd.h"

#include "SP_volume.h"
#include "SP_audio.h"

#include "GAMES_highscore.h"
#include "GAMES_huarong.h"
#include "product.h"
/*==================================================================================================
    LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
void APP_Huarong_entry(void);
void App_Huarong_exit(void);
void App_Huarong_handler ( OPUS_EVENT_ENUM_TYPE   event, 
                                 void                   *pMess, 
                                 OP_BOOLEAN             *handle );
static OP_BOOLEAN Huarong_Penmove();

static void APP_Huarong_Init(void);
static void initRoadblocks(void);
static void on_KeyPress(void  *pMess);
static void movePiece(DIRECTION direct);
static void moveCursor(DIRECTION direct);
static void Paint(void);
static void DrawSquare(OP_INT8 index);
static void HighlightSquare(OP_INT8 index);
static void DrawBoard(void);
static void HuarongRun(void );
static OP_BOOLEAN hasPass(void );
static void ShowGameOver(OP_UINT16 wScore);
static OP_BOOLEAN JudgeNextPiece(DIRECTION direct );
static OP_INT8 JudgeStep(DIRECTION direct);
static OP_BOOLEAN MoveIfCan();
static void DrawCursor(DIRECTION direct);
static void ChangeState();

/*==================================================================================================
    LOCAL CONSTANTS
==================================================================================================*/
#define    rowNum            5
#define    colNum            4

#ifdef PACIFIC_VERSION
#define    RECTWIDTH        44
#define    RECTHEIGHT       35
#else
#define    SQUAREWIDTH        24
#endif

#define HUARONG_BG_COLOR    COLOR_BLACK  

#define BLANK_COLOR         COLOR_BLUE   //0xFDE4

#ifdef PACIFIC_VERSION
#define FRAMEWIDTH                 1 /* 4 is the width of the board frame */
#define FRAME_TOPLEFT_COLOR        COLOR_LIGHT_GRAY
#define FRAME_RIGHTBOTTOM_COLOR    COLOR_DARK_GRAY
#define FRAME_FILL_COLOR           0xFC08
#else
#define FRAMEWIDTH                9 /* 9 is the width of the board frame */
#define FRAME_TOPLEFT_COLOR       COLOR_LIGHT_GRAY
#define FRAME_RIGHTBOTTOM_COLOR   COLOR_DARK_GRAY
#define FRAME_FILL_COLOR          0xFC08
#endif

#define MAX_STRING_LENGTH    100
#define FIRST_BLANK                  10    /*The blank place.*/
#define SECOND_BLANK               11   /*The blank place.*/
#define Caocao  BMP_HUARONG_CAOCAO
#define Guanyu  BMP_HUARONG_GUANYU
#define Zhaoyun  BMP_HUARONG_ZHAOYUN
#define Zhangfei  BMP_HUARONG_ZHANGFEI
#define Huangzhong  BMP_HUARONG_HUANGZHONG
#define Machao  BMP_HUARONG_MACHAO
#define Soldier  BMP_HUARONG_SOLDIER
// TODO: remove the data of BMP_HUARONG_BLANK
#define Blank  BMP_HUARONG_BLANK

/*==================================================================================================
    LOCAL TYPEDEFS - Structure, Union, Enumerations...etc
==================================================================================================*/

/*
 * description of this structure, if needed. - Remember self documenting code
 */
typedef enum
{
    MOVECURSOR,
    MOVEPIECE
}STATUS; 

/*==================================================================================================
    LOCAL MACROS
==================================================================================================*/
/*
 * description of this macro, if needed. - Remember self documenting code
 */

/*==================================================================================================
    LOCAL VARIABLES
==================================================================================================*/

static OP_INT16 xoffset,yoffset;

static STATUS state;    /* move piece or just move cursor */
static OP_UINT8 cursorX, cursorY;
static OP_UINT16 step;
static OP_UINT8 posx,posy;
static OP_BOOLEAN pieceClicked=OP_FALSE;
static OP_INT8 current_map=-1;

static OP_UINT8 text_str[MAX_STRING_LENGTH];   

static CHESSMAN pieces[12] =
{
    {Caocao, 2, 2, -1, -1, {0, 0, 0, 0}},      // 0
    {Guanyu, 2, 1, -1, -1, {0, 0, 0, 0}},         // 1
    {Zhaoyun, 1, 2, -1, -1, {0, 0, 0, 0}},        // 2
    {Huangzhong, 1, 2, -1, -1, {0, 0, 0, 0}},     // 3
    {Machao, 1, 2, -1, -1, {0, 0, 0, 0}},     // 4
    {Zhangfei, 1, 2, -1, -1, {0, 0, 0, 0}},    // 5
    {Soldier, 1, 1, -1, -1, {0, 0, 0, 0}},        // 6
    {Soldier, 1, 1, -1, -1, {0, 0, 0, 0}},        // 7
    {Soldier, 1, 1, -1, -1, {0, 0, 0, 0}},        // 8
    {Soldier, 1, 1, -1, -1, {0, 0, 0, 0}},        // 9
    {Blank, 1, 1, -1, -1,  {0, 0, 0, 0}},       // 10
    {Blank, 1, 1, -1, -1,  {0, 0, 0, 0}},       // 11
}; 

static OP_UINT8 map[rowNum][colNum];

static OP_UINT8 const map0[rowNum][colNum]=
{
    2, 0, 0, 3, 
    2, 0, 0, 3,  
    4, 1, 1, 5, 
    4, 7, 8, 5, 
    6, 10, 11, 9, 
};

static OP_UINT8 const map1[rowNum][colNum]=
{
    2, 0, 0, 3, 
    2, 0, 0, 3,  
    6, 1, 1, 9, 
    4, 7, 8, 5, 
    4, 10, 11, 5, 
};

static OP_UINT8 const map2[rowNum][colNum]=
{
    0, 0, 2, 3, 
    0, 0, 2, 3,  
    1, 1, 6, 7, 
    4, 5, 8, 9, 
    4, 5, 10, 11, 
};

static OP_UINT8 const map3[rowNum][colNum]=
{
    6, 0, 0, 8, 
    7, 0, 0, 9,  
    4, 1, 1, 5, 
    4, 2, 3, 5, 
    10, 2, 3, 11, 
};


static OP_UINT8 state1=0;  /* whether highlight current piece */
static OP_BOOLEAN blanksContiguous;    /* whether the 2 blanks are contiguous */
static OP_BOOLEAN gamePause;
static OP_BOOLEAN inGame;

static RM_SOUND_ID_T sound_list[]=
{
    RES_SOUND_0010,  /* huarong opening song */
    RES_SOUND_0013,  /* block is moved */
    RES_SOUND_0010,  /* game over */
};



/*==================================================================================================
    GLOBAL VARIABLES
==================================================================================================*/
extern APP_GAMES_STRUCTURE_NAME_T   gamesApp_data;
extern APP_SUBSTATE_STRUCTURE_NAME_T games_substate;



/*==================================================================================================
    LOCAL FUNCTIONS
==================================================================================================*/

/*==================================================================================================
    FUNCTION: APP_Huarong_entry

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
void APP_Huarong_entry(void)
{
    ds_set_screen_mode(SCREEN_GENERAL);/*_cathy_*/
    gamesApp_data.popupwin=OP_NULL;
    APP_Huarong_Init();
}

/*==================================================================================================
    FUNCTION: App_Huarong_exit

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
void App_Huarong_exit(void)
{
    close_old_popup();
    ds_set_softkeys_rm(PMPT_SKEY_EMPTY, PMPT_SKEY_EMPTY, PMPT_SKEY_EMPTY);   
    SP_Audio_stop();
}


/*==================================================================================================
    FUNCTION: app_Huarong_handler

    DESCRIPTION:
        Description of this specific function.

    ARGUMENTS PASSED:

    RETURN VALUE:

    IMPORTANT NOTES:
        
==================================================================================================*/
void    
App_Huarong_handler
( 
    OPUS_EVENT_ENUM_TYPE   event, 
    void                   *pMess, 
    OP_BOOLEAN             *handle 
)
{
    KEYEVENT_STRUCT *pKey;
    TP_PEN_EVENT_STRUCTURE_T  *pPen;
    TPO_OPERATION_PARAM_STRUCTURE_T *pOperation_param;
    
    *handle = OP_TRUE;

    switch (event)
    {
        case OPUS_FOCUS_CUST_PAINT :
            if ( (pMess != OP_NULL) && (*((OP_BOOLEAN *)pMess) == OP_TRUE))
            {
                if (ds_get_screen_mode() != SCREEN_GENERAL) /*_cathy_*/
                {
                    ds_set_screen_mode(SCREEN_GENERAL); /*_cathy_*/
                }
                clear_full_screen(HUARONG_BG_COLOR);
                DrawBoard();
                ds_set_softkeys_rm( PMPT_SKEY_RESTART,PMPT_SKEY_EMPTY, PMPT_SKEY_BACK);
                Paint();
                gamePause=OP_FALSE;
                TPO_SetCurrent_RPU(TPO_RUI_GAMES);
                if (state==MOVEPIECE)
                {
                    HuarongRun();
                }
            }
            break;

        case OPUS_TIMER_GAME_TIMING:
            if (!gamePause && state==MOVEPIECE && inGame)
            {
                HuarongRun();
            }
            break;

        case OPUS_FOCUS_KEYPAD :
            pKey = (KEYEVENT_STRUCT *)pMess;
            if(pKey->state == UHKEY_RELEASE) 
            {
                 break;
            }
            on_KeyPress(pMess);
            break;

        case OPUS_TIMER_POPUP_MSG:
            if (gamesApp_data.popupwin != OP_NULL)
            {
                 close_old_popup();
            }
            Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
            break;
            
        case OPUS_FOCUS_CUST_APP_PAUSE:
            gamePause=OP_TRUE;
            OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
            OPUS_Stop_Timer(OPUS_TIMER_GAME_PEN);
            if (gamesApp_data.popupwin!= OP_NULL)
            {
                close_old_popup();
                Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
            }
            break;
         case OPUS_TIMER_GAME_PEN:
              /*When the game pen timer arrives,let the picture move.*/
             if(posx == cursorX && posy == cursorY)
             {
                 ChangeState();
                 OPUS_Stop_Timer(OPUS_TIMER_GAME_PEN);
                 break;
             }
             Huarong_Penmove();
             break;
         case OPUS_FOCUS_PEN :
            /*Record the pen message and run the game pen timer.*/
            pPen = pMess;
            pieceClicked=OP_FALSE;
            if(pPen->state == TP_PEN_STATE_PENDN 
            && pPen->x-xoffset-FRAMEWIDTH>0 && pPen->x-xoffset-FRAMEWIDTH<xoffset+RECTWIDTH*colNum
            && pPen->y-yoffset-FRAMEWIDTH-LCD_ANNUN_HIGH>0 && pPen->y-yoffset-FRAMEWIDTH-LCD_ANNUN_HIGH<yoffset+RECTHEIGHT*rowNum)
            {
                Paint();
                OPUS_Stop_Timer(OPUS_TIMER_GAME_PEN);
                posx=(pPen->x-xoffset-FRAMEWIDTH)/RECTWIDTH;
  		        posy=(pPen->y-yoffset-FRAMEWIDTH-LCD_ANNUN_HIGH)/RECTHEIGHT;
                if( map[posy][posx]!=FIRST_BLANK 
                && map[posy][posx]!=SECOND_BLANK )
                {
                        pieceClicked = OP_TRUE;
                        if(map[posy][posx] == map[cursorY][cursorX])
                        {
                            MoveIfCan();
                            HighlightSquare(map[cursorY][cursorX]);
                            ds_refresh(); 
                            posx = cursorX;
                            posy = cursorY;
                            break;
                        }
                        else
                        {
                            DrawSquare(map[cursorY][cursorX]);
                            cursorX=pieces[map[posy][posx]].x;
                            cursorY=pieces[map[posy][posx]].y;
                            HighlightSquare(map[posy][posx]);
                            ChangeState();
                            ds_refresh();
                        }
                }
                else
                {
                    OPUS_Start_Timer(OPUS_TIMER_GAME_PEN, 1, 0,  ONE_SHOT);
                }
                }
                break;
        case OPUS_FOCUS_OPERATION:
           pOperation_param = (TPO_OPERATION_PARAM_STRUCTURE_T *)pMess;
           switch (pOperation_param->op)   
           {
           case OPERATION_ID_SK_CONFIRM:
               {
                   switch(pOperation_param->id)
                   {
                       case COMMAND_SOFTKEY_OK:
                          break;
                       case COMMAND_SOFTKEY_RIGHT:
                                 Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
                          break;
                       case COMMAND_SOFTKEY_LEFT:
                            if(gamesApp_data.popupwin != OP_NULL)
                            {
                                close_old_popup();
                            }
                            current_map = -1;  /* set current_map to -1, so the status will be reset in function APP_Huarong_Init() */
                            OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
                            APP_Huarong_Init();
                            break;
                       default:
                          break;
                   }
               }

⌨️ 快捷键说明

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