亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? puzzleapp.c

?? 在Palm上可以正常運(yùn)行的類似拼圖小游戲源代碼!
?? C
?? 第 1 頁 / 共 2 頁
字號(hào):
/******************************************************************************
 *
 * Copyright (c) 1995-2004 PalmSource, Inc. All rights reserved.
 *
 * File: PuzzleApp.c
 *
 * Description:
 *	  This is the main source module for the Puzzle(15) game.
 *
 *****************************************************************************/

#include <PalmOS.h>

#include "PuzzleRsc.h"

/***********************************************************************
 *
 *	Entry Points
 *
 ***********************************************************************/


/***********************************************************************
 *
 *	Internal Constants
 *
 ***********************************************************************/
#define puzzleAppCreator	'0910'

#define version20			0x02000000

#define boardX				18
#define boardY				26


#define pieceWidth			30
#define pieceHeight			30

#define pieceCornerDiameter	7

#define pieceFrameWidth		1
#define pieceSpace			pieceFrameWidth		// space between pieces
#define boardFrameMargin	pieceFrameWidth
#define boardFrameWidth		3

#define boardRows			4
#define boardColumns		4

#define numPositions		(boardRows * boardColumns)

#define minRow				0
#define minColumn			0
#define maxRow				(boardRows - 1)					// 0-based
#define maxColumn			(boardColumns - 1)				// 0-based

#define emptySquareID		0

// Number of moves the puzzle is shuffled from a solved position
#define numShuffleMoves		700


/***********************************************************************
 *
 *	Internal Structures
 *
 ***********************************************************************/
typedef struct PieceCoordType {
	Int16		row;							// 0-based
	Int16		col;							// 0-based
	} PieceCoordType;


typedef union GameBoardType {
	UInt8		square[numPositions];
	UInt32	save[(numPositions+3)/4];
	} GameBoardType;


/***********************************************************************
 *
 *	Private global variables
 *
 ***********************************************************************/
static GameBoardType	GameBoard;
static Int16			EmptyPos;


/***********************************************************************
 *
 *	Internal Functions
 *
 ***********************************************************************/
static UInt16 StartApplication (void);
static void StopApplication (void);
static Boolean MainFormDoCommand (UInt16 command);
static void MainFormInit (FormPtr frm);
static Boolean MainFormHandleEvent (EventPtr event);
static void AppEventLoop (void);


static void		InitGameBoard(void);
static Int16	CoordToPosition(PieceCoordType coord);
static PieceCoordType	PositionToCoord(Int16 pos);
static Int16	GetEmptyPos(void);
static void		MoveOnePiece(Int16 from, Boolean draw);
static void		MoveRange(Int16 from, Boolean draw);
static void		DrawGameBoard(void);
static Int16	MapPenPosition(Int16 penX, Int16 penY);
static void		DrawPiece(Int16 pos);
static void		ShuffleGameBoard(UInt32 moves);
static void		SaveGameBoard(void);
static void		LoadGameBoard(void);




/***********************************************************************
 *
 * FUNCTION:	InitGameBoard
 *
 * DESCRIPTION:	Generate a new game.
 *
 * PARAMETERS:	none
 *
 * RETURNED:	nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *
 ***********************************************************************/
static void InitGameBoard(void)
{
	UInt8		i;
	for ( i=0; i < (numPositions - 1); i++ )
		GameBoard.square[i] = i + 1;
	GameBoard.square[numPositions - 1] = emptySquareID;
	EmptyPos = numPositions - 1;
}


/***********************************************************************
 *
 * FUNCTION:	ShuffleGameBoard
 *
 * DESCRIPTION:	Shuffle the game board, updating it visually with each step.
 *
 * PARAMETERS:	moves		-- number of moves to shuffle
 *
 * RETURNED:	nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/20/95		Initial Version
 *
 ***********************************************************************/
static void ShuffleGameBoard(UInt32 moves)
{
	UInt16		rand;
	PieceCoordType	coord;


	InitGameBoard();
	
	do	{
		rand = (UInt16)SysRandom( 0 ) % 8;				// generate 0-7
		coord = PositionToCoord( EmptyPos );
		if ( rand & 4L )
			coord.row = (Int16)(rand & 3L);
		else
			coord.col = (Int16)(rand & 3L);
		MoveRange( CoordToPosition(coord), false/*draw*/ );
		}
	while ( --moves );
}


