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

📄 noughtsandcrossescontainer.cpp

📁 Symbian智能手机操作系统源代码值的参考_界面
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2005, Nokia. All rights reserved */


// INCLUDE FILES
#include <aknviewappui.h>
#include <AknUtils.h>

#include "noughtsandcrossescontainer.h"
#include "noughtsandcrossesdocument.h"
#include "noughtsandcrossesinformationandsettings.h"
#include "noughtsandcrossesview.h"


// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CNoughtsAndCrossesContainer* CNoughtsAndCrossesContainer::NewL(
    const TRect& aRect, CNoughtsAndCrossesView& aView, TInt aCursorRow, TInt aCursorColumn)
    {
    CNoughtsAndCrossesContainer *self = new (ELeave) CNoughtsAndCrossesContainer(
        aView, aCursorRow, aCursorColumn);
    CleanupStack::PushL (self);
    self->ConstructL (aRect);
    CleanupStack::Pop();
    return self;
    }

// ----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::CNoughtsAndCrossesContainer()
// Default constructor.
// ----------------------------------------------------------------------------
//
CNoughtsAndCrossesContainer::CNoughtsAndCrossesContainer(
    CNoughtsAndCrossesView& aView, TInt aCursorRow, TInt aCursorColumn) :
    iView (aView), iCursorRow (aCursorRow), iCursorColumn (aCursorColumn)
    {
    }

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CNoughtsAndCrossesContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    SetRect(aRect);
    ActivateL();
    HandleBoardReset();
    }

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::~CNoughtsAndCrossesContainer()
// Destructor.
// -----------------------------------------------------------------------------
//
CNoughtsAndCrossesContainer::~CNoughtsAndCrossesContainer()
    {
    }

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CNoughtsAndCrossesContainer::SizeChanged()
    {
    }

// ---------------------------------------------------------
// CNoughtsAndCrossesSettingListbox::HandleResourceChange()
// Called by framework when layout is changed.
// ---------------------------------------------------------
//
void CNoughtsAndCrossesContainer::HandleResourceChange(TInt aType)
    {
    CCoeControl::HandleResourceChange(aType);

    // ADDED FOR SCALABLE UI SUPPORT
    // *****************************
    if ( aType==KEikDynamicLayoutVariantSwitch )
        {
        TRect rect;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
        }
    }

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::CountComponentControls()
// Returns number of components.
// -----------------------------------------------------------------------------
//
TInt CNoughtsAndCrossesContainer::CountComponentControls() const
    {
    return 0;
    }

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::ComponentControl()
// Returns pointer to a particular component.
// -----------------------------------------------------------------------------
//
CCoeControl* CNoughtsAndCrossesContainer::ComponentControl (TInt /*aIndex*/) const
    {
    return NULL;	
    }

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::Draw()
// Draw function.
// -----------------------------------------------------------------------------
//
void CNoughtsAndCrossesContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    
    gc.SetBrushColor(KRgbWhite);
    gc.SetBrushStyle (CGraphicsContext::ESolidBrush);
    gc.DrawRect (aRect);

    DrawGrid (aRect);
    DrawCursor (KRgbBlue, KRgbBlack, iCursorRow, iCursorColumn);

    CNoughtsAndCrossesDocument* document = static_cast<
        CNoughtsAndCrossesDocument*> (iView.AppUi()->Document());

    const CNoughtsAndCrossesDocument::TBoard& board = document->Board();

    for (TInt i = 0; i < BOARD_SIZE; ++i)
        {
        for (TInt j = 0; j < BOARD_SIZE; ++j)
            {
            if (board[i][j] == CNoughtsAndCrossesEngine::ENought)
                {
                DrawNought (i, j);
                }
            else if (board[i][j] == CNoughtsAndCrossesEngine::ECross)
                {
                DrawCross (i, j);
                }
            }
        }

    if (iView.iWinningRowX != -1)
        {
        DrawWinnersLine (iView.iWinningRowX, iView.iWinningColumnX, 
        	iView.iWinningRowY, iView.iWinningColumnY);
        }
    }

// ---------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::OfferKeyEventL()
// Handles keyevents.
// ---------------------------------------------------------------------------
//
TKeyResponse CNoughtsAndCrossesContainer::OfferKeyEventL(
    const TKeyEvent& aKeyEvent, TEventCode aType)
    {
    if (aType != EEventKey)
        {
        return EKeyWasNotConsumed;
        }

    if (aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyOK)
        {
        CNoughtsAndCrossesDocument* document = static_cast<
             CNoughtsAndCrossesDocument*> (iView.AppUi()->Document());

        if (!document->CanMove())
            {
            return EKeyWasConsumed;
            }

        if (document->MakeHumanMoveL(iCursorRow, iCursorColumn))
            {
            if (document->CanMove())
                {
                document->MakeComputerMove();
                }
            }	
        return  EKeyWasConsumed;
        }
    else if (aKeyEvent.iCode == EKeyUpArrow && iCursorRow > 0)
        {
        --iCursorRow;
        DrawDeferred();
        return EKeyWasConsumed;
        }
    else if (aKeyEvent.iCode == EKeyDownArrow && iCursorRow < (BOARD_SIZE-1))
        {
        ++iCursorRow;
        DrawDeferred();
        return EKeyWasConsumed;
        }
    else if (aKeyEvent.iCode == EKeyLeftArrow && iCursorColumn > 0)
        {
        --iCursorColumn;
        DrawDeferred();
        return EKeyWasConsumed;
        }
    else if (aKeyEvent.iCode == EKeyRightArrow && iCursorColumn < (BOARD_SIZE-1))
        {
        ++iCursorColumn;
        DrawDeferred();
        return EKeyWasConsumed;
        }	

    return EKeyWasNotConsumed;
    }

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::HandleMove()
// 
// -----------------------------------------------------------------------------
//
void CNoughtsAndCrossesContainer::HandleMove(TPlayer /*aPlayer*/, TUint /*aRow*/,
    TUint /*aColumn*/)
    {
    DrawDeferred();
    }

// -----------------------------------------------------------------------------
// CNoughtsAndCrossesContainer::HandleWinnerL()
// 
// -----------------------------------------------------------------------------

⌨️ 快捷键说明

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