richman.cpp

来自「本手机游戏richman运行于Nokia 9210 Communicator手机」· C++ 代码 · 共 1,228 行 · 第 1/3 页

CPP
1,228
字号
// richman.CPP
//
// Copyright LiJichuan.  All rights reserved.
//
 

#include "CommonFramework.h"
#include <e32base.h>
#include <e32cons.h>
 

#include "richman.h"
#include <uikon.hrh>
#include <fbs.h>
#include "sprite.h"
#include <MinimalDialog.mbg>
#define TextLocationX			190
#define TextLocationY			93
#define YesOrNoLocationX		75
#define YesOrNoLocationY		80




TUid CExampleApplication::AppDllUid() const
	{
	return KUidIdmin;
	}

CApaDocument* CExampleApplication::CreateDocumentL()
	{
	return new (ELeave) CExampleDocument(*this);
	}



CExampleDocument::CExampleDocument(CEikApplication& aApp)
		: CEikDocument(aApp)
	{
	}

CEikAppUi* CExampleDocument::CreateAppUiL()
	{
    return new(ELeave) CExampleAppUi;
	}




void CExampleAppUi::ConstructL()
    {
    BaseConstructL();
    iAppView=new(ELeave) CExampleAppView;
    iAppView->ConstructL(ApplicationRect()/*ClientRect()*/);
    }

CExampleAppUi::~CExampleAppUi()
	{
    delete iAppView;
	}

void CExampleAppUi::HandleCommandL(TInt aCommand)
	{
	switch (aCommand)
		{
	case EExampleCmdDialog:
	case ECbaButton0:
		iAppView->Posion=300;
		//if(iAppView->blank()==0)			Exit();
		break;
	case ECbaButton1:
		//CExampleCharEditor::Input();
		break;
	case EEikCmdExit:
	case ECbaButton3:
		Exit();
		break;
		}
	}
TKeyResponse CExampleAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
	return iAppView->OfferKeyEventL(aKeyEvent,aType);
}


void CExampleAppView::InitialData()
{
	TInt i,j,k;
						//land[i][0]	owner of the land
						//land[i][1]	level of the land 
						//land[i][2]	x position of the land	associate road
						//land[i][3]	y position of the land	associate road
						//land[i][4]	x position of the land 
						//land[i][5]	y position of the land 
						//land[i][6]	init value of the land 
						//land[i][7]	current value of the land
						//land[i][8]	road the land belong to
	TInt CopyLand[LandNum][LandPra]=
	{	
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,7000,0,0},		//CQ
		{0,0,0,0,0,0,7000,0,0},		
		{0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,3000,0,1},		//XA
		{0,0,0,0,0,0,3000,0,1},
		{0,0,0,0,0,0,3000,0,1},
		{0,0,0,0,0,0,3000,0,1},
		{0,0,0,0,0,0,3000,0,1},
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,10000,0,2},		//BJ
		{0,0,0,0,0,0,10000,0,2},
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,3500,0,3},		//SY
		{0,0,0,0,0,0,3500,0,3},		
		{0,0,0,0,0,0,3500,0,3},
		{0,0,0,0,0,0,3500,0,3},
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,4000,0,4},		//NJ
		{0,0,0,0,0,0,4000,0,4},
		{0,0,0,0,0,0,4000,0,4},
		{0,0,0,0,0,0,4000,0,4},
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,8000,0,5},		//SH
		{0,0,0,0,0,0,8000,0,5},
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,3000,0,6},		//GZ
		{0,0,0,0,0,0,3000,0,6},
		{0,0,0,0,0,0,3000,0,6},
		{0,0,0,0,0,0,3000,0,6},
		{0,0,0,0,0,0,3000,0,6},
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,9000,0,7},		//HK
		{0,0,0,0,0,0,9000,0,7},
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,3500,0,8},		//SZ
		{0,0,0,0,0,0,3500,0,8},
		{0,0,0,0,0,0,3500,0,8},
		{0,0,0,0,0,0,3500,0,8},
		{0,0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,4000,0,9},		//CD
		{0,0,0,0,0,0,4000,0,9},
		{0,0,0,0,0,0,4000,0,9},
		{0,0,0,0,0,0,4000,0,9}
	};