/***********************************************************************
 *
 * FUNCTION:	SaveGameBoard
 *
 * DESCRIPTION:	Save game in the feature registry.
 *
 * PARAMETERS:	none
 *
 * RETURNED:	nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *
 ***********************************************************************/
static void SaveGameBoard(void)
{
	UInt16		featureNum;
	UInt16		numFeatures;
	
	numFeatures = sizeof(GameBoard.save) / sizeof(GameBoard.save[0]);
	
	for ( featureNum = 0; featureNum < numFeatures; featureNum++ )
		FtrSet( puzzleAppCreator, featureNum, GameBoard.save[featureNum] );
}


/***********************************************************************
 *
 * FUNCTION:	LoadGameBoard
 *
 * DESCRIPTION:	Load saved game from the feature registry.
 *
 * PARAMETERS:	none
 *
 * RETURNED:	nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *
 ***********************************************************************/
static void LoadGameBoard(void)
{
	Err		err = 0;
	UInt16		featureNum;
	UInt16		numFeatures;
	
	numFeatures = sizeof(GameBoard.save) / sizeof(GameBoard.save[0]);
	
	// Load game board from feature registry
	for ( featureNum = 0; featureNum < numFeatures; featureNum++ )
		{
		err = FtrGet( puzzleAppCreator, featureNum, &GameBoard.save[featureNum] );
		if ( err )	break;
		}

	// Initialize the board of load failed
	if ( !err  )
		{
		EmptyPos = GetEmptyPos();
		}
	else
		{
		InitGameBoard();
		}
}


/***********************************************************************
 *
 * FUNCTION:	GetEmptyPos
 *
 * DESCRIPTION:	Get position of the empty square
 *
 * PARAMETERS:	none
  *
 * RETURNED:	position of the empty square(0-based)
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *
 ***********************************************************************/
static Int16 GetEmptyPos(void)
{
	Int16		pos;
	
	for ( pos=0; pos < numPositions; pos++ )
		if ( GameBoard.square[pos] == emptySquareID )
			return( pos );
	
	ErrDisplay( "didn't find empty square position" );
	return( 0 );
}


/***********************************************************************
 *
 * FUNCTION:	CoordToPosition
 *
 * DESCRIPTION:	Convert row and column pair to a 0-based position
 *
 * PARAMETERS:	coord		-- piece row and column
  *
 * RETURNED:	piece position (0-based)
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *
 ***********************************************************************/
static Int16 CoordToPosition(PieceCoordType coord)
{
	return( (coord.row * boardColumns) + coord.col );
}


/***********************************************************************
 *
 * FUNCTION:	PositionToCoord
 *
 * DESCRIPTION:	Convert a 0-based position to row and column pair
 *
 * PARAMETERS:	pos		-- piece position (0-based)
 *
 * RETURNED:	row and column
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *
 ***********************************************************************/
static PieceCoordType PositionToCoord(Int16 pos)
{
	PieceCoordType		coord;
	
	ErrFatalDisplayIf( pos >= numPositions, "pos out of bounds" );

	coord.row = pos / boardColumns;
	coord.col = pos % boardColumns;
	
	return( coord );
}


/***********************************************************************
 *
 * FUNCTION:	MapPenPosition
 *
 * DESCRIPTION:	Map a screen-relative pen position to a game piece
 *						position;
 *
 * PARAMETERS:	penX		-- display-relative x position
 *				penY		-- display-relative y position
 *
 * RETURNED:	piece position (0-based)
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *
 ***********************************************************************/
