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

📄 engine.h

📁 也是一个基于S60的源代码
💻 H
字号:
// engine.h
//
// Copyright (c) 2000 Symbian Ltd.  All rights reserved.

#ifndef __ENGINE_H
#define __ENGINE_H

#include <s32std.h>

class TShip
	{
public:
	enum TShipType
		{
		EUnknown, ESea,
		EBattleship, ECruiser, EDestroyer, EFrigate
		};
public:
	TShip(); // default constructor for no initialization
	TShip(TShipType aType); // initialize type, length and remaining
	// persistence
	void ExternalizeL(RWriteStream& aStream) const;
	void InternalizeL(RReadStream& aStream);
public:
	// initialized members
	TShipType iType; // type
	TInt iLength; // length - determined from type
	TInt iRemaining; // remaining unhit squares
	// calculated members
	TInt iStartX, iStartY; // start position
	TInt iDx, iDy; // orientation vector
	};

class TFleet
	{
public:
	enum TSquareState // same as TShip::TShipType
		{
		EUnknown, ESea,
		EBattleship, ECruiser, EDestroyer, EFrigate,
		EHit=0x80
		};
public:
	// setup
	TFleet();
	void SetupBlank();
	void SetupRandom();
	void SetMyFleet();
	void SetOppFleet();
	// interrogators
	TBool IsMyFleet() const;
	TBool IsOppFleet() const;
	TBool IsShip(TInt aX, TInt aY) const;
	TShip::TShipType ShipType(TInt aX, TInt aY) const;
	TBool IsSea(TInt aX, TInt aY) const;
	TBool IsKnown(TInt aX, TInt aY) const;
	TBool IsHit(TInt aX, TInt aY) const;
	// complicated interrogators
	TShip& ShipAt(TInt aX, TInt aY) const; // use for my fleet only
	TShip* PossibleShipAt(TInt aX, TInt aY) const; // use even if fleet unknown
	TInt RemainingSquares() const; // fleet squares which haven't been destroyed
	TInt RemainingShips() const; // ships which haven't been totally destroyed
	TInt SquaresHit() const; // squares hit (sea or otherwise)
	// change
	void SetSea(TInt aX, TInt aY); // say a square is sea
	void SetShipType(TInt aX, TInt aY, TShip::TShipType aShipType); // set ship type
	void SetHit(TInt aX, TInt aY); // hit a square - must be known when it's hit
	void TestWholeShip(TInt aX, TInt aY); // test whether hit has sunk a ship
	void SetSeaAroundHit(TInt aX, TInt aY); // set sea around a hit square
	// persistence
	void ExternalizeL(RWriteStream& aStream) const;
	void InternalizeL(RReadStream& aStream);
private:	
	// setup
	TBool TryPlaceShip(TInt aShipIndex, TShip::TShipType aShipType);
	void PlaceShip(TInt aShipIndex, TShip aShip);
	// square accessors
	const TSquareState& Square(TInt aX, TInt aY) const;
	TSquareState& Square(TInt aX, TInt aY);
private:
	TSquareState iSquares[64];
	TBool iMyFleet; // whether my fleet (which I know all about) or opponent's (which I don't)
	TShip iShips[10]; // all the ships we know about
	TInt iKnownShips; // number of ships known to be in fleet
	TInt iRemainingShips; // how many ships haven't been destroyed
	TInt iRemainingSquares; // how many squares haven't been destroyed
	TInt iSquaresHit; // how many squares (including sea) have been hit
	TInt64 iRandomSeed; // seed for random-number generation during setup
	};

class CGameEngine : public CBase
	{
public:
	// setup
	CGameEngine();
	// reset
	void Reset();
	// interrogate
	TBool IsWon() const;
	TBool IsLost() const;
	TBool IsStarted() const;
	TBool IsMyTurn() const;
	// set up
	void SetFirstPlayer();
	void SetSecondPlayer();
	// persistence
	void ExternalizeL(RWriteStream& aStream) const;
	void InternalizeL(RReadStream& aStream);
	TStreamId StoreL(CStreamStore& aStore) const;
	void RestoreL(const CStreamStore& aStore, TStreamId aStreamId);
public:
	TFleet iMyFleet;
	TFleet iOppFleet;
	TBool iFirstPlayer;
	};

#endif

⌨️ 快捷键说明

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