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

📄 mmigame.c

📁 GSM手机设计软件代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*******************************************************************************

					CONDAT (UK)

********************************************************************************                                                                              

 This software product is the property of Condat (UK) Ltd and may not be
 disclosed to any third party without the express permission of the owner.                                 
                                                                              
********************************************************************************

 $Project name:	Basic MMI                                                      
 $Project code:	BMI (6349)                                                           
 $Module:		Game
 $File:		    Mmigame.c
 $Revision:		1.0                                                       
                                                                              
 $Author:		Condat(UK)                                                         
 $Date:		    03/07/01                                                      
                                                                               
********************************************************************************
                                                                              
 Description

    This provides the main game (four in a row) functionality

  
********************************************************************************/


/*******************************************************************************
                                                                              
                                Include files
                                                                              
*******************************************************************************/

#define ENTITY_MFW

/* includes */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#if defined (NEW_FRAME)

#include "typedefs.h"
#include "vsi.h"
#include "pei.h"
#include "custom.h"
#include "gsm.h"

#else

#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"

#endif
#include "mfw_sys.h"

#include "p_sim.h"
#include "cus_aci.h"

#include "mfw_mfw.h"
#include "mfw_win.h"
#include "mfw_kbd.h"
/* SPR#1428 - SH - New Editor changes */
#ifndef NEW_EDITOR
#include "mfw_edt.h"
#endif
#include "mfw_lng.h"
#include "mfw_tim.h"
#include "mfw_icn.h"
#include "mfw_mnu.h"
#include "mfw_phb.h"
#include "mfw_cm.h"
#include "mfw_sim.h"
#include "mfw_nm.h"
#include "mfw_sat.h"
#include "mfw_ss.h" /*for convert*/
#include "mfw_phb.h"
#include "ksd.h"
#include "psa.h"
#include "mfw_sms.h"
#include "mfw_cphs.h"
#include "mfw_sat.h"
#include "Mfw_band.h"
#include "Mfw_ffs.h"
#include "mmigame.h"

#include "dspl.h"

#include "MmiMmi.h"
#include "MmiDialogs.h"
#include "MmiLists.h"
#include "MmiBand.h"
#include "MmiCPHS.h"
/* SPR#1428 - SH - New Editor changes */
#ifdef NEW_EDITOR
#include "ATBCommon.h"
#include "ATBDisplay.h"
#include "ATBEditor.h"
#include "AUIEditor.h"
#else
#include "MmiEditor.h"
#endif
#include"mmibookshared.h"




#include "font_bitmaps.h"
#include "mmicolours.h"
#include "mmiresources.h"

#include "mmigame.h"
//GW 14/09/01 Disable game when not required.
#ifdef MMIGAME
void dspl_show_bitmap(int x,int y,t_font_bitmap* current_bitmap,U32 attr );	
/*******************************************************************************
                                                                              
                                internal data
                                                                              
*******************************************************************************/

#define FOUR_IN_A_ROW_INIT 121
#define MAX_X_BOARD 11
#define MAX_Y_BOARD 8
/*
*  The information related to every window must be encapsulated in such an structure
*/

typedef struct
{
    T_MMI_CONTROL   mmi_control;		// common control parameter
	T_MFW_HND win;
	T_MFW_HND kbd;
	T_MFW_HND	menu;
	T_MFW_HND 	parent_win;	
	T_MFW_HND info_win;
	char board_array[MAX_Y_BOARD][MAX_X_BOARD];	//the virtual board
} T_four_in_a_row;

typedef struct
{
    /* administrative data */

    T_MMI_CONTROL     mmi_control;
    T_MFW_HND         win;
    T_MFW_HND         parent_win;
/* SPR#1428 - SH - New editor data */
#ifdef NEW_EDITOR
	T_AUI_EDITOR_DATA editor_data;
#else /* NEW_EDITOR */
    T_EDITOR_DATA   editor_data;
#endif /* NEW_EDITOR */

    /* internal data */
    char        buffer[80];
    UBYTE       status;

} tShowInfo;


/*
*  These are common functions xxx_create and xxx_destroy
*/
T_MFW_HND four_in_a_row_create(MfwHnd parent);
void four_in_a_row_destroy (T_MFW_HND);


/*
*  This dialog function (the same name as the window)
* is used to handle the comunication between different windows. The global macro SEND_EVENT can be used with parameter win
* and the corresponding events to send from one mmi dialog to another.
*/
void four_in_a_row (T_MFW_HND win, USHORT event, SHORT value, void * parameter);


