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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? oandxcontroller.cpp

?? Symbian OS C++ for Mobile Phones v3 Example Code
?? CPP
字號:
// oandxcontroller.cpp
//
// Copyright (c) 2006 Symbian Ltd.  All rights reserved.
//

#include "oandxcontroller.h"
#include "oandxengine.h"
#include "oandxappview.h"
#include "oandxappui.h"
#include "oandxdefs.h"


// -------- (de)allocation --------

COandXController* COandXController::NewL(MOandXGameObserver* aObserver)
/**
	Factory function allocates new instance of COandXController.
	
	@param	aObserver		Observer to notify when game events occur.
	@return					New, initialized instance of COandXController.
							This object is owned by the caller.
 */
	{
	COandXController* self = new(ELeave) COandXController(aObserver);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop(self);
	return self;
	}

COandXController::COandXController(MOandXGameObserver* aObserver)
/**
	Record observer to notify when game events occur, and
	clears the board.
	
	@param	aObserver		Observer to notify when game events occur.
 */
:	iObserver(aObserver),
	iState(EStBlank)
	{
    // empty
	}

void COandXController::ConstructL()
/**
	Second-phase constructor allocates an asynchronous callback
	to delete the transport outside transport AO handling.
 */
	{
	TCallBack cb(ConnectionCloserCallBack, this);
	iConnectionCloser = new(ELeave) CAsyncCallBack(cb, CActive::EPriorityHigh);
	}

COandXController::~COandXController()
/**
	If a transport is in use then delete it.
 */
	{
	delete iConnectionCloser;
	DeleteTransport();
	}


// -------- transport --------

void COandXController::AllocTransportL(TUid aTransportUid, TBool aRequireAddress, TBool aInitListen)
/**
	Factory function allocates a new transport.

	@pre This controller is not currently using a transport.
 */
	{
	TRAN_LOG3(">COandXController::AllocTransportL,uid=0x%08x,ra=%d,il=%d", aTransportUid.iUid, aRequireAddress, aInitListen);
	
	__ASSERT_DEBUG(iTransportInterface == 0, Panic(EAtAlreadyExists));

	TBuf<KMaxAddressLen> address;
	if (aRequireAddress)
		{
		_LIT(KTitle, "Enter address");
		CEikDialog* dlg = new(ELeave) CTextInputDialog(KTitle, address);
		dlg->ExecuteLD(R_TEXTINPUT_DIALOG);
		}
	
	iTransportInterface = CTransportInterface::NewL(aTransportUid, *this, address, aInitListen);
	
	TRAN_LOG1("<COandXController::AllocTransportL,ti=0x%08x", iTransportInterface);
	}

TInt COandXController::ConnectionCloserCallBack(TAny* aPtr)
/**
	This callback function is queued when a link error is detected or
	when a multiplayer game ends.  It tears down the current transport.

	@param	aPtr			Standard 32bit callback value.  This is actually
							the required this pointer.
	@return					KErrNone.  This arbitrary value is used to satisfy
							the callback signature.
 */
	{
	COandXController* self = static_cast<COandXController*>(aPtr);
	self->DeleteTransport();
	return KErrNone;
	}

void COandXController::DeleteTransport()
/**
	Deletes the current transport.  This cannot be called when handling
	a transport AO event.
 */
	{
	delete iTransportInterface;
	iTransportInterface = 0;
	}


// -------- start / stop game --------

void COandXController::OfferGameL(TUid aTransportUid, TBool aRequireAddress)
/**
	Start a new game where this device is the host, and sends the
	first move.  Any existing game is cancelled.
 */
	{
	ResetCurrentGame();
	
	iLocalUserSymbol = ETileCross;
	AllocTransportL(aTransportUid, aRequireAddress, /*aInitListen*/ EFalse);
	iState = EStWaitLocalMove;
	iObserver->ResetView();
	}

void COandXController::JoinGameL(TUid aTransportUid, TBool aRequireAddress)
/**
	Join a game which is being hosted on a remote device.
	This device is noughts and the remote device makes
	the first move.
 */
	{
	ResetCurrentGame();
	
	iLocalUserSymbol = ETileNought;
	AllocTransportL(aTransportUid, aRequireAddress, /*aInitListen*/ ETrue);
	iState = EStWaitRemoteMove;
	iObserver->ResetView();
	}

