Beispiel #1
0
        public void Init(double width = 0, double height = 0)
        {
            drawings.Clear();

            if (width != 0 && height != 0)
            {
                CalculateCellSize(width, height);
            }

            levelMatrix = StaticHelper.GetEmptyMatrix(gridWidth * 3, gridHeight * 3);
            grid        = new Grid(this, gridWidth, gridHeight);
            Height      = (gridHeight * 3) * cellSize;
            Width       = (gridWidth * 3) * cellSize;
            border      = new GameBorder(this.height, this.width);

            drawings.Add(grid);
            drawings.Add(border);

            foreach (PuzzlePiece puzzlePiece in puzzlePieces)
            {
                PlacePuzzlePieceOutOfGrid(puzzlePiece);
                puzzlePiece.isInitialised = true;
            }

            //PrintLevelMatrix();
        }
        private CombinedPuzzlePiece CreateUnionPuzzlePiece(PuzzlePiece p1, PuzzlePiece p2)
        {
            CombinedPuzzlePiece retVal = null;

            int minX, minY, maxX, maxY;

            if (p1.XIndex < p2.XIndex)
            {
                minX = p1.XIndex;
            }
            else
            {
                minX = p2.XIndex;
            }

            if (p1.YIndex < p2.YIndex)
            {
                minY = p1.YIndex;
            }
            else
            {
                minY = p2.YIndex;
            }

            if (p1.XIndex + p1.Width > p2.XIndex + p2.Width)
            {
                maxX = p1.XIndex + p1.Width;
            }
            else
            {
                maxX = p2.XIndex + p2.Width;
            }

            if (p1.YIndex + p1.Height > p2.YIndex + p2.Height)
            {
                maxY = p1.YIndex + p1.Height;
            }
            else
            {
                maxY = p2.YIndex + p2.Height;
            }


            Field[,] newPieceMatrix = StaticHelper.GetEmptyMatrix(maxX - minX, maxY - minY);
            FillType fill1;
            FillType fill2;
            FillType newFill = FillType.Empty;

            for (int y = 0; y < maxY - minY; y++)
            {
                for (int x = 0; x < maxX - minX; x++)
                {
                    fill1 = GetPieceFillInWorld(x + minX, y + minY, p1);
                    fill2 = GetPieceFillInWorld(x + minX, y + minY, p2);

                    if (fill1 == FillType.Full || fill2 == FillType.Full)
                    {
                        newFill = FillType.Full;
                    }
                    else if (fill1 != FillType.Empty && fill2 != FillType.Empty)
                    {
                        newFill = CellStateRules.GetUnion(fill1, fill2);
                    }
                    else if (fill1 == FillType.Empty)
                    {
                        newFill = fill2;
                    }
                    else if (fill2 == FillType.Empty)
                    {
                        newFill = fill1;
                    }

                    newPieceMatrix[y, x].Fill = newFill;
                }
            }

            LinearGradientBrush myBrush = new LinearGradientBrush();

            myBrush.GradientStops.Add(new GradientStop(((SolidColorBrush)p1.Brush).Color, 0.0));
            myBrush.GradientStops.Add(new GradientStop(((SolidColorBrush)p2.Brush).Color, 1.0));

            retVal        = new CombinedPuzzlePiece(newPieceMatrix, myBrush);
            retVal.XIndex = minX;
            retVal.YIndex = minY;
            retVal.Piece1 = p1;
            retVal.Piece2 = p2;


            return(retVal);
        }