?? controller.cpp
字號:
// controller.cpp
//
// Copyright (c) 2000 Symbian Ltd. All rights reserved.
//
#include "controller.h"
#include "view.h"
#include "appui.h"
#include <eikenv.h>
#include <eiklabel.h>
#include <s32mem.h>
enum TPanic {
EInitiateNotBlank,
EListenNotBlank,
ERestartNotFinished,
ESetGdpNotBlank,
ESetPrefBadState,
EHitFleetNotMyTurn,
EAbandonNotMyTurn,
EResendBadState,
EBindBadState,
ESendStartNoPrefs,
EHandleRequestBadOpcode,
EHandleResponseBadOpcode,
EHandleRestartReqNotFinished,
EHandleStartReqNotAccepting,
EHandleAbandondReqNotOppTurn,
EHandleHitReqNotOppTurn,
EHandleStartRespNotStarting,
EHandleHitRespNotOppTurn,
EHitFleetAlreadyKnown,
};
static void Panic(TInt aPanic)
{
_LIT(KPanicCategory,"BSHIPS-CTRL");
User::Panic(KPanicCategory, aPanic);
}
/*
class CGameController
*/
CGameController* CGameController::NewL()
{
CGameController* self=new(ELeave) CGameController;
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
void CGameController::ConstructL()
{
iEnv=CEikonEnv::Static();
// construct engine and RGCP
iEngine=new(ELeave) CGameEngine;
iZoomFactor=1000;
}
CGameController::~CGameController()
{
delete iEngine;
}
// persistence
void CGameController::ExternalizeL(RWriteStream& aStream) const
{
aStream.WriteUint8L(iState);
aStream.WriteInt32L(iZoomFactor);
}
void CGameController::InternalizeL(RReadStream& aStream)
{
iState=(TState) aStream.ReadUint8L();
iZoomFactor=aStream.ReadInt32L();
}
TStreamId CGameController::StoreL(CStreamStore& aStore) const
{
RStoreWriteStream stream;
TStreamId id = stream.CreateLC(aStore);
iEngine->ExternalizeL(stream);
ExternalizeL(stream);
stream.CommitL();
CleanupStack::PopAndDestroy(); // stream
return id;
}
void CGameController::RestoreL(const CStreamStore& aStore, TStreamId aStreamId)
{
RStoreReadStream stream;
stream.OpenLC(aStore,aStreamId);
iEngine->InternalizeL(stream);
InternalizeL(stream);
CleanupStack::PopAndDestroy(); // stream
}
// game control
void CGameController::Reset() // set to blank, loopback, my-address from document
{
iEngine->Reset();
iState = EGameOn;
iEnv->InfoMsg(R_GAME_RESET);
}
CFleetView& CGameController::ActiveView() const
{
CGameAppUi* appUI = static_cast<CGameAppUi*>(iEnv->EikAppUi());
return appUI->ActiveView();
}
// fleet view commands
void CGameController::ViewCmdHitFleet(TInt aX, TInt aY)
{
__ASSERT_ALWAYS(!(iEngine->OppFleet().IsKnown(aX, aY)), Panic(EHitFleetAlreadyKnown));
// hit fleet
iEngine->OppFleet().SetShipType(aX, aY, iEngine->MyFleet().ShipType(aX, aY));
TFleet::THitResult result = iEngine->OppFleet().SetHit(aX,aY);
iEngine->MyFleet().SetHit(aX,aY);
// update view and play sounds
switch (result)
{
case TFleet::EMiss:
ActiveView().MissSound();
break;
case TFleet::EShip:
ActiveView().ExplSound();
break;
case TFleet::ESunk:
ActiveView().SunkSound();
break;
default:
break;
};
ActiveView().DrawTilesNow();
// if game is won, transition to finished
if (iEngine->IsWon())
{
iState = EFinished;
iEnv->InfoMsg(R_GAME_CONGRATULATIONS);
}
}
// zooming
void CGameController::ZoomInL()
{
TInt zoom=iZoomFactor;
zoom=
zoom < 250 ? 250 :
zoom < 350 ? 350 :
zoom < 500 ? 500 :
zoom < 350 ? 350 :
zoom < 500 ? 500 :
zoom < 600 ? 600 :
zoom < 750 ? 750 :
zoom < 850 ? 850 :
zoom < 1000 ? 1000 :
250;
CGameAppUi* appUi = static_cast<CGameAppUi*>(iEnv->EikAppUi());
appUi->FleetViewData().SetZoomL(zoom);
ActiveView().DrawNow();
iZoomFactor=zoom;
}
void CGameController::ZoomOutL()
{
TInt zoom=iZoomFactor;
zoom=
zoom > 1000 ? 1000 :
zoom > 850 ? 850 :
zoom > 750 ? 750 :
zoom > 600 ? 600 :
zoom > 500 ? 500 :
zoom > 350 ? 350 :
zoom > 250 ? 250 :
1000;
CGameAppUi* appUi = static_cast<CGameAppUi*>(iEnv->EikAppUi());
appUi->FleetViewData().SetZoomL(zoom);
ActiveView().DrawNow();
iZoomFactor=zoom;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -