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); }
protected bool IsPieceOutsideOfGrid(PuzzlePiece piece) { if (IsPieceInsideOfGrid(piece)) { return(false); } if (StaticHelper.RectangleIntersects(piece.XIndex, piece.YIndex, piece.Width, piece.Height, 0, 0, gridWidth, gridHeight)) { //dodatnu proveru za polja koja se seku..ako su polja koja se seku empty odobriti int x; int y; int width; int height; StaticHelper.GetIntersectionData(piece.XIndex, piece.YIndex, piece.Width, piece.Height, 0, 0, gridWidth, gridHeight, out x, out y, out width, out height); if (height == 0 || width == 0) { return(true); } int minPieceX = x - piece.XIndex; int minPieceY = y - piece.YIndex; FillType puzzleFill; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { puzzleFill = piece.Matrix[i + minPieceY, j + minPieceX].Fill; if (puzzleFill != FillType.Empty) { return(false); } } } } return(true); }