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

📄 mopoidgrid.h

📁 一款大砖块的游戏
💻 H
字号:
/*
* ============================================================================
*  Name     : TMopoidGrid and TBrick from MopoidGrid.h
*  Part of  : Mopoid
*  Created  : 16.01.2004 by Andreas Jakl / Mopius - http://www.mopius.com/
*  Description:
*     Handles the grid containing bricks.
*  Version  : 1.02
*  Copyright: 
*     'Mopoid' is free software; you can redistribute
*     it and/or modify it under the terms of the GNU General Public License
*     as published by the Free Software Foundation; either version 2 of
*     the License, or (at your option) any later version.
* 
*     'Mopoid' is distributed in the hope that it
*     will be useful, but WITHOUT ANY WARRANTY; without even the implied
*     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*     See the GNU General Public License for more details.
* 
*     You should have received a copy of the GNU General Public License
*     along with 'Mopoid'; if not, write to the Free Software
*     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
* ============================================================================
*/

#ifndef __MOPOIDGRID_H__
#define __MOPOIDGRID_H__

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

#define GRID_COLS		8
#define GRID_ROWS		7

// -------------------------------------------------------------------------
/**
 * Class containing information about a brick.
 */
class TBrick {
public:
    typedef enum {
        EBrickInactive,
        EBrickInvisible,
	    EBrickIndestructible, 
	    EBrickNormal, 
	    EBrickDouble
    } 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 TMopoidGrid {
    
public:		/// Constructors
	TMopoidGrid();

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 Init();

    /**
     * Copy the level to the internal grid. Also counts the number of active blocks.
     * @param aBricks level definition array that contains the blocks.
     * @return the number of active bricks in the current level.
     */
    TInt LoadLevel(TBrick aBricks[GRID_COLS][GRID_ROWS]);


    /**
     * 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;


    /**
     * 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 HitBrickAtPos(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 HitBrickAtPos(const TInt aXGrid, const TInt aYGrid);

private:    // Own private functions
	
public:     // Public data

    /**
     * Size of a brick bitmap.
     */
	TSize iBrickSize;

    /**
     * Upper left position where the bricks-grid should start (= offset).
     */
	TPoint iUpperLeft;

    /**
     * rectangle containing the grid.
     */
    TRect iGridRect;
	
private:    // Private Data

    /**
     * Array containing the bricks of the current level.
     */
	TBrick iBricks[GRID_COLS][GRID_ROWS];


};

#endif

⌨️ 快捷键说明

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