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

📄 oandxcontroller.h

📁 Symbian OS C++ for Mobile Phones Volume 3 源码
💻 H
字号:
// OandxController.h
//
// Copyright (c) 2006 Symbian Ltd.  All rights reserved.
//

#ifndef OANDX_CONTROLLER_H
#define OANDX_CONTROLLER_H

#include <transportinterface.h>

#include <coecntrl.h>
#include <coemain.h>

#include <eikedwin.h>
#include <eiklabel.h>
#include <eikdialg.h>
#include <eikappui.h>
#include <eikapp.h>
#include <eikdoc.h>
#include <eikenv.h>
#include <eikon.hrh>

#include <oandx.rsg>
#include "oandx.hrh"
#include "oandxappview.h"

class COandXEngine;
class CWaitDialog;

class COandXController : public CBase, public MTransportObserver
/**
	This controller uses instructions from the users to update the
	engine (board.) 
 */
	{
public:
	static COandXController* NewL(MOandXGameObserver* aObserver);
	virtual ~COandXController();

	void OfferGameL(TUid aTransportUid, TBool aRequireAddress);
	void JoinGameL(TUid aTransportUid, TBool aRequireAddress);
	
	TBool DrawableGame() const;
    void HitSquareL(TInt aIndex);
    TBool IsCrossTurn() const;

	void SendIndexL();
	
private:
	COandXController(MOandXGameObserver* aObserver);
	void ConstructL();

	void ResetCurrentGame();
	void AllocTransportL(TUid aTransportUid, TBool aRequireAddress, TBool aInitListen);
	static TInt ConnectionCloserCallBack(TAny* aPtr);
	void DeleteTransport();

	void SendMove(TInt aIndex);
	void TerminateGame(const TDesC& aMsg);
	
	// implement MTransportObserver
	virtual void SentPayload();
	virtual void ReceivedPayload(const TDesC& aPayload);
	virtual void LostConnection(TInt aError);
	
	virtual TInt StartedLookingForServiceL();
	virtual void StoppedLookingForService();
	virtual TInt StartedConnectingToServiceL();
	virtual void StoppedConnectingToService();
	virtual TInt StartedWaitingForClientL();
	virtual void StoppedWaitingForClient();

	TInt RunWaitDialogL(const TDesC& aMessage);
	void CancelWaitDialog();

#ifdef _DEBUG
	enum TPanic
	/** Invalid states for this object. */
		{
		EAtAlreadyExists = 0x10,
		ERpBadState = 0x20,
		ESpBadState = 0x30,
		ESmBadState = 0x40
		};
	static void Panic(TPanic aPanic);
#endif

private:
	/** Observer to notify when game events occur. */
	MOandXGameObserver*const iObserver;

	/** Engine represents the board. */
	COandXEngine* iEngine;
	/** Tears down the transport outside of the current AO. */
	CAsyncCallBack* iConnectionCloser;
	/** Transport used to communicate with remote device. */
	CTransportInterface* iTransportInterface;

	enum TState
	/** This object's state identifies which event it is waiting for. */
		{
		EStBlank,					///< No game is in progress.
		EStWaitRemoteJoin,			///< Waiting for a remote player to connect.
		EStWaitLocalMove,			///< Waiting for local user to move.
		EStWaitSendingLocalMove,	///< Sending local move to remote player.
		EStWaitRemoteMove,			///< Waiting for remote player to move.
		EStWaitOffer,				///< Waiting to connect to remote host
		EStFinished					///< Game has been won.
		};
	/** This object's current state. */
	TState iState;
	void CheckForGameOver(TState aNotOverState);

	/** The local user's symbol, ETileNought or ETileCross. */
	TInt iLocalUserSymbol;
	
	/** Points to waiting dialog, e.g. when connection to remote device. */
	CWaitDialog* iWaitDialog;
	/** Whether the application (as opposed to the user) cancelled the wait dialog. */
	TBool iAppDismiss;
	};

class CWaitDialog : public CEikDialog
/**
	This dialog displays a wait message while connecting
	to a remote devices.
 */
	{
public:
	CWaitDialog(const TDesC& aBodyText);

	inline void TryExitL(TInt aButtonId);

private:
	// override CEikDialog
	virtual void PreLayoutDynInitL();

private:
	/** Text to display in wait dialog label. */
	const TDesC& iBodyText;
	};

inline void CWaitDialog::TryExitL(TInt aButtonId)
/**
	This function is defined to provide access to TryExitL,
	which is protected in CEikDialog.

	@param	aButtonId		The ID of the pressed button.
 */
	{
	CEikDialog::TryExitL(aButtonId);
	}

class CTextInputDialog : public CEikDialog
/**
	Modal dialog gets remote device address.
 */
	{
public:
	CTextInputDialog(const TDesC& aTitle, TDes& aBuffer);

private:
	// override CEikDialog
	virtual void PreLayoutDynInitL();
	virtual TBool OkToExitL(TInt aKeyCode);

private:
	/** Dialog title. */
	const TDesC& iTitle;
	/** Descriptor to populate with text entered by user. */
	TDes& iBuffer;
	};


#endif // OANDX_CONTROLLER_H

⌨️ 快捷键说明

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