Пример #1
0
        private void MakeBasicMap(string[] lines)
        {
            var powerPills = new List <Location>();

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    var c = lines[y][x];

                    CellType piece;
                    Boolean  throughSpace = false;
                    switch (c)
                    {
                    case '.':
                        piece = CellType.Pill;
                        _initialPills++;
                        break;

                    case ',':
                        throughSpace = true;
                        piece        = CellType.Pill;
                        _initialPills++;
                        break;

                    case '*':
                        piece = CellType.PowerPill;
                        powerPills.Add(new Location(x, y));
                        break;

                    case '=':
                        throughSpace = true;
                        piece        = CellType.PlayArea;
                        break;

                    default:
                        piece = c switch
                        {
                            ' ' => CellType.PlayArea,
                            'X' => CellType.SingleWall,
                            '#' => CellType.DoubleWall,
                            '+' => CellType.DeadSpace,
                            'G' => CellType.GhostWall,
                            '-' => CellType.Door,
                            'T' => CellType.Tunnel,
                            _ => throw new NotImplementedException()
                        };
                        break;
                    }

                    _map[x, y] = new MapCellDetail(this, x, y, piece, throughSpace, MapDisplayPiece.Blank);
                }
            }

            _initialPowerPills = powerPills;
        }
Пример #2
0
        public MapDisplayPiece FindBoardPiece(MapCellDetail board)
        {
            foreach (var pattern in _patterns)
            {
                if (pattern.DoCellsMatchPattern(board))
                {
                    return(pattern.MapDisplayPiece);
                }
            }

#if DEBUG
            // Failed to match - loop through again to help debug layout

            foreach (var pattern in _patterns)
            {
                if (pattern.DoCellsMatchPattern(board))
                {
                    return(pattern.MapDisplayPiece);
                }
            }
#endif

            throw new Exception($"No matching board piece pattern @ c{board.X},{board.Y}");
        }