void COandXController::ResetCurrentGame()
/**
	Helper function for OfferGameL and JoinGameL closes any
	current transport link and resets the current game so it
	is not drawn.
 */
	{
	iState = EStBlank;
	iObserver->ResetView();
	DeleteTransport();
	Engine().Reset();
	}

// -------- game move --------

TBool COandXController::DrawableGame() const
/**
	Predicate function is used by the UI to determine whether there
	is a drawable game.  This can be a game which is in progress or
	which has finished, but it cannot be a game which has been aborted,
	e.g. because of resource failure or a lost connection, or which
	has not yet been started.

	@return					Whether the UI should redraw the game.
 */
	{
	return iState != EStBlank;
	}

void COandXController::HitSquareL(TInt aIndex)
/**
	The UI calls this function when the user selects a square.
	If it is the local player's turn and the selected square is
	blank then it selects the square and sends the move to the
	remote player.  Otherwise this function just returns, which
	saves the UI from having to determine whether the move is
	legal.

	@param	aIndex			Selected square's index.
 */
    {
    TRAN_LOG2(">COandXController::HitSquareL,idx=%d,st=%d", aIndex, iState);
    
    if (!(	iState == EStWaitLocalMove
		&&	Engine().TryMakeMove(aIndex, IsCrossTurn()) ))
        {
        return;
		}

    iObserver->RedrawSquare(aIndex);
	iObserver->RedrawCurrentPlayer();

	// send the move to the remote player
	SendMove(aIndex);

    TRAN_LOG0("<COandXController::HitSquareL");
    }

TBool COandXController::IsCrossTurn() const
/**
	The UI calls this function to find out whether it should
	draw the current player symbol as a nought or a cross.

	@return					Whether the last selected player was crosses.
 */
    {
	TBool ownTurn = (iState == EStWaitLocalMove);
	TBool amCross = (iLocalUserSymbol == ETileCross);
	return ownTurn == amCross;
    }

void COandXController::CheckForGameOver(COandXController::TState aNotOverState)
/**
	Checks if the game has ended, either as a draw or as a win for
	one of the players.  If the game has ended then it notifies the
	local user and tears down the transport.  (This is done as soon
	as possible instead of waiting for another game to start to save
	power.)  If the game has finished the game's state is set to
	EStFinished.

	This helper function combines the is used by SentPayload and
	ReceivedPayload.

	@param	aNotOverState	State to transition to if the game has not
							completed.  (Otherwise this controller
							transitions to EStFinished.)
 */
	{
	TInt winner = Engine().GameWonBy();
	if (winner == 0)
		iState = aNotOverState;
	else
		{
        iState = EStFinished;
        iObserver->ReportWinner(winner);
		iConnectionCloser->CallBack();
		}
	}

void COandXController::SendIndexL()
/**
	Send a custom index to the remote device to test invalid input handling.
	
	This function can only be called if the remote device is waiting for this
	device to send an index, else it would not be listening for input.
 */
	{
	if (iState != EStWaitLocalMove)
		return;
	
	// ask the user to specify the index
	TBuf<KMaxIndexLen> idxText;
	_LIT(KTitle, "Enter index");
	CEikDialog* dlg = new(ELeave) CTextInputDialog(KTitle, idxText);
	dlg->ExecuteLD(R_TEXTINPUT_DIALOG);
	
	TInt idxVal;
	TInt r = TLex(idxText).Val(idxVal);
	User::LeaveIfError(r);
	SendMove(idxVal);
	}

void COandXController::SendMove(TInt aIndex)
/**
	Convert the supplied index to an ASCII character and send it
	to the remote device.
 */
	{
	__ASSERT_DEBUG(iState == EStWaitLocalMove, Panic(ESmBadState));
	
	iState = EStWaitSendingLocalMove;
	TBuf<KPayloadLen> pyl(KPayloadLen);
	pyl[0] = '0' + aIndex;
	iTransportInterface->SendPayload(pyl);
	}

