public MainWindowViewModel() { LoadLevels(); menu = new MenuScreenViewModel(this); currentView = menu; CellStateRules.Init(); }
protected bool IsPieceOverlaping(PuzzlePiece p1, PuzzlePiece p2) { int x; int y; int width; int height; if (StaticHelper.RectangleIntersects(p1.XIndex, p1.YIndex, p1.Width, p1.Height, p2.XIndex, p2.YIndex, p2.Width, p2.Height)) { StaticHelper.GetIntersectionData(p1.XIndex, p1.YIndex, p1.Width, p1.Height, p2.XIndex, p2.YIndex, p2.Width, p2.Height, out x, out y, out width, out height); if (height == 0 || width == 0) { return(false); } int minPieceX = x - p2.XIndex; int minPieceY = y - p2.YIndex; FillType levelCellFill; FillType pieceCellFill; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { levelCellFill = levelMatrix[y + gridHeight + i, x + gridWidth + j].Fill; pieceCellFill = p2.Matrix[i + minPieceY, j + minPieceX].Fill; if (levelCellFill == FillType.Empty || pieceCellFill == FillType.Empty) { continue; } if (levelCellFill == FillType.Full && pieceCellFill != FillType.Empty) { return(true); } if (pieceCellFill == FillType.Full && levelCellFill != FillType.Empty) { return(true); } if (CellStateRules.IsIntersecting(levelCellFill, pieceCellFill)) { return(true); } } } } return(false); }
public void AddPuzzlePieceTolLevelMatrix(PuzzlePiece piece) { int xIndex = piece.XIndex + gridWidth; int yIndex = piece.YIndex + gridHeight; Field[,] pieceMatrix = piece.Matrix; FillType pieceCellFill; FillType levelCellFill; FillType newFill = FillType.Empty; for (int y = 0; y < piece.Height; y++) { for (int x = 0; x < piece.Width; x++) { levelCellFill = levelMatrix[yIndex + y, xIndex + x].Fill; pieceCellFill = piece.Matrix[y, x].Fill; if (levelCellFill == FillType.Empty) { newFill = pieceCellFill; } else if (pieceCellFill == FillType.Empty) { newFill = levelCellFill; } else { if (pieceCellFill != FillType.Empty) { newFill = CellStateRules.GetGridFillAfterAddingPiece(levelCellFill, pieceCellFill); } } if (newFill != FillType.Invalid) { levelMatrix[yIndex + y, xIndex + x].Fill = newFill; } } } }
protected void RemovePuzzlePieceFromLevelMatrix(PuzzlePiece piece) { Field[,] pieceMatrix = piece.Matrix; FillType pieceCellFill; FillType levelCellFill; FillType newFill = FillType.Empty; for (int y = 0; y < piece.Height; y++) { for (int x = 0; x < piece.Width; x++) { pieceCellFill = piece.Matrix[y, x].Fill; levelCellFill = levelMatrix[piece.YIndex + y + gridHeight, piece.XIndex + x + gridWidth].Fill; if (levelCellFill == FillType.Empty) { continue; } if (pieceCellFill == FillType.Full) { newFill = FillType.Empty; } else { newFill = CellStateRules.GetGridFillAfterRemovingPiece(levelCellFill, pieceCellFill); } if (newFill != FillType.Invalid) { levelMatrix[piece.YIndex + y + gridHeight, piece.XIndex + x + gridWidth].Fill = newFill; } } } }
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); }