/////////////////////////////////////////////
//land associate road's position
/////////////////////////////////////////////
	for(i=0;i<LandNum;i++)
		for(j=0;j<LandPra;j++)
			Land[i][j]=CopyLand[i][j];
	for(i=0;i<LandNum;i++)
		Land[i][7]=Land[i][6];

	for(i=0;i<18;i++)
		Land[i][3]=16;
	for(i=18;i<22;i++)
		Land[i][2]=606;
	for(i=22;i<40;i++)
		Land[i][3]=184;
	for(i=40;i<44;i++)
		Land[i][2]=28;
	Land[0][2]=32;
	Land[1][2]=84;
	Land[2][2]=114;
	Land[3][2]=146;
	Land[4][2]=178;
	Land[5][2]=210;
	Land[6][2]=242;
	Land[7][2]=274;
	Land[8][2]=306;
	Land[9][2]=338;
	Land[10][2]=370;
	Land[11][2]=396;
	Land[12][2]=428;
	Land[13][2]=460;
	Land[14][2]=492;
	Land[15][2]=524;
	Land[16][2]=556;
	Land[17][2]=608;
	for(i=0;i<18;i++)
	{
		Land[i+22][2]=639-Land[i][2];
	}

	Land[18][3]=Land[43][3]=52;
	Land[19][3]=Land[42][3]=84;
	Land[20][3]=Land[41][3]=116;
	Land[21][3]=Land[40][3]=148;
/////////////////////////////////////////////
//////////land 's position
/////////////////////////////////////////////
	for(i=0;i<18;i++)
	{
		Land[i][4]=Land[i][2];
		Land[i][5]=Land[i][3]+20;
	}
	for(i=18;i<22;i++)
	{
		Land[i][4]=Land[i][2]-23;
		Land[i][5]=Land[i][3];
	}
	for(i=22;i<40;i++)
	{
		Land[i][4]=Land[i][2];
		Land[i][5]=Land[i][3]-30;
	}
	for(i=40;i<44;i++)
	{
		Land[i][4]=Land[i][2]+27;
		Land[i][5]=Land[i][3];
	}

/*	for(i=0;i<RoadNum;i++)
		for(j=0;j<LandPerRoad;j++)
			Road[i][j]=j+i*(LandPerRoad+1);
*/
	Road[0][0]=2;
	Road[1][0]=5;
	Road[2][0]=2;
	Road[3][0]=4;
	Road[4][0]=4;
	Road[5][0]=2;
	Road[6][0]=5;
	Road[7][0]=2;
	Road[8][0]=4;
	Road[9][0]=4;
	k=0;
	for(i=0;i<RoadNum;i++)
	{
		k++;
		for(j=0;j<Road[i][0];j++)
		{
			Road[i][j+1]=k++;
		}
	}
	//

	tempk=0;
	BeforeStart=0;
	LOCATION=0;
	PersonGo=0;
	Step=0;
	Person[1][0]=Person[2][0]=Person[3][0]=Person[4][0]=200000;
	Person[1][1]=0;
	Person[2][1]=17;
	Person[3][1]=22;
	Person[4][1]=39;
	WaitTimer=0;
	TimerCount=0;
	Arrived=0;		
	KeyChoose=1;		//yes
	ThisTurnFinished=0;
	CanBuyLand=0;
	PersonThisTurn=1;
	computed=0;
	ChoosePerson=0;
	Player=1;
	saizisort[0]=4;
	saizisort[1]=1;
	saizisort[2]=2;
	saizisort[3]=0;
	saizisort[4]=3;
	saizisort[5]=5;	
	now.HomeTime();			//Ramdom Seed
	iSeed=now.Int64();
	Posion=50;
	k=1;
}
void CExampleAppView::ConstructL(const TRect& aRect)
    {    
    _LIT(KSwiss, "Mssong");
    CreateWindowL();
    SetRect(aRect);    
#ifdef __WINS__
	TFontSpec spec(KSwiss, 200);
#else
	TFontSpec spec(KSwiss, 100);
#endif
    //iAppFont=iCoeEnv->CreateScreenFontL(spec);
	//CFont* myFont;
	CGraphicsDevice* screenDevice = iCoeEnv->ScreenDevice();
	screenDevice->GetNearestFontInTwips(iAppFont,spec);	
	GetFullPath();
	LoadResource();
	LoadAllBitmap();
	iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityStandard);
	TDisplayMode displayMode = CEikonEnv::Static()-> ScreenDevice()->DisplayMode();	
	iBackBufferBitmap = new(ELeave) CFbsBitmap();
	User::LeaveIfError(iBackBufferBitmap->Create(Rect().Size(), displayMode));
	iBackBufferDevice = CFbsBitmapDevice::NewL(iBackBufferBitmap);
	User::LeaveIfError(iBackBufferDevice->CreateContext(iBackBufferGc));
	iBackBufferGc->UseFont(iAppFont);	
	testbmp=LoadMyBitmapL(39);
	BitAdd=(TUint16*)AppBitMap->DataAddress();
	BufferAdd=(TUint16*)iBackBufferBitmap->DataAddress();
	blank();
	InitialData();

	StartTimer();
    ActivateL();
	

    }