// -------- implement MTransportObserver --------

void COandXController::ReceivedPayload(const TDesC& aPayload)
	{
	__ASSERT_DEBUG(iState == EStWaitRemoteMove, Panic(ERpBadState));

	// extract the tile number from the payload
	TInt tileIndex = aPayload[0] - '0';
	TRAN_LOG1("-COandXController::ReceivedPayload,tileIndex=%d", tileIndex);
	
	TBool validTile = (tileIndex >= 0) && (tileIndex < KNumberOfTiles);
	COandXEngine& eng = Engine();
	validTile = validTile && eng.SquareStatus(tileIndex) == ETileBlank;
	
	if (! validTile)
		{
		_LIT(KInvalidMsg, "Received invalid tile index.");
		TerminateGame(KInvalidMsg);
		}
	else
		{
		eng.TryMakeMove(tileIndex, IsCrossTurn());
		iObserver->RedrawSquare(tileIndex);
		iObserver->RedrawCurrentPlayer();

		CheckForGameOver(EStWaitLocalMove);
		}
	}

void COandXController::SentPayload()
	{
	__ASSERT_DEBUG(iState == EStWaitSendingLocalMove, Panic(ESpBadState));

	CheckForGameOver(EStWaitRemoteMove);
	}

void COandXController::LostConnection(TInt aError)
/**
	Implement MTransportObserver by displaying an error dialog to
	notify the user the connection has been lost, and resetting the game.
	
	@param	aError			Symbian OS error code, the reason for the
							lost connection.  Not used.
 */
	{
	(void) aError;
	
	_LIT(KMessage, "Lost connection to remote device.");
	TerminateGame(KMessage);
	}

void COandXController::TerminateGame(const TDesC& aMsg)
/**
	This function is called when the game has to be terminated
	because of an error condition.
	
	@param	aMsg			Error messge to display to user.
 */
	{
	iState = EStBlank;
	iObserver->ResetView();
	
	_LIT(KEndGame, "End of game");
	CEikonEnv* ee = CEikonEnv::Static();
	ee->AlertWin(KEndGame, aMsg);
	
	// call after dialog dismissed so doesn't run and delete
	// transport while dialog is displayed.
	iConnectionCloser->CallBack();
	}

TInt COandXController::StartedLookingForServiceL()
/**
	Implement MTransportObserver by displaying a modal dialog
	which reads "Waiting for host.".
	
	@return					ExecuteLD return code.
	@see StoppedLookingForService
 */
	{
	_LIT(KMessage, "Waiting for host.");
	return RunWaitDialogL(KMessage);
	}

void COandXController::StoppedLookingForService()
/**
	Implement MTransportObserver by dismissing the dialog
	raised by StartedLookingForServiceL.
	
	@see StartedLookingForServiceL
 */
	{
	CancelWaitDialog();
	}

TInt COandXController::StartedConnectingToServiceL()
/**
	Implement MTransportObserver by raising a modal
	dialog which says "Connecting to service.".
	
	@return					ExecuteLD return code.
	@see StoppedConnectingToService
 */
	{
	_LIT(KMessage, "Connecting to service.");
	return RunWaitDialogL(KMessage);
	}

void COandXController::StoppedConnectingToService()
/**
	Implement MTransportObserver by dismissing the modal
	dialog raised by StartedConnectingToServiceL.
	
	@see StartedConnectingToServiceL
 */
	{
	CancelWaitDialog();
	}

TInt COandXController::StartedWaitingForClientL()
/**
	Implement MTransportObserver by raising a modal
	dialog which says "Waiting for client.".
	
	@return					ExecuteLD return code.
	@see StoppedWaitingForClient
 */
	{
	_LIT(KMessage, "Waiting for client.");
	return RunWaitDialogL(KMessage);
	}

void COandXController::StoppedWaitingForClient()
/**
	Implement MTransportObserver by dismissing the dialog
	raised by StartedWaitingForClientL.
 */
	{
	CancelWaitDialog();
	}

