Пример #1
0
 private void LoadData(int width, int height, string shapeString)
 {
     if (shapeString.Length != width * height)
     {
         throw new InvalidShapeSizeException();
     }
     else if (HasInvalidShapeCharacter(shapeString))
     {
         throw new InvalidShapeStringCharacterException();
     }
     else
     {
         this.width       = width;
         this.height      = height;
         this.shapeString = shapeString;
         this.shapeArray  = new IBrick[width, height];
         int i = 0;
         for (int row = 0; row < height; row++)
         {
             for (int column = 0; column < width; column++)
             {
                 int    nColor = Convert.ToInt32(shapeString.Substring(i, 1));
                 IBrick brick  = null;
                 if (nColor > 0)
                 {
                     brick = new Brick(column, row, GetShapeColorFromInteger(nColor));
                 }
                 shapeArray[column, row] = brick;
                 i++;
             }
         }
     }
 }
Пример #2
0
 public Brick(IBrick brick)
 {
     Boundary    = brick.Boundary;
     ColorNumber = brick.ColorNumber;
     Type        = brick.Type;
     IsHit       = brick.IsHit;
 }
Пример #3
0
 private void LoadData(int width, int height, string shapeString)
 {
     if (shapeString.Length != width * height)
     {
         throw new InvalidShapeSizeException();
     }
     else if (HasInvalidShapeCharacter(shapeString))
     {
         throw new InvalidShapeStringCharacterException();
     }
     else
     {
         this._w        = width;
         this._h        = height;
         this._shapeStr = shapeString;
         this._brickArr = new IBrick[width, height];
         int i = 0;
         for (int row = 0; row < height; row++)
         {
             for (int column = 0; column < width; column++)
             {
                 int    nColor = Convert.ToInt32(shapeString.Substring(i, 1));
                 IBrick brick  = null;
                 if (nColor > 0)
                 {
                     brick = new Brick(column, row, this.ShapeKind);
                 }
                 _brickArr[column, row] = brick;
                 i++;
             }
         }
     }
 }
Пример #4
0
        private bool DetectBrickCollision(IBall ball, out List <BrickHit> bricksHit)
        {
            collisionManager.bricksHit = null;

            bricksHit = new List <BrickHit>();
            List <IBrick> bricks = levelManager.GetCurrent().Bricks;

            bool result = false;
            int  id     = 0;

            foreach (var value in bricks)
            {
                IBrick brick = value;
                if (brick.Hit || !brick.IsVisible())
                {
                    ++id;
                    continue;
                }

                if (collisionManager.Detect(brick, ball))
                {
                    bricksHit.Add(new BrickHit(id, brick));
                    result = true;
                }
                ++id;
            }
            return(result);
        }
        private IBrick DrawBrick(string typeName, object[,] properties, RectangleF rect)
        {
            IBrick brick = ps.CreateBrick(typeName);

            brick.SetProperties(properties);
            return(graph.DrawBrick(brick, rect));
        }
Пример #6
0
 public void Init(IBrick brick)
 {
     this._myTransform = transform;
     this._brick       = brick;
     //  brick = new SimpleBreak(this);
     //   Debug.Log("!!!!!!!!!!!!!!!!");
 }
Пример #7
0
        /// <summary>
        /// Extention method for IBrick. Check is a correct brick part.
        /// </summary>
        /// <param name="x">Part Point X.</param>
        /// <param name="y">Part Point Y.</param>
        /// <returns>True if it is correct part.</returns>
        /// <exception cref="ArgumentException">Thrown exception if new part is not correct.</exception>
        private static bool IsCorrectPart(this IBrick checkedBrick, int id, int x, int y)
        {
            if (checkedBrick.Parts.Count >= GeneralConstants.MaxBrickParts && checkedBrick.Id == id)
            {
                var errMsg = string.Format(ErrMsg.BrickWithThatIdHasAllParts, y, id);
                throw new ArgumentException(errMsg);
            }

            if (checkedBrick.Parts.Count == GeneralConstants.MinBrickParts)
            {
                var existingPart = checkedBrick.Parts[0];
                var canProceed   = (existingPart.Y == y && existingPart.X + 1 == x && checkedBrick.Id == id) ||
                                   (existingPart.X == x && existingPart.Y + 1 == y && checkedBrick.Id == id);

                if (!canProceed)
                {
                    var errMsg = string.Format(ErrMsg.BrickPartWrongPosition, id, y);
                    throw new ArgumentException(errMsg);
                }

                if (existingPart.Y == y && existingPart.X + 1 != x && checkedBrick.Id != id)
                {
                    var errMsg = string.Format(ErrMsg.BrickPartAboveMustMatch, id, y, checkedBrick.Id);
                    throw new ArgumentException(errMsg);
                }

                if (existingPart.X == x && existingPart.Y + 1 != y && checkedBrick.Id != id)
                {
                    var errMsg = string.Format(ErrMsg.BrickPartWrongPositionSameRow, y, id);
                    throw new ArgumentException(errMsg);
                }
            }

            return(true);
        }
