Beispiel #1
0
        /// <summary>Renders a cell without taking the adjacent cells into account.</summary>
        /// <param name="g">Graphics object to render onto.</param>
        /// <param name="x">X co-ordinate of the cell to render.</param>
        /// <param name="y">Y co-ordinate of the cell to render.</param>
        private void renderCellAsPartOfCompleteRender(Graphics g, int x, int y)
        {
            if (x < 0 || x >= _level.Width || y < 0 || y >= _level.Height)
            {
                return;
            }

            if (_level.Cell(x, y) != SokobanCell.Wall)
            {
                g.InterpolationMode = InterpolationMode.High;
            }

            // Draw level
            switch (_level.Cell(x, y))
            {
            case SokobanCell.Wall:
                g.InterpolationMode = InterpolationMode.Default;
                DrawCell(g, x, y, SokobanImage.Wall);
                break;

            case SokobanCell.Target:
                DrawCell(g, x, y, SokobanImage.Target);
                break;

            case SokobanCell.PieceOnTarget:
                DrawCell(g, x, y, SokobanImage.TargetUnderPiece);
                break;
            }
            // Draw piece
            switch (_level.Cell(x, y))
            {
            case SokobanCell.Piece:
                DrawCell(g, x, y, SokobanImage.Piece);
                break;

            case SokobanCell.PieceOnTarget:
                DrawCell(g, x, y, SokobanImage.PieceOnTarget);
                break;
            }
            // Draw Sokoban
            if (x == _level.SokobanPos.X && y == _level.SokobanPos.Y)
            {
                DrawCell(g, x, y, SokobanImage.Sokoban);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Examines a cell to see if the length of the path to it can be shortened (or
 /// whether the cell has even been discovered yet).
 /// </summary>
 /// <param name="pos">Cell under consideration.</param>
 /// <param name="pivot">Becomes the new predecessor if it makes the path length
 /// shorter.</param>
 /// <param name="ignorePieces">If true, only walls are considered obstacles.</param>
 /// <param name="queue">The queue to insert newly discovered cells into.</param>
 private void examine(Point pos, Point pivot, bool ignorePieces, Queue <Point> queue)
 {
     if (pos.X < 0 || pos.X >= _level.Width || pos.Y < 0 || pos.Y >= _level.Height)
     {
         return;
     }
     if ((_level.IsFree(pos) || (ignorePieces && _level.Cell(pos) != SokobanCell.Wall)) &&
         _pathLength[pos.Y * _level.Width + pos.X] == 0)
     {
         if (pos.X > 0 && pos.X < _level.Width - 1 && pos.Y > 0 && pos.Y < _level.Height - 1)
         {
             queue.Enqueue(pos);
         }
         _pathLength[pos.Y * _level.Width + pos.X]  = _pathLength[pivot.Y * _level.Width + pivot.X] + 1;
         _predecessor[pos.Y * _level.Width + pos.X] = pivot;
     }
 }