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

📄 cgameappview.cpp

📁 symbian 的一个 二维飞行游戏 源码 及相关技术文章
💻 CPP
字号:
// Copyright 2002 Kenneth Guy,
// 
// CGameAppView.cpp

/** \file CGameAppView.cpp

    implementation of class CGameAppView */
//

#include "CGameAppUi.h"
#include "CGameAppView.h"
#include "CGameApplication.h"
#include "CGameDocument.h"
#include "CGameState.h"
#include "CScoreDialog.h"
#include "CHighScores.h"

/** 2nd phase construction 
    
    Load strings from resource file, and create the window.
 */

void CGameAppView::ConstructL(const TRect& aRect, CGameState* aGameState) {
  iGameState=aGameState;
  CEikonEnv* eikonEnv=CEikonEnv::Static();
  iCompleteString = eikonEnv->AllocReadResourceL(R_COMPLETE_STRING);
  iPausedString = eikonEnv->AllocReadResourceL(R_PAUSED_STRING);
  iScoresString = eikonEnv->AllocReadResourceL(R_SCORES_STRING);

  CreateWindowL();
  SetRect(aRect);
  ActivateL();
}

/** Delete localised strings. */

CGameAppView::~CGameAppView() {
  delete iCompleteString;
  delete iPausedString;
  delete iScoresString;
}

/** Draw the window.

    Redraw the window depending on the game state */

void CGameAppView::Draw(const TRect& /*aRect*/) const {	
  switch(iGameState->State()) {
  case CGameState::ENoGame:
    DrawHighScores();
    break;
  case CGameState::EPaused:
    DrawPaused();
    break;
  case CGameState::ENextLevel:
    DrawLevelCompleted();
    break;
  }
}

/** Draw high score table.

    Draws the high score table, highliting the most recently
    added entry if there is one. */

void CGameAppView::DrawHighScores() const {
  CWindowGc& gc = SystemGc();
  const CFont*     fontUsed;
  CEikonEnv* eikonEnv=CEikonEnv::Static();
  gc.Clear();
  fontUsed = eikonEnv->TitleFont();
  gc.UseFont(fontUsed);

  TInt y=60;
  const TInt KFontHeight=fontUsed->HeightInPixels();

  TRgb red(230,0,0);
  TRgb blue(0,0,230);
  TRgb black(0,0,0);

  const TRect& area=Rect();

  const TInt KMargin=60;
  gc.SetPenColor(red);
  gc.DrawText(*iScoresString,TPoint((area.Width()-fontUsed->TextWidthInPixels(*iScoresString))/2,30));

  const TInt count=iGameState->HighScores().Number();
  for(TInt i=0;i<count;i++) {
    if(iGameState->HighScores().LastAdded()==i) {
      gc.SetPenColor(blue);
    } else {
      gc.SetPenColor(black);
    }

    gc.DrawText(iGameState->HighScores().Name(i),TPoint(KMargin,y));

    TBuf<15> temp;
    _LIT(KScoreFormat,"%+ 8d");
    
    temp.Format(KScoreFormat,iGameState->HighScores().Score(i));
    gc.DrawText(temp,TPoint(area.Width()-fontUsed->TextWidthInPixels(temp)-KMargin,y));

    y+=KFontHeight;
  }
  gc.SetPenColor(black);
  gc.DiscardFont();
}


/** Draw a paused screen */

void CGameAppView::DrawPaused() const {
  CWindowGc& gc = SystemGc();
  const CFont*     fontUsed;
  CEikonEnv* eikonEnv=CEikonEnv::Static();
  gc.Clear();
  fontUsed = eikonEnv->TitleFont();
  gc.UseFont(fontUsed);
  TRect      drawRect = Rect();
  TInt baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; 
  gc.DrawText(*iPausedString,drawRect,baselineOffset,CGraphicsContext::ECenter,0);
  gc.DiscardFont();
}

/** Draw a level complete screen */

void CGameAppView::DrawLevelCompleted() const {
  CWindowGc& gc = SystemGc();
  const CFont*     fontUsed;
  CEikonEnv* eikonEnv=CEikonEnv::Static();
  gc.Clear();
  fontUsed = eikonEnv->TitleFont();
  gc.UseFont(fontUsed);
  TRect      drawRect = Rect();
  TInt baselineOffset=(drawRect.Height() - fontUsed->HeightInPixels())/2; 
  gc.DrawText(*iCompleteString,drawRect,baselineOffset,CGraphicsContext::ECenter,0);
  gc.DiscardFont();
}

⌨️ 快捷键说明

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