Пример #8
0
        /// <summary>
        /// Remove brick by index
        /// </summary>
        /// <param name="indexRow"></param>
        /// <param name="indexOfBrick"></param>
        public void RemoveBrickAt(int indexRow, int indexOfBrick)
        {
            IBrick brick = brickList[indexRow][indexOfBrick];

            brickList[indexRow].RemoveAt(indexOfBrick);
            ResetBrickEvent(brick);
            OnBrickRemoved(brick);
        }
Пример #9
0
 public bool Detect(IBrick first, IBall second)
 {
     if (Check(first as IElement, second as IElement))
     {
         //bricksHit.Add(first);
         return(true);
     }
     return(false);
 }
 private static void Append(SentenceModelBuilder builder, IBrick brick)
 {
     builder.Append(
         brick.Text,
         brick.X,
         brick.Y,
         brick.Width,
         brick.Height);
 }
Пример #11
0
    public void CreateBonusObject(IBrick brick)
    {
        Vector3    pos = brick.GetBrickPosition();
        GameObject obj = bonusesPrefs[Random.Range(0, bonusesPrefs.Length)];

        if (Random.Range(0, 100) < bonusChanse)
        {
            Debug.Log(obj);
            Instantiate(obj, pos, Quaternion.identity);
        }
    }
        private void DrawDetailText(ListViewItem item, Rectangle bounds)
        {
            Rectangle r = bounds;

            r.Width = bounds.Width - (imageList.ImageSize.Width + 2);
            r.Offset(bounds.Width - r.Width, 0);
            IBrick brick = DrawBrick("TextBrick", r);

            brick.SetProperties(new object[, ] {
                { "Text", item.SubItems[0].Text },
                { "Sides", BorderSide.None }, { "BackColor", Color.Transparent }
            });
        }
Пример #13
0
 protected virtual void Brick_OnBrokedCompletly(object sender, EventArgs e)
 {
     if (sender is IBrick)
     {
         bricksLeft--;
         IBrick brick = (IBrick)sender;
         OnBrickBroke(brick);
         GeneratePrize(new RectangleF(brick.Left, brick.Top, brick.Width, brick.Height));
         if (CheckIfLevelFinished())
         {
             FinishLevel();
         }
     }
 }
Пример #14
0
        public bool Rotate90()
        {
            bool test = false;

            if (!_anchored)
            {
                if (_containerBoard == null)
                {
                    throw new NullContainerBoardException();
                }

                IBrick[,] newBrickArr = new IBrick[_h, _w];
                IBrick[,] oldBrickArr = new IBrick[_w, _h];
                //store the original _brickArr in case rotate operation fails
                for (int row = 0; row < _h; row++)
                {
                    for (int column = 0; column < _w; column++)
                    {
                        newBrickArr[_h - row - 1, column] = _brickArr[column, row];
                        oldBrickArr[column, row]          = _brickArr[column, row];
                    }
                }

                _containerBoard.RemovePieceFromCurPosition(this);

                int w = _w;
                int h = _h;
                this._w        = h;
                this._h        = w;
                this._brickArr = newBrickArr;

                if (_containerBoard.TestPieceOnPosition(this, this.X, this.Y))
                {
                    _containerBoard.PutPieceOnPosition(this, this.X, this.Y);
                }
                else
                {
                    this._w        = w;
                    this._h        = h;
                    this._brickArr = oldBrickArr;
                    _containerBoard.PutPieceOnPosition(this, this.X, this.Y);
                }
            }
            return(test);
        }
