/*
* ============================================================================
* Name : CJewelView from JewelView.h
* Part of : Jewel
* Created : 02.10.2005 by Thosing
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version : 0.1
* Copyright: Another
* ============================================================================
*/
// INCLUDE FILES
#include "JewelView.h"
#include <fbs.h>
#include <aknutils.h>
#include <Jewel.mbg>
#include <e32math.h>
#include "JewelEngine.h"
#include <eikenv.h>
const TRect CJewelView::iJewelSmallRect = TRect(0, 0, 19, 19);
const TRect CJewelView::iJewelLargeRect = TRect(0, 0, 29, 29);
const TRect CJewelView::iBoardRect = TRect(2, 2, 174, 174);
const TPoint CJewelView::iGridStart = TPoint (4, 4);
const TSize CJewelView::iGridSize = TSize(21, 21);
const TInt CJewelView::iNumGridsX = 8;
const TInt CJewelView::iNumGridsY = 8;
const TInt CJewelView::iLifeTotal = 100;
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CJewelView::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CJewelView::ConstructL(const TRect& aRect) {
CreateWindowL();
SetRect(aRect);
//ActivateL();
//Load game elements
iGameBoard=LoadBitmapL(EMbmJewelBoard);
iLifeIndicator=LoadBitmapL(EMbmJewelLife);
iLifeIndicatorMask=LoadBitmapL(EMbmJewelLife_mask);
iProgressBar=LoadBitmapL(EMbmJewelProgress);
iGameOverBitmap=LoadBitmapL(EMbmJewelGameover);
for(int i=0; i<NUM_OF_JEWELS; i++) {
iJewelsSmall[i]=LoadBitmapL(EMbmJewelBlue_s+i*4);
iJewelsSmallMask[i]=LoadBitmapL(EMbmJewelBlue_s+i*4+1);
iJewelsLarge[i]=LoadBitmapL(EMbmJewelBlue_s+i*4+2);
iJewelsLargeMask[i]=LoadBitmapL(EMbmJewelBlue_s+i*4+3);
}
//Create back buffer
TDisplayMode displayMode = CEikonEnv::Static()->ScreenDevice()->DisplayMode();
iBackBuffer = new(ELeave) CFbsBitmap();
CleanupStack::PushL(iBackBuffer);
User::LeaveIfError(iBackBuffer->Create(aRect.Size(), displayMode));
// Create bitmap device for the bitmap
iBackDevice = CFbsBitmapDevice::NewL(iBackBuffer);
// Create graphics context for the bitmap
User::LeaveIfError(iBackDevice->CreateContext(iBackGc));
CleanupStack::Pop();
iGameEngine=new(ELeave) CJewelEngine();
CleanupStack::PushL(iGameEngine);
iGameEngine->ConstructL(this);
CleanupStack::Pop();
iGameEngine->FlushGameboard();
}
// Destructor
CJewelView::~CJewelView() {
if(iGameBoard) delete iGameBoard;
if(iGameOverBitmap) delete iGameOverBitmap;
if(iLifeIndicator) delete iLifeIndicator;
if(iLifeIndicatorMask) delete iLifeIndicatorMask;
if(iProgressBar) delete iProgressBar;
for(int i=0; i<NUM_OF_JEWELS; i++) {
if(iJewelsSmall[i]) delete iJewelsSmall[i];
if(iJewelsSmallMask[i]) delete iJewelsSmallMask[i];
if(iJewelsLarge[i]) delete iJewelsLarge[i];
if(iJewelsLargeMask[i]) delete iJewelsLargeMask[i];
}
if(iBackGc) delete iBackGc;
if(iBackDevice) delete iBackDevice;
if(iBackBuffer) delete iBackBuffer;
if(iGameEngine) delete iGameEngine;
}
// key event
TKeyResponse CJewelView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) {
static TInt hx, hy;
switch(aType) {
case EEventKey:
iGameEngine->KeyPressed(aKeyEvent.iScanCode);
break;
}
return EKeyWasNotConsumed;
}
// ---------------------------------------------------------
// CJewelView::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CJewelView::Draw(const TRect& /*aRect*/) const {
CWindowGc& gc = SystemGc();
if(!iGameEngine->IsGameOver()) {
gc.BitBlt(TPoint(0, 0), iBackBuffer);
} else {
gc.BitBlt(TPoint(0, 0), iGameOverBitmap); // draw game over
const CFont* ft=iEikonEnv->TitleFont();
gc.UseFont(ft);
gc.SetPenStyle(CFbsBitGc::ESolidPen);
gc.SetPenSize(TSize(1, 1));
gc.SetPenColor(KRgbWhite);
TBuf<32> yourScore(_L("Your Score: ")); //score
TBuf<32> highScore(_L("High Score: "));
TInt yourScoreInt=iGameEngine->Marks();
TInt highScoreInt=iGameEngine->LoadHighScore();
yourScore.AppendNum(yourScoreInt);
highScore.AppendNum(highScoreInt);
gc.DrawText(yourScore, TPoint(50, 100));
gc.DrawText(highScore, TPoint(50, 120));
if(yourScoreInt>=highScoreInt) { //high score
gc.DrawText(_L("Congratulations,"), TPoint(45, 150));
gc.DrawText(_L("you break the record!"), TPoint(30, 170));
}
}
}
CFbsBitmap* CJewelView::LoadBitmapL(TInt aID) {
// set the name of the multi-bitmap file containing the bitmaps
_LIT(KMBMFileName,"Jewel.mbm");
TFileName mbmFileName(KMBMFileName);
CompleteWithAppPath(mbmFileName);
// load bitmap from the mbm file
CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
CleanupStack::PushL(bitmap);
User::LeaveIfError(bitmap->Load(mbmFileName, aID));
CleanupStack::Pop(); //bitmap
return bitmap;
}
void CJewelView::DrawBoard(TInt *aJewels, TInt aHighLight, TBool aShowIndicator) {
//aJewels MUST contain at least iNumGridsY*iNumGridsX elements!!
iBackGc->Clear();
//Draw game board
iBackGc->BitBlt(iBoardRect.iTl, iGameBoard);
//Draw general jewels
TInt pointer=0;
for(int y=0; y<iNumGridsY; y++) {
for(int x=0; x<iNumGridsX; x++) {
TInt jewelID=aJewels[pointer];
if(!iGameEngine->IsJewelMasked(pointer))
DrawJewel(TPoint(iGridStart.iX+x*iGridSize.iWidth+1, iGridStart.iY+y*iGridSize.iHeight+1),jewelID);
pointer++;
}
}
//Draw highlighted Jewel.
if(aHighLight>=0) {
TInt hx=aHighLight%iNumGridsX, hy=aHighLight/iNumGridsY;
TInt hID=aJewels[aHighLight];
if(!iGameEngine->IsJewelMasked(aHighLight))
DrawJewel(TPoint(iGridStart.iX+hx*iGridSize.iWidth-4, iGridStart.iY+hy*iGridSize.iHeight-4), hID, EFalse);
if(aShowIndicator)
DrawSwapIndicator(hx, hy);
}
//Draw Life indicator
iBackGc->BitBltMasked(TPoint(2, 175), iLifeIndicator, TRect(0, 0, 32, 32), iLifeIndicatorMask, ETrue);
iBackGc->UseBrushPattern(iProgressBar);
iBackGc->SetBrushStyle(CFbsBitGc::EPatternedBrush);
iBackGc->SetPenStyle(CFbsBitGc::ENullPen);
iBackGc->DrawRect(TRect(40, 177, iGameEngine->Life()+40, 185));
iBackGc->SetBrushStyle(CFbsBitGc::ENullBrush);
iBackGc->SetBrushColor(KRgbWhite);
//Draw Marks
const CFont* ab=iEikonEnv->TitleFont();
iBackGc->UseFont(ab);
iBackGc->SetPenStyle(CFbsBitGc::ESolidPen);
iBackGc->SetPenSize(TSize(1, 1));
TBuf<12> strMark;
strMark.Num(iGameEngine->Marks());
iBackGc->DrawText(strMark, TPoint(50, 200));
}
//draw single jewel
void CJewelView::DrawJewel(TPoint aPoint, TInt aID, TBool aDrawSmall) {
CFbsBitmap* src;
CFbsBitmap* mask;
TRect drawRect;
if(aID<0) return;
if(aDrawSmall) { //small
src=iJewelsSmall[aID];
mask=iJewelsSmallMask[aID];
drawRect=iJewelSmallRect;
} else { //large
src=iJewelsLarge[aID];
mask=iJewelsLargeMask[aID];
drawRect=iJewelLargeRect;
}
iBackGc->BitBltMasked(aPoint, src, drawRect, mask, ETrue);
}
//draw swap indicator
void CJewelView::DrawSwapIndicator(TInt aX, TInt aY) {
CFbsBitGc::TPenStyle penStyle=CFbsBitGc::EDashedPen;
iBackGc->SetPenStyle(CFbsBitGc::ENullPen);
iBackGc->SetPenColor(KRgbRed);
iBackGc->SetPenSize(TSize(2, 2));
iBackGc->MoveTo(TPoint(iGridStart.iX+aX*iGridSize.iWidth, iGridStart.iY+aY*iGridSize.iHeight));
if(aY>0) {
iBackGc->SetPenStyle(penStyle);
} else {
iBackGc->SetPenStyle(CFbsBitGc::ENullPen);
}
iBackGc->DrawLineBy(TPoint(0, -iGridSize.iHei
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
.rar (65个子文件)
Jewel
group
ABLD.BAT 316B
JEWEL.DSP 10KB
JEWEL.UID.CPP 155B
bld.inf 424B
JEWEL.DSW 531B
Jewel.mmp 2KB
JEWEL.SUP.MAKE 10KB
sis
Jewel.pkg 886B
inc
JewelView.h 3KB
JewelEngine.h 2KB
Jewel.loc 973B
Jewel.hrh 669B
JewelAppui.h 2KB
JewelDocument.h 1KB
JewelStartScreen.h 903B
JewelApp.h 1KB
src
JewelEngine.cpp 7KB
JewelDocument.cpp 1KB
JewelApp.cpp 2KB
JewelAppui.cpp 3KB
JewelStartScreen.cpp 1KB
JewelView.cpp 10KB
img
red_l.bmp 3KB
purple_l.bmp 3KB
orange_s_mask.bmp 1KB
yellow_l_mask.bmp 2KB
green_l.bmp 3KB
board.bmp 87KB
orange_s.bmp 1KB
white_s.bmp 1KB
yellow_s.bmp 1KB
white_l.bmp 3KB
white_s_mask.bmp 1KB
gameover.bmp 107KB
orange_l.bmp 3KB
Thumbs.db 56KB
orange_l_mask.bmp 2KB
life.bmp 3KB
blue_s_mask.bmp 1KB
purple_s.bmp 1KB
blue_l.bmp 3KB
green_s_mask.bmp 1KB
white_l_mask.bmp 2KB
purple_s_mask.bmp 1KB
red_l_mask.bmp 2KB
purple_l_mask.bmp 2KB
red_s_mask.bmp 1KB
life_mask.bmp 2KB
blue_l_mask.bmp 2KB
blue_s.bmp 1KB
yellow_l.bmp 3KB
startup.bmp 87KB
green_l_mask.bmp 2KB
progress.bmp 222B
green_s.bmp 1KB
red_s.bmp 1KB
yellow_s_mask.bmp 1KB
aif
list_icon.bmp 4KB
Jewelaif.rss 624B
context_pane_icon.bmp 6KB
Thumbs.db 9KB
list_icon_mask.bmp 294B
context_pane_icon_mask.bmp 414B
data
Jewel_caption.rss 592B
Jewel.rss 2KB
共 65 条
- 1
资源评论
- 齐德隆咚强2015-02-19同楼上,挂羊头卖狗肉。不是泡泡龙
- hqhony2012-08-06不是泡泡龙,类似宝石消除的东西,java的,挂羊头卖狗肉
z4lby
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言基础-C语言编程基础之Leetcode编程题解之第39题组合总和.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第38题外观数列.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第37题解数独.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第36题有效的数独.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第35题搜索插入位置.zip
- index.wxml
- C语言基础-C语言编程基础之Leetcode编程题解之第33题搜索旋转排序数组.zip
- 基于Python实现的手写数字识别系统源码.zip
- 从网页提取禁止转载的文字
- C语言基础-C语言编程基础之Leetcode编程题解之第32题最长有效括号.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功