static Int16 MapPenPosition(Int16 penX, Int16 penY)
{
	Int16		x;
	Int16		y;
	RectangleType	rect;
	PieceCoordType	coord;
	
	// Map display relative coordinates to window-relative
	x = (Int16)penX;
	y = (Int16)penY;
	WinDisplayToWindowPt( &x, &y );
	
	rect.topLeft.x = boardX + boardFrameMargin;
	rect.topLeft.y = boardY + boardFrameMargin;
	rect.extent.x = (boardColumns * pieceWidth) +
			((boardColumns - 1) * pieceSpace);
	rect.extent.y = (boardRows * pieceHeight) +
			((boardRows - 1) * pieceSpace);
	
	if ( !RctPtInRectangle(x, y, &rect) )
		return( -1 );
	
	// Convert to board-relative coordinates
	x -= boardX;
	y -= boardY;
	
	if ( x < 0 )
		{
		ErrDisplay( "board x is negative" );
		x = 0;
		}
	if ( y < 0 )
		{
		ErrDisplay( "board y is negative" );
		y = 0;
		}
	
	// Get the piece position
	coord.col = x / (pieceWidth + pieceSpace);
	coord.row = y / (pieceHeight + pieceSpace);
	if ( coord.col > maxColumn )
		{
		ErrDisplay( "column out of bounds" );
		coord.col = maxColumn;
		}
	if ( coord.row > maxRow )
		{
		ErrDisplay( "row out of bounds" );
		coord.row = maxRow;
		}
	
	return( CoordToPosition(coord) );
}


/***********************************************************************
 *
 * FUNCTION:	DrawPiece
 *
 * DESCRIPTION:	Draw a game piece
 *
 * PARAMETERS:	pos		-- piece position (0-based)
 *
 * RETURNED:	nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *
 ***********************************************************************/
static void DrawPiece(Int16 pos)
{
	RectangleType	rect;
	PieceCoordType	coord;
	FontID			oldFontID;
	
	ErrFatalDisplayIf( pos >= numPositions, "pos out of bounds" );
	
	// Compute the piece rectangle
	coord = PositionToCoord( pos );
	//PrvPieceCoordToRect( coord, &rect );
	rect.topLeft.x = boardX + boardFrameMargin + (pieceWidth * coord.col) +
			(coord.col * pieceSpace);
	rect.topLeft.y = boardY + boardFrameMargin + pieceHeight *coord.row +
			(coord.row * pieceSpace);
	rect.extent.x = pieceWidth;
	rect.extent.y = pieceHeight;
	
	// Erase the old piece

	// If this is the empty square, erase the old game piece
	if ( GameBoard.square[pos] == emptySquareID )
		{
		RectangleType	erase;
	
		WinEraseRectangle( &rect, 0/*cornerDiam*/ );
		
		// Clean up the pieces of frame around board edges
		if ( coord.col == minColumn )
			{
			erase = rect;
			erase.topLeft.x -= pieceFrameWidth;
			erase.topLeft.y -= pieceFrameWidth;
			erase.extent.x = pieceFrameWidth;
			erase.extent.y = pieceHeight + (pieceFrameWidth * 2);
			WinEraseRectangle( &erase, 0/*cornerDiam*/ );
			}
		else if ( coord.col == maxColumn )
			{
			erase = rect;
			erase.topLeft.x += rect.extent.x;
			erase.topLeft.y -= pieceFrameWidth;
			erase.extent.x = pieceFrameWidth;
			erase.extent.y = pieceHeight + (pieceFrameWidth * 2);
			WinEraseRectangle( &erase, 0/*cornerDiam*/ );
			}
			
		if ( coord.row == minRow )
			{
			erase = rect;
			erase.topLeft.x -= pieceFrameWidth;
			erase.topLeft.y -= pieceFrameWidth;
			erase.extent.x = pieceWidth + (pieceFrameWidth * 2);
			erase.extent.y = pieceFrameWidth;
			WinEraseRectangle( &erase, 0/*cornerDiam*/ );
			}
		else if ( coord.row == maxRow )
			{
			erase = rect;
			erase.topLeft.x -= pieceFrameWidth;
			erase.topLeft.y += rect.extent.y;
			erase.extent.x = pieceWidth + (pieceFrameWidth * 2);
			erase.extent.y = pieceFrameWidth;
			WinEraseRectangle( &erase, 0/*cornerDiam*/ );
			}
		} // If this is the empty square, erase the old game piece
	
	// Erase the old piece frame
	else
		{
		// For now, we are always drawing new pieces over empty squares,
		// and do not need to erase anything
		//WinEraseRectangleFrame( frameBits.word, &rect );
		}
	
	//
	// Draw the new piece
	//
	
	if ( GameBoard.square[pos] != emptySquareID )
		{
		FrameBitsType	frameBits;
		Char				text[32];
		UInt16				textLen;
		Int16				textHeight;
		Int16				textWidth;
		Int16				x, y;
		
		// Draw the frame
		frameBits.word = 0;					// initialize the entire structure
		frameBits.bits.cornerDiam = pieceCornerDiameter;
		frameBits.bits.shadowWidth = 0;
		frameBits.bits.width = pieceFrameWidth;
		WinDrawRectangleFrame( frameBits.word, &rect );
		
		// Draw the label
		StrIToA( text, GameBoard.square[pos] );
		textLen = StrLen( text );
		oldFontID = FntSetFont( ledFont );
		textHeight = FntLineHeight();
		textWidth = FntCharsWidth( text, textLen );
		x = rect.topLeft.x + ((rect.extent.x - textWidth) / 2);
		y = rect.topLeft.y + ((rect.extent.y - textHeight) /2 );
		WinDrawChars( text, textLen, x, y);
		FntSetFont( oldFontID );
		}

}


/***********************************************************************
 *
 * FUNCTION:	DrawGameBoard
 *
 * DESCRIPTION:	Draw the game board
 *
 * PARAMETERS:	pos		-- piece position (0-based)
 *
 * RETURNED:	nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			vmk		8/19/95		Initial Version
 *			vmk		12/17/97	Fixed drawing glitch by initializing the "word"
 *								field of frameBits.
 *
 ***********************************************************************/
static void DrawGameBoard(void)

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕一区二区三区蜜月| 国产精品综合在线视频| 亚洲桃色在线一区| 国产精品国产三级国产aⅴ原创| 欧美电视剧免费全集观看| 欧美一级一级性生活免费录像| 欧美日韩免费视频| 欧美精品久久久久久久多人混战| 国产盗摄精品一区二区三区在线| 亚洲成人高清在线| 亚洲国产cao| 午夜精品免费在线观看| 亚洲444eee在线观看| 午夜精品久久一牛影视| 美女一区二区在线观看| 国产酒店精品激情| 成人夜色视频网站在线观看| eeuss鲁片一区二区三区| 97国产一区二区| 欧美日韩综合不卡| 欧美日韩国产a| 欧美va亚洲va国产综合| 久久久久久97三级| 亚洲图片另类小说| 亚洲一区中文日韩| 久久er99热精品一区二区| 国产精品一二三四| 91玉足脚交白嫩脚丫在线播放| 欧美专区亚洲专区| 欧美一区二区三区的| 久久精品男人的天堂| 亚洲国产精品传媒在线观看| 亚洲精品国产高清久久伦理二区| 午夜精品久久久久| 国产一区二区精品久久| 97精品久久久久中文字幕| 欧美日韩dvd在线观看| 日韩免费看的电影| 国产精品久久久久久亚洲毛片| 亚洲综合999| 久久精品国产色蜜蜜麻豆| 成人av电影在线| 欧美精品一级二级三级| 久久久亚洲欧洲日产国码αv| 亚洲免费在线观看| 免费视频最近日韩| 99视频热这里只有精品免费| 欧美狂野另类xxxxoooo| 欧美国产精品专区| 五月天激情综合网| 成人午夜视频福利| 91精品国产免费| 国产精品免费视频一区| 日韩国产一二三区| 99久久精品久久久久久清纯| 制服丝袜一区二区三区| 中文字幕永久在线不卡| 久久福利视频一区二区| 日本韩国欧美一区二区三区| 337p日本欧洲亚洲大胆色噜噜| 亚洲老妇xxxxxx| 豆国产96在线|亚洲| 91精品综合久久久久久| 成人欧美一区二区三区| 久久 天天综合| 欧美日韩一区二区在线视频| 国产日本欧美一区二区| 日韩激情一二三区| 色综合网色综合| 国产女同性恋一区二区| 日韩一区欧美二区| 欧洲精品在线观看| 亚洲国产精品成人综合| 久久 天天综合| 欧美老女人第四色| 亚洲另类中文字| 国产成人aaa| 2017欧美狠狠色| 麻豆成人久久精品二区三区红 | 色网站国产精品| 国产亚洲欧美激情| 六月丁香婷婷久久| 7777精品伊人久久久大香线蕉的| **欧美大码日韩| 丁香婷婷综合五月| 2014亚洲片线观看视频免费| 青青草97国产精品免费观看| 欧美日韩亚洲高清一区二区| 亚洲色欲色欲www在线观看| 国产v综合v亚洲欧| 久久久久久9999| 国产乱一区二区| 精品国产3级a| 精品一区二区三区在线播放| 欧美亚洲日本国产| 亚洲一区在线播放| 欧美日韩亚洲综合在线 欧美亚洲特黄一级 | 久久色在线视频| 精品一区二区三区免费毛片爱| 欧美一区二区三区在线观看| 婷婷夜色潮精品综合在线| 精品视频123区在线观看| 亚洲柠檬福利资源导航| 色网综合在线观看| 亚洲国产一区视频| 欧美视频在线不卡| 天天操天天色综合| 欧美一区二区在线免费播放| 日产精品久久久久久久性色| 日韩欧美中文字幕制服| 捆绑变态av一区二区三区| 日韩欧美国产午夜精品| 久久草av在线| 久久久久国产一区二区三区四区| 国产精品一级在线| 国产精品女同互慰在线看| 91麻豆.com| 亚洲一区二区三区视频在线播放| 欧美嫩在线观看| 精品在线一区二区| 国产欧美日韩视频一区二区| 成人激情免费视频| 一区二区三区在线观看视频| 欧美日韩aaa| 韩国av一区二区三区四区| 久久久www成人免费毛片麻豆| 成人蜜臀av电影| 亚洲线精品一区二区三区八戒| 制服丝袜激情欧洲亚洲| 国内成人精品2018免费看| 中文字幕av一区二区三区免费看 | 国产在线不卡一区| 国产精品美女www爽爽爽| 在线观看国产日韩| 日本大胆欧美人术艺术动态| 久久久久88色偷偷免费| 91麻豆国产精品久久| 爽好多水快深点欧美视频| 精品国产乱子伦一区| 99国产精品国产精品久久| 亚洲高清免费在线| 久久综合99re88久久爱| 一本久久综合亚洲鲁鲁五月天| 亚瑟在线精品视频| 日本一区二区综合亚洲| 在线观看91精品国产入口| 狠狠色综合色综合网络| 亚洲精品免费播放| 精品区一区二区| 色综合天天性综合| 秋霞午夜鲁丝一区二区老狼| 国产女人aaa级久久久级| 欧美剧在线免费观看网站| 国产精品一二三区在线| 亚洲v日本v欧美v久久精品| 国产欧美一区二区精品婷婷| 欧美性生活影院| 国产成人免费在线视频| 亚洲123区在线观看| 国产精品色噜噜| 日韩一区二区三免费高清| 99久久综合狠狠综合久久| 免费成人深夜小野草| 亚洲老妇xxxxxx| 国产视频视频一区| 777午夜精品免费视频| 成人av资源网站| 国内成+人亚洲+欧美+综合在线| 亚洲国产精品欧美一二99| 欧美激情在线免费观看| 日韩欧美国产精品| 日本精品免费观看高清观看| 国产91精品一区二区麻豆网站 | 欧美综合一区二区三区| 国产一区二区三区四区在线观看| 亚洲一区视频在线| 国产精品久久久久影院亚瑟| 精品国产免费视频| 欧美美女bb生活片| 91麻豆免费观看| 成人一道本在线| 国产精品1区2区| 久久国产夜色精品鲁鲁99| 午夜精品久久久久久久99樱桃| 18欧美亚洲精品| 国产精品嫩草影院av蜜臀| 久久婷婷综合激情| 精品国产区一区| 日韩欧美aaaaaa| 日韩一卡二卡三卡四卡| 欧美色区777第一页| 色欧美片视频在线观看| 成人高清视频在线| 高清国产一区二区| 国产精品中文欧美| 国产一区二区三区免费在线观看 | 91官网在线免费观看| av激情综合网| 成人高清视频在线| 成人av在线看|