/*
*  These are common optional functions handler
*/
int four_in_a_row_kbd_cb (MfwEvt e, MfwKbd *k);
int four_in_a_row_win_cb (MfwEvt e, MfwWin *w);

int Game_Result;


/*
*  This an optional function, used often to call, create and init a new dialog, with different parameters depending
* on the context
*/
T_MFW_HND four_in_a_row_start (T_MFW_HND win_parent,char *character);
int four_in_a_row_aktivate(MfwMnu* m, MfwMnuItem* i);

int check_column(T_four_in_a_row *data, int where_from);
void drop_stone(T_four_in_a_row *data);

int mobile_thinking(T_four_in_a_row *data);
int check_line(T_four_in_a_row *data, int x_value, int drop_position, int dx, int dy, BOOL where_from);
void check_for_winner(T_four_in_a_row *data, int check_out_position);
int random_scoring();

T_MFW_HND Game_Info(T_MFW_HND parent_window);
static T_MFW_HND ShowGame_Information(MfwHnd parent_window);
static void ShowGame_DialogCB(T_MFW_HND win, USHORT e,  SHORT identifier, void *parameter);
void ShowGameInfoEditor(T_MFW_HND win);
static void ShowInfoCB( T_MFW_HND win, USHORT Identifier,UBYTE reason);
void showGameInfo_destroy(MfwHnd own_window);

const char * info = "Welcome to Connect 4!";
const char * playAgain = "Play Again?";


//internal datas

int column;				//this is the current position of white player cursor
int x_runer;	//goes through the horizontal lines
int y_runer;	//goes through the vertical lines
char winner;	//describes the winner 0->nobody 'B'->black(mobile) 'W'->white(human player)
int column_black;	//this is the current position of black player cursor
int request_stone;	//helps to decide between black or white (for strategical things)

static  T_MFW_HND       info_window=0;

#ifndef BMP_FORMAT_BW_UNPACKED
#define BMP_FORMAT_BW_UNPACKED 1
#endif


t_font_bitmap  plWin1		={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)player_win1};
t_font_bitmap  plWin2		={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)player_win2};
t_font_bitmap  plLost1		={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)player_lost1};
t_font_bitmap  plLost2		={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)player_lost2};
t_font_bitmap  draw1		={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)board_full1};
t_font_bitmap  draw2		={ 0, BMP_FORMAT_BW_UNPACKED, 21, 24, 0, (char*)board_full2};
t_font_bitmap  gameName1	={ 0, BMP_FORMAT_BW_UNPACKED, 18, 24, 0, (char*)game_name1};
t_font_bitmap  gameName2	={ 0, BMP_FORMAT_BW_UNPACKED, 24, 24, 0, (char*)game_name2};

#ifdef COLOURDISPLAY
char colBmp[256*4];
t_font_bitmap  allCol  ={ 0, BMP_FORMAT_256_COLOUR, 32, 32, 0, colBmp };
t_font_bitmap  stone_colour   ={ 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)black_stone_bw};
t_font_bitmap  gameCursor = { 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)game_cursor};
#else
#ifdef LSCREEN
t_font_bitmap  blackStone_bw ={ 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)black_stone_bw};
t_font_bitmap  whiteStone_bw ={ 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)white_stone_bw};
t_font_bitmap  gameCursor = { 0, BMP_FORMAT_BW_UNPACKED, 8, 8, 0, (char*)game_cursor};
#else
t_font_bitmap  blackStone_bw ={ 0, BMP_FORMAT_BW_UNPACKED, 4, 4, 0, (char*)black_stone_bw};
t_font_bitmap  whiteStone_bw ={ 0, BMP_FORMAT_BW_UNPACKED, 4, 4, 0, (char*)white_stone_bw};
t_font_bitmap  gameCursor = { 0, BMP_FORMAT_BW_UNPACKED, 6, 6, 0, (char*)game_cursor};
#endif
#endif

t_font_bitmap *blackStone, *whiteStone;

/*******************************************************************************

 $Function:    	four_in_a_row_create

 $Description:	 
 
 $Returns:		

 $Arguments:	
 				
*******************************************************************************/