TBool COandXController::RunWaitDialogL(const TDesC& aMessage)
/**
	This helper function puts up a modal dialog.  The dialog is
	dismissed by CancelWaitDialog(), which is called when the
	actual event, such as connecting to a remote device, occurs.
	It can also be dismissed by the user selecting the Cancel
	option.
	
	@param	aMessage		Message to display in wait dialog.
	@return					EFalse if the user cancelled the dialog;
							ETrue if the application cancelled the dialog.
	@see CancelWaitDialog
 */
	{
	iAppDismiss = EFalse;
	iWaitDialog = new(ELeave) CWaitDialog(aMessage);
	iWaitDialog->ExecuteLD(R_WAIT_DIALOG);
	iWaitDialog = 0;
	return iAppDismiss;
	}

void COandXController::CancelWaitDialog()
/**
	This helper functions dismisses the dialog raised by RunWaitDialogL.
	
	@see RunWaitDialogL.
 */
	{
	TRAPD(r, iWaitDialog->TryExitL(EEikBidCancel));
	iAppDismiss = (r == KErrNone);
	}


// -------- debugging --------

#ifdef _DEBUG

void COandXController::Panic(COandXController::TPanic aPanic)
	{
	_LIT(KPanicCat, "OANDXCTRL");
	User::Panic(KPanicCat, aPanic);
	}

