示例#1
0
        public LevelBuilder()
        {
            int currentXpos = 0;

            for (int i = 0; i < BRICK_NUMBER_X; i++)
            {
                int currentYpos = 0;
                for (int j = 0; j < BRICK_NUMBER_Y; j++)
                {
                    KeyValuePair <int, int> coordinates = new KeyValuePair <int, int>(i, j);
                    GameObjectEmpty         objectEmpty = new GameObjectEmpty(new Position(currentXpos, currentYpos), BUILDERBRICKDIMY, BUILDERBRICK_DIMX);
                    builderGrid.Add(objectEmpty, coordinates);
                    currentYpos += BUILDERBRICKDIMY;
                }
                currentXpos += BUILDERBRICK_DIMX;
            }
            currentXpos = 0;
            for (int i = 0; i < BRICK_NUMBER_X; i++)
            {
                int currentYpos = 0;
                for (int j = 0; j < BRICK_NUMBER_Y; j++)
                {
                    KeyValuePair <int, int> coordinates = new KeyValuePair <int, int>(i, j);
                    GameObjectEmpty         objectEmpty = new GameObjectEmpty(new Position(currentXpos, currentYpos), BUILDERBRICKDIMY, BUILDERBRICK_DIMX);
                    gameGrid.Add(coordinates, new KeyValuePair <GameObjectEmpty, BrickBasic>(objectEmpty, null));
                    currentYpos += GAMEBRICK_DIMY;
                }
                currentXpos += GAMEBRICK_DIMX;
            }
        }
示例#2
0
        /// <summary>
        /// select a brick in a grid and put it in.
        /// </summary>
        /// <param name="x"> position x</param>
        /// <param name="y"> position y</param>
        /// <param name="state">state of brick</param>
        /// <param name="durability">durability of brick</param>
        /// <returns>value if brick was insert correctly</returns>
        public KeyValuePair <GameObjectEmpty, Boolean> brickSelected(double x, double y, BrickStatus state, int durability)
        {
            KeyValuePair <GameObjectEmpty, Boolean> retState = new KeyValuePair <GameObjectEmpty, bool>(new GameObjectEmpty(new Position(0, 0), 0, 0), false);

            foreach (GameObjectEmpty objectEmpty in builderGrid.Keys)
            {
                if (x > objectEmpty.GetPos().GetX() && x <= objectEmpty.GetPos().GetX() + objectEmpty.GetWidth() && y > objectEmpty.GetPos().GetY() &&
                    y <= objectEmpty.GetPos().GetY() + objectEmpty.GetHeight())
                {
                    KeyValuePair <int, int> brickSelected = builderGrid[objectEmpty];
                    if (this.gameGrid[brickSelected].Value != null)
                    {
                        KeyValuePair <GameObjectEmpty, BrickBasic> temp = new KeyValuePair <GameObjectEmpty, BrickBasic>(gameGrid[brickSelected].Key, null);
                        gameGrid[brickSelected] = temp;

                        retState = new KeyValuePair <GameObjectEmpty, bool>(objectEmpty, false);
                    }
                    else
                    {
                        string selectedTexture;
                        if (state.Equals(BrickStatus.dropPowerup))
                        {
                            selectedTexture = BrickBasic.GetDefaultPowerupTexturePath();
                        }
                        else if (state.Equals(BrickStatus.notDestructible))
                        {
                            selectedTexture = BrickBasic.GetTextureNotDestructible();
                        }
                        else
                        {
                            selectedTexture = BrickBasic.GetDefaultBrickTexturePath();
                        }

                        GameObjectEmpty gameObjectEmpty = gameGrid[brickSelected].Key;
                        BrickBasic      brick           = new BrickBasic(new Position(gameObjectEmpty.GetPos().GetX(), gameObjectEmpty.GetPos().GetY()),
                                                                         this.gameGrid[brickSelected].Key.GetHeight(),
                                                                         this.gameGrid[brickSelected].Key.GetWidth(),
                                                                         state,
                                                                         durability,
                                                                         selectedTexture);
                        KeyValuePair <GameObjectEmpty, BrickBasic> temp = new KeyValuePair <GameObjectEmpty, BrickBasic>(gameGrid[brickSelected].Key, brick);
                        gameGrid[brickSelected] = temp;
                        retState = new KeyValuePair <GameObjectEmpty, bool>(objectEmpty, true);
                    }
                }
            }
            return(retState);
        }