Пример #15
0
        private void DrawBricks(Graphics g)
        {
            List <IBrick> bricks = Game.Bricks;

            foreach (var entry in bricks)
            {
                IBrick brick = entry;

                if (!brick.Hit && brick.Type > 0)
                {
                    if (colors.TryGetValue((int)brick.ColorNumber, out Color color))
                    {
                        brush.Color = color;
                        g.FillRectangle(brush, new Rectangle(brick.PosX, brick.PosY, brick.Width, brick.Height));
                    }
                }
            }
        }
Пример #16
0
        public bool Rotate270()
        {
            bool test = false;

            if (!_anchored)
            {
                if (_containerBoard == null)
                {
                    throw new NullContainerBoardException();
                }

                _containerBoard.RemovePieceFromCurPosition(this);

                IBrick[,] newShapeArray = new IBrick[_h, _w];
                IBrick[,] oldShapeArray = new IBrick[_w, _h];
                for (int row = 0; row < _h; row++)
                {
                    for (int column = 0; column < _w; column++)
                    {
                        newShapeArray[row, _w - column - 1] = _brickArr[column, row];
                        oldShapeArray[column, row]          = _brickArr[column, row];
                    }
                }

                int w = _w;
                int h = _h;
                this._w        = h;
                this._h        = w;
                this._brickArr = newShapeArray;

                if (_containerBoard.TestPieceOnPosition(this, this.X, this.Y))
                {
                    _containerBoard.PutPieceOnPosition(this, this.X, this.Y);
                }
                else
                {
                    this._w        = w;
                    this._h        = h;
                    this._brickArr = oldShapeArray;
                    _containerBoard.PutPieceOnPosition(this, this.X, this.Y);
                }
            }
            return(test);
        }
Пример #17
0
        public bool Rotate270()
        {
            bool test = false;

            if (!anchored)
            {
                if (containerBoard == null)
                {
                    throw new NullContainerBoardException();
                }

                containerBoard.RemovePieceFromCurrentPosition(this);

                IBrick[,] newShapeArray = new IBrick[height, width];
                IBrick[,] oldShapeArray = new IBrick[width, height];
                for (int row = 0; row < height; row++)
                {
                    for (int column = 0; column < width; column++)
                    {
                        newShapeArray[row, width - column - 1] = shapeArray[column, row];
                        oldShapeArray[column, row]             = shapeArray[column, row];
                    }
                }

                int w = width;
                int h = height;
                this.width      = h;
                this.height     = w;
                this.shapeArray = newShapeArray;

                if (containerBoard.TestPieceOnPosition(this, this.X, this.Y))
                {
                    containerBoard.PutPieceOnPosition(this, this.X, this.Y);
                }
                else
                {
                    this.width      = w;
                    this.height     = h;
                    this.shapeArray = oldShapeArray;
                    containerBoard.PutPieceOnPosition(this, this.X, this.Y);
                }
            }
            return(test);
        }
        private void DrawDetailImage(ListViewItem item, Rectangle bounds)
        {
            int index = item.ImageIndex;

            if (index < 0)
            {
                return;
            }

            Rectangle r = bounds;

            r.Size = imageList.ImageSize;
            r.Offset(2, (bounds.Height - r.Height) / 2);
            IBrick brick = DrawBrick("ImageBrick", r);

            brick.SetProperties(new object[, ] {
                { "Image", imageList.Images[index] },
                { "Sides", BorderSide.None }, { "BackColor", Color.Transparent }
            });
        }
Пример #19
0
 /// <summary>
 /// Raise the BrickBroke Event
 /// </summary>
 /// <param name="brick"></param>
 protected virtual void OnBrickBroke(IBrick brick)
 {
     BrickBroke?.Invoke(this, brick);
 }
Пример #20
0
 public void BricksDecrement(IBrick brick)
 {
     CurrentScoreCount = CurrentScoreCount + GetRewardForBrick(brick.GetBrickType());
     BricksCount--;
     CreateBonusObject(brick);
 }
