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

📄 mopoidgrid.h

📁 mopoid game symbian os application development
💻 H
字号:
/*
========================================================================
 Name        : MopoidGrid.h
 Author      : 
 Copyright   : 
 Description : Handles the grid that contains the bricks.
 License     : 
 
========================================================================
*/
#ifndef __MOPOIDGRID_H__
#define __MOPOIDGRID_H__

#include <eikenv.h>
#include <e32math.h>
#include "MopoidSharedData.h"
#include "MopoidSettings.h"

// -------------------------------------------------------------------------
/**
 * Class containing information about a brick.
 */
class TBrick {
public:
    typedef enum {
        EBrickInactive,
        EBrickInvisible,
	    EBrickIndestructible, 
	    EBrickNormal, 
	    EBrickDouble,
	    EBrickMoving,
	    EBrickHarderBrick,
	    EBrickSofterBrick
    } TBrickType;

	TBrick();
	TBrick(TBrickType aBrickType);

    /**
     * Checks if this brick is active (= has a meaning to the current game world).
     * @return ETrue, if the brick is active. Otherwise: EFalse.
     */
    inline TBool IsActive() const;
public:

    /**
     * The type of the brick.
     */
	TBrickType iBrickType;
};

inline TBool TBrick::IsActive() const
{
    return !(iBrickType == EBrickInactive);
}

// -------------------------------------------------------------------------
/**
 * Class storing the layout of the current level + providing ways to access
 * and modify the information.
 */
class CMopoidGrid : public CBase {
    
public:		/// Constructors
	CMopoidGrid();
	
	~CMopoidGrid();

	/**
	 * Store a pointer to the settings object.
	 * This is requied - without the pointer assigned, you will get
	 * null pointer exceptions (KERN-EXEC 3) as there are no checks
	 * for performance reasons.
	 * This class does not take ownership of this object.
	 */
	void SetSettingsPointer(CMopoidSettings* aSettings);

public:     // Own public functions
    /**
     * Initialize the grid. The brick-size has to be set before this function is called.
     * Fills the grid with empty bricks and sets up the rectangle where the grid will be drawn.
     */
    void InitL();

    /**
     * Checks if the specified x/y-position is inside of the grid area.
     * @param aXY x/y coordinates to check.
     * @return ETrue if the position is within the grid area.
     */
    TBool IsXYInGrid(const TPoint aXY) const;


    /**
     * Converts a grid position to real x/y coordinates (top left of grid cell).
     * @param aXYGrid position in grid.
     * @return point containing screen coordinates.
     */
    TPoint ConvertGridToXY(const TPoint aXYGrid) const;

    /**
     * Converts a grid position to real x/y coordinates (top left of grid cell).
     * @param aXGrid position in grid (x-axis).
     * @param aYGrid position in grid (y-axis).
     * @return point containing screen coordinates.
     */
    TPoint ConvertGridToXY(const TInt aXGrid, const TInt aYGrid) const;


    /**
     * Converts real x/y screen coordinates to the grid cell coordinates.
     * @param aXY screen coordinates.
     * @return position information of the grid cell that corresponds to 
     * the x/y screen coordinates.
     */
	TPoint ConvertXYToGrid(const TPoint aXY) const;

    /**
     * Converts real x/y screen coordinates to the grid cell coordinates.
     * @param aX screen coordinate, x-axis.
     * @param aY screen coordinate, y-axis.
     * @return position information of the grid cell that corresponds to 
     * the x/y screen coordinates.
     */
	TPoint ConvertXYToGrid(const TInt aX, const TInt aY) const;


	void SetBrickAtPos(const TPoint aXYGrid, TBrick::TBrickType aBrickType);
	
    /**
     * Check if grid coordinate is valid and if it contains an active brick.
     * @param aXYGrid grid position to check.
     * @return ETrue if grid position contains an active brick.
     */
    TBool IsBrickAtPos(const TPoint aXYGrid) const;

    /**
     * Check if grid coordinate is valid and if it contains an active brick.
     * @param aXGrid grid position to check, x-axis.
     * @param aYGrid grid position to check, y-axis.
     * @return ETrue if grid position contains an active brick.
     */
	TBool IsBrickAtPos(const TInt aXGrid, const TInt aYGrid) const;


    /**
     * Check whether this grid position contains something to draw.
     * @param aXGrid grid position to check, x-axis.
     * @param aYGrid grid position to check, y-axis.
     * @return EFalse if there is no brick at this position, or if it is invisible.
     */
    TBool DrawBrickAtPos(const TInt aXGrid, const TInt aYGrid) const;

    /**
     * Return the brick type of the specified grid position.
     * @param aXYGrid grid position to check.
     * @return brick type at the specified grid position.
     */
    TBrick::TBrickType GetBrickTypeAtPos(const TPoint aXYGrid) const;

    /**
     * Return the brick type of the specified grid position.
     * @param aXGrid grid position to check, x-axis.
     * @param aYGrid grid position to check, y-axis.
     * @return brick type at the specified grid position.
     */
    TBrick::TBrickType GetBrickTypeAtPos(const TInt aXGrid, const TInt aYGrid) const;


    /**
     * Should be called when the specified brick position was hit by the ball.
     * Will modify the brick at the position according to its properties.
     * @param aXYGrid grid position where to hit a brick.
     * @return ETrue if the brick was destroyed. EFalse otherwise (e.g. also
     * when it was the first hit of a double-hit brick, or an indestructible brick).
     */
	TBool HitBrickAtPosL(const TPoint aXYGrid);

    /**
     * Should be called when the specified brick position was hit by the ball.
     * Will modify the brick at the position according to its properties.
     * @param aXGrid grid position where to hit a brick, x-axis.
     * @param aYGrid grid position where to hit a brick, y-axis.
     * @return ETrue if the brick was destroyed. EFalse otherwise (e.g. also
     * when it was the first hit of a double-hit brick, or an indestructible brick).
     */
	TBool HitBrickAtPosL(const TInt aXGrid, const TInt aYGrid);
	
	TInt GetNumBricks();
	
	void CreateGridL();
	
	void DeleteGrid();

private:    // Own private functions
	TPoint FindBrickExceptPosL(const TInt aXGrid, const TInt aYGrid, const TBrick::TBrickType aBrickType);
	
public:     // Public data
    /**
     * rectangle containing the grid.
     */
    TRect iGridRect;
	
private:    // Private Data

    /**
     * Array containing the bricks of the current level.
     */
	TBrick** iBricks;

    /**
     * Number of remaining (destroyable) bricks.
     */
	TInt iNumBricks;
	
	/**
	 * Number of columns the array is currently made of.
	 * It's important to save this value here, as the value stored
	 * in the settings might be changed from the outside and then
	 * doesn't correspond to the array anymore, causing in memory
	 * problems when deleting or accessing it.
	 */
	TInt iCurGridCols;

	/**
	 * Number of rows the array is currently made of.
	 * It's important to save this value here, as the value stored
	 * in the settings might be changed from the outside and then
	 * doesn't correspond to the array anymore, causing in memory
	 * problems when deleting or accessing it.
	 */
	TInt iCurGridRows;
private:
	/**
	 * Pointer to the settings object, required for
	 * various calculations.
	 * Will need the size of some objects from the settings object.
	 */
	CMopoidSettings* iSettings;

};

#endif

⌨️ 快捷键说明

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