#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本不卡视频一二三区| 91精品一区二区三区久久久久久| 欧美做爰猛烈大尺度电影无法无天| 欧美主播一区二区三区美女| 日韩视频一区二区在线观看| 中文字幕成人av| 亚洲午夜影视影院在线观看| 麻豆91在线看| 97久久超碰国产精品| 欧美一二三区在线观看| 国产精品久久久久精k8| 天堂久久一区二区三区| 国产成人av一区二区三区在线| 色呦呦国产精品| 日韩一区二区麻豆国产| 国产精品久久夜| 日韩av不卡在线观看| 波多野结衣中文字幕一区二区三区 | 欧美精品高清视频| 日韩精品中文字幕一区二区三区| 中文字幕一区二区三区色视频| 天堂午夜影视日韩欧美一区二区| 成人精品视频一区二区三区尤物| 欧美高清激情brazzers| 自拍偷拍亚洲欧美日韩| 久久99深爱久久99精品| 欧美性大战久久| 国产精品另类一区| 蜜臀a∨国产成人精品| 色中色一区二区| 久久精品一区二区三区av| 天天影视网天天综合色在线播放| 成人性生交大片免费看在线播放| 欧美日韩不卡在线| 亚洲色图欧洲色图| 国产传媒久久文化传媒| 4438亚洲最大| 亚洲一区二区三区在线| 成人激情开心网| 亚洲精品一区二区三区影院| 午夜精品久久久久久久| 色综合久久综合网欧美综合网| 国产亚洲成年网址在线观看| 麻豆91小视频| 欧美精品丝袜久久久中文字幕| 亚洲天堂成人网| 成人av动漫在线| 欧美精彩视频一区二区三区| 久久av老司机精品网站导航| 欧美肥妇毛茸茸| 亚洲午夜久久久久| 91国产免费观看| 最新日韩在线视频| 成人性生交大片免费| 久久久久久亚洲综合| 久久精品国产精品亚洲红杏| 91精品国产乱码| 亚洲成人你懂的| 欧美日韩一区二区三区高清| 一区二区不卡在线视频 午夜欧美不卡在| 成人精品一区二区三区四区 | 成人免费看黄yyy456| 久久蜜臀精品av| 精品一区二区综合| 日韩欧美一区在线观看| 亚洲国产一区二区视频| 色av综合在线| 亚洲午夜激情av| 欧美日韩精品一二三区| 一区二区国产视频| 欧美视频一二三区| 亚洲妇熟xx妇色黄| 777xxx欧美| 久久机这里只有精品| 欧美一级片在线| 黄网站免费久久| 国产亚洲综合在线| 99在线精品视频| 亚洲精品一二三区| 亚洲欧洲在线观看av| av在线不卡电影| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 99精品国产视频| 亚洲精品伦理在线| 欧美在线免费播放| 日本成人中文字幕在线视频| 欧美一级高清片| 国产精品一二三四| 国产精品情趣视频| 色天使色偷偷av一区二区| 亚洲一区二区av在线| 91麻豆精品国产91| 国产伦精品一区二区三区视频青涩 | 香蕉久久一区二区不卡无毒影院| 在线成人av网站| 久久99久国产精品黄毛片色诱| 久久久久久日产精品| 99精品视频在线观看免费| 夜夜爽夜夜爽精品视频| 在线播放中文字幕一区| 精品一区二区精品| 国产精品久久午夜夜伦鲁鲁| 91久久精品网| 美女免费视频一区| 国产精品久久久久久久蜜臀| 色综合婷婷久久| 日本vs亚洲vs韩国一区三区 | 97精品国产露脸对白| 亚洲午夜精品在线| 欧美v国产在线一区二区三区| 国产风韵犹存在线视精品| 亚洲精品久久7777| 91精品欧美综合在线观看最新| 国产综合久久久久久鬼色 | 欧美色精品天天在线观看视频| 麻豆精品视频在线| 国产精品久久免费看| 欧美剧情片在线观看| 国产乱人伦偷精品视频免下载| 亚洲日韩欧美一区二区在线| 欧美一区二区三区不卡| 粉嫩在线一区二区三区视频| 午夜精品福利久久久| 国产精品嫩草影院av蜜臀| 欧美精品乱人伦久久久久久| 国产91精品免费| 午夜欧美一区二区三区在线播放| 国产嫩草影院久久久久| 国产精品欧美久久久久一区二区| 欧美三级日韩三级国产三级| 国产成人福利片| 日本视频中文字幕一区二区三区| 中文字幕制服丝袜一区二区三区| 91精品国产品国语在线不卡| 成人午夜激情片| 免费看欧美美女黄的网站| 国产精品福利一区| 2017欧美狠狠色| 欧美日韩免费不卡视频一区二区三区| 国产一区二区在线免费观看| 亚洲一卡二卡三卡四卡五卡| 国产欧美一区视频| 欧美一级日韩不卡播放免费| 日本高清免费不卡视频| 国产99一区视频免费| 蜜臀91精品一区二区三区| 亚洲六月丁香色婷婷综合久久 | 91色婷婷久久久久合中文| 久久99蜜桃精品| 午夜精品久久久久久久蜜桃app| 欧美国产欧美综合| 精品精品欲导航| 7777精品伊人久久久大香线蕉| 色综合久久久久| 成人午夜激情片| 国产美女精品一区二区三区| 蜜臀国产一区二区三区在线播放 | 欧美精品久久一区二区三区| 91网站视频在线观看| 懂色av噜噜一区二区三区av| 久99久精品视频免费观看| 天堂成人免费av电影一区| 亚洲综合小说图片| 一区二区三区欧美亚洲| 亚洲日本在线看| 亚洲欧洲性图库| 亚洲欧洲精品一区二区精品久久久 | 日本午夜精品一区二区三区电影 | 日韩精品一区国产麻豆| 欧美美女一区二区| 欧美日韩亚洲综合在线| 欧美亚洲日本国产| 欧美吻胸吃奶大尺度电影| 91黄色免费观看| 欧洲人成人精品| 在线观看日韩一区| 欧美色精品在线视频| 欧美另类变人与禽xxxxx| 欧美视频三区在线播放| 欧日韩精品视频| 欧美日韩国产在线观看| 欧美日韩dvd在线观看| 最新欧美精品一区二区三区| 国产拍揄自揄精品视频麻豆| 国产欧美精品一区二区色综合| 日本一区二区免费在线观看视频| 中文字幕国产一区| 中文字幕制服丝袜成人av| 国产精品免费av| 亚洲另类春色国产| 亚洲午夜日本在线观看| 亚洲成a人v欧美综合天堂下载 | 久久亚洲精品小早川怜子| 欧美精品一区二区蜜臀亚洲| 久久女同精品一区二区| 国产欧美中文在线| 1024成人网色www| 亚洲一区二区三区小说| 午夜影院久久久| 精品在线观看视频|