Пример #21
0
 public Roof(IBrick brick)
 {
     _brick = brick;
 }
        private IBrick DrawBrick(string typeName, RectangleF rect)
        {
            IBrick brick = ps.CreateBrick(typeName);

            return(graph.DrawBrick(brick, rect));
        }
Пример #23
0
        private bool RemoveCompletedRows()
        {
            bool completed = false;
            int  row       = height - 1;

            while (row >= 0)
            {
                completed = true;
                for (int column = 0; column < width; column++)
                {
                    if (shapeArray[column, row] == null)
                    {
                        completed = false;
                        break;
                    }
                }

                if (completed)
                {
                    //presenter.HighlightCompletedRow(row);

                    IBrick[] removedBricks = new IBrick[width];
                    for (int column = 0; column < width; column++)
                    {
                        removedBricks[column] = shapeArray[column, row];
                    }

                    shape = null;
                    for (int innerRow = row; innerRow > 0; innerRow--)
                    {
                        for (int innerColumn = 0; innerColumn < width; innerColumn++)
                        {
                            shapeArray[innerColumn, innerRow]     = shapeArray[innerColumn, innerRow - 1];
                            shapeArray[innerColumn, innerRow - 1] = null;
                        }
                    }

                    score += 10 * level;
                    if (score > hiScore)
                    {
                        hiScore = score;
                    }
                    lines++;
                    level = 1 + (lines / 10);
                    presenter.UpdateScoreView(score, hiScore, lines, level, next);
                }
                else
                {
                    row--;
                }
            }

            if (presenter != null)
            {
                presenter.UpdateBoardView(GetStringFromShapeArray(), shapeArray, width, height);
            }

            if (completed)
            {
                RemoveCompletedRows();
            }
            return(completed);
        }
Пример #24
0
 public BrickHit(int number, IBrick brick)
 {
     Number = number;
     Brick  = brick;
 }
Пример #25
0
        private bool RemoveCompletedRows()
        {
            bool completed = false;
            int  row       = _h - 1;

            while (row >= 0)
            {
                completed = true;
                for (int column = 0; column < _w; column++)
                {
                    if (_brickArr[column, row] == null)
                    {
                        completed = false;
                        break;
                    }
                }

                if (completed)
                {
                    //presenter.HighlightCompletedRow(row);

                    IBrick[] removedBricks = new IBrick[_w];
                    for (int column = 0; column < _w; column++)
                    {
                        removedBricks[column] = _brickArr[column, row];
                    }

                    _shape = null;
                    for (int innerRow = row; innerRow > 0; innerRow--)
                    {
                        for (int innerColumn = 0; innerColumn < _w; innerColumn++)
                        {
                            _brickArr[innerColumn, innerRow]     = _brickArr[innerColumn, innerRow - 1];
                            _brickArr[innerColumn, innerRow - 1] = null;
                        }
                    }

                    _score += 10 * _level;
                    if (_score > _hiScore)
                    {
                        _hiScore = _score;
                    }
                    _lines++;
                    _level = 1 + (_lines / 10);
                    _presenter.UpdateScoreView(_score, _hiScore, _lines, _level, _next);
                }
                else
                {
                    row--;
                }
            }

            if (_presenter != null)
            {
                _presenter.UpdateBoardView(GetShapeString(), _brickArr, _w, _h);
            }

            if (completed)
            {
                RemoveCompletedRows();
            }
            return(completed);
        }
Пример #26
0
 private void Level_OnBrickBroke(object sender, IBrick e)
 {
     Score += scoreAddByBrokeBrick * e.SumOfLvls * levelNum;
 }
Пример #27
0
 /// <summary>
 /// Extention method for IBrick. Has all brick parts.
 /// </summary>
 /// <returns>Returns true if has all brick parts.</returns>
 private static bool HasAllParts(this IBrick checkedBrick)
 {
     return(checkedBrick.Parts.Count == GeneralConstants.MaxBrickParts);
 }
Пример #28
0
 private void Start()
 {
     _gameInteractor = GameInteractor.Instance;
     brick           = brickCreatorMap[BrickType]();
     _material       = GetComponent <Renderer>().material;
 }