T_MFW_HND four_in_a_row_create (T_MFW_HND parent_window)
{

    T_MFW_WIN     * win;
    
    /*
     * This window is dynamic, for that reason the associated data are allocated in the mfw heap
     */
	T_four_in_a_row *  data = (T_four_in_a_row *)ALLOC_MEMORY (sizeof (T_four_in_a_row));

	TRACE_FUNCTION ("four_in_a_row_create()");

    /*
     * Create window handler
     */

    data->win = win_create (parent_window, 0, E_WIN_VISIBLE, (T_MFW_CB)four_in_a_row_win_cb);

    if (data->win EQ 0)
      return 0;

	 /*
     * These assignments are necessary to attach the data to the window, and to handle the mmi event communication.
     */

	data->mmi_control.dialog    = (T_DIALOG_FUNC)four_in_a_row;
    data->mmi_control.data      = data;
	data->parent_win           = parent_window;
    win                         = ((T_MFW_HDR *)data->win)->data;
    win->user                   = (void *) data;

    /*
    * Create any other handler
    */

    data->kbd      = kbd_create (data->win,KEY_ALL,(T_MFW_CB)four_in_a_row_kbd_cb);

	column=0;	//set start value for game cursor
	winner ='0';			//game starts, so set winner to nobody

	/*clear the board*/
	for (y_runer=0;y_runer<MAX_Y_BOARD;y_runer++){
		for(x_runer=0;x_runer<MAX_X_BOARD;x_runer++){
			data->board_array[y_runer][x_runer] ='0';
		}
	}
	winShow(data->win);
  
  return data->win;
}

/*******************************************************************************

 $Function:    	four_in_a_rowr_destroy

 $Description:	 
 
 $Returns:		

 $Arguments:	
 				
*******************************************************************************/

void four_in_a_row_destroy (T_MFW_HND own_window)
{
  T_MFW_WIN     * win;
  T_four_in_a_row       * data;

	TRACE_EVENT("four_in_a_row_destroy");

  if (own_window)
  {
    win  = ((T_MFW_HDR *)own_window)->data;
    data = (T_four_in_a_row *)win->user;

    if (data)
    {
      /*
       * Exit Keyboard Handler
       */
      /*
       * Delete WIN Handler
       */
      win_delete (data->win);
    }

   /*
   *  In this case the data attached to window must be also deleted.
   */
	FREE_MEMORY ((void *)data, sizeof (T_four_in_a_row));

   column=0;			//set the current column back to 0

  }
}

/*******************************************************************************

 $Function:    	four_in_a_row_start

 $Description:	 This function just creates and inits the new dialog
 
 $Returns:		

 $Arguments:	
 				
*******************************************************************************/
T_MFW_HND four_in_a_row_start (T_MFW_HND win_parent,char *character)
{
  T_MFW_HND win; 
 /*
 MmiTetrisStart();
 return;
 */
  win = four_in_a_row_create (win_parent);
  TRACE_EVENT("four_in_a_row_start");

  if (win NEQ NULL)
  {
		SEND_EVENT(win,FOUR_IN_A_ROW_INIT,0,character);
  }
  return win;

}

/*******************************************************************************

 $Function:    	four_in_a_row

 $Description:	 
 
 $Returns:		

 $Arguments:	
 				
*******************************************************************************/



void four_in_a_row (T_MFW_HND win, USHORT event, SHORT value, void * parameter)
{
    T_MFW_WIN      * win_data = ((T_MFW_HDR *) win)->data;
    T_four_in_a_row       * data = (T_four_in_a_row *)win_data->user;

    TRACE_FUNCTION ("four_in_a_row()");

   /*
   *  In this case the communication is very simple (only one intern event)
   */


    switch (event)
	{
		case FOUR_IN_A_ROW_INIT:
			softKeys_displayId(TxtSearchName,TxtNull,0,COLOUR_IDLE);			
			winShow(data->win);
		break;

	    default:
		return;
	}

}

/*******************************************************************************

 $Function:    	four_in_a_row_win_cb

 $Description:	win calback function of four in a row
 
 $Returns:		

 $Arguments:	
 				
*******************************************************************************/


int four_in_a_row_win_cb (MfwEvt e, MfwWin *w)
{
	T_DISPLAY_DATA display_info;
	T_four_in_a_row * data = (T_four_in_a_row *)w->user;
	int xOfs,yOfs, xScale, yScale;
	int manOfsX,manOfsY;
	int xPos,yPos;
	int y_axis;																	//goes through the vertical lines
	int x_axis;																	//goes through the horizontal lines
	int x,y,i,b;
	int displayPosX, temp;

    TRACE_FUNCTION ("four_in_a_row_win_cb()");
	
	switch (e)
    {
        case MfwWinVisible:
#ifdef COLOURDISPLAY
				whiteStone = &stone_colour;
				blackStone = &stone_colour;
				
#else
				whiteStone = &blackStone_bw;
				blackStone = &whiteStone_bw;
				
#endif

⌨️ 快捷键说明

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