void CExampleAppView::LoadSprite()
{	
	TBuf<60>	FullFileName;
	FullFileName=FullPath;
	_LIT(RFileName,"MySprite.mbm");
	FullFileName.Insert(FullFileName.Length(),RFileName);
	TFileName mbmFileName(FullFileName);
	iMySprite = RWsSprite( CEikonEnv::Static()->WsSession() );
	User::LeaveIfError( iMySprite.Construct( Window(), TPoint(0,0), 0 ) );
	for ( TInt i = 0; i < 7; i ++ ) 
	{ 
		iMySpriteMembers[i].iBitmap = new ( ELeave ) CFbsBitmap();
		User::LeaveIfError( iMySpriteMembers[i].iBitmap->Load( mbmFileName,i*2) ); 
		iMySpriteMembers[i].iMaskBitmap = new ( ELeave ) CFbsBitmap();
		User::LeaveIfError( iMySpriteMembers[i].iMaskBitmap->Load( mbmFileName,i*2+1) ); 
		iMySpriteMembers[i].iInvertMask = ETrue;
		iMySpriteMembers[i].iOffset = TPoint(0,0); 
		iMySpriteMembers[i].iInterval = TTimeIntervalMicroSeconds32(100000);
		User::LeaveIfError( iMySprite.AppendMember( iMySpriteMembers[i] ) ); 
	}   
	User::LeaveIfError(iMySprite.Activate());
	iMySprite.SetPosition(TPoint(50,50));
}


CExampleAppView::~CExampleAppView()
	{
	iCoeEnv->ReleaseScreenFont(iAppFont);
	//delete iExampleText;
	}

CFbsBitmap* CExampleAppView::LoadMyBitmapL(TInt i) 
{
	TBuf<60>	FullFileName;
	FullFileName=FullPath;
	_LIT(RFileName,"MyGame.mbm");
	FullFileName.Insert(FullFileName.Length(),RFileName);
	TFileName mbmFileName(FullFileName);
	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
	CleanupStack::PushL(bitmap);
	User::LeaveIfError(bitmap->Load(mbmFileName, i));
	CleanupStack::Pop(); 
	return bitmap; 
}

TInt CExampleAppView::blank()
{

	TPckgBuf<TScreenInfoV01> info;
	UserSvr::ScreenInfo(info);
	if(info().iScreenAddressValid==EFalse ||
     info().iScreenSize.iWidth!=640 ||
     info().iScreenSize.iHeight!=200) 
		return 0;
	screenMemory=STATIC_CAST(TUint16*,info().iScreenAddress);
	screenMemory += 16;
	ScrrenMemoryBak=screenMemory;
//	TUint16* screenMemory = (TUint16*) screenInfo.iScreenAddress + 16;  
	return 1;

}


void CExampleAppView::Draw(const TRect& /*aRect*/) const 
{
///////////////////////////
//Copy BackScreen To Screen
#ifdef __WINS__	
	CWindowGc& gc = SystemGc();
	TRect drawRect=Rect();
	gc.BitBlt(Rect().iTl, iBackBufferBitmap);
#else
	BltBuffer();							
#endif
//////////////////////////
} 

void CExampleAppView::BltBuffer()
{
	
	TUint16* scrmem;
	scrmem=screenMemory;
	for(TInt i=0;i<640*200;i++)  	  *scrmem++=*BufferAdd++;
	
}

void CExampleAppView::StartTimer()
{
	if (!iPeriodicTimer->IsActive())
	{
		iPeriodicTimer->Start(1,1,TCallBack(CExampleAppView::Period,this));
	}	
}

void CExampleAppView::ThisTurn()
{		
	if(BeforeStart==0)
	{
		if(Key==' ')
		{
			BeforeStart=1;
		}
		return ;
	}
	if(ChoosePerson==0)
	{
		switch(Key)

⌨️ 快捷键说明

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