Exemplo n.º 1
0
 internal DungeonLevel SetCell(DungeonCell cell)
 {
     return(new DungeonLevel(
                Level,
                cells.ToDictionary(
                    k => k.Key,
                    v => v.Value.Position == cell.Position ? cell : v.Value
                    )
                ));
 }
Exemplo n.º 2
0
        public Maybe <(Player, DungeonCell)> Action(DungeonCell cell)
        {
            if ((!cell.Occupant.HasValue && cell.LetterTile.HasValue) || (cell.Occupant.HasValue && (cell.Occupant.Value is UpStairs || cell.Occupant.Value is DownStairs)))
            {
                return(new Player(cell.Position, LetterInventory, BlankTileOfYendor), cell);
            }

            if (cell.Occupant.HasValue && cell.Occupant.Value is LetterChest || cell.Occupant.Value is BlankTileOfYendor)
            {
                var occupant = cell.Occupant.Value;
                var player   = occupant.InteractWithPlayer(this);

                cell = cell.SetOccupant(new Rocks());

                return(player, cell);
            }

            return(Maybe.None <(Player, DungeonCell)>());
        }
Exemplo n.º 3
0
        private void CheckAdjacency(DungeonCell sc, Point dir, List <DungeonCell> allLetterCells)
        {
            var newPos = sc.Position + dir;
            var cell   = GetCell(newPos);

            if (!cell.HasValue || !cell.Value.LetterTile.HasValue)
            {
                return;
            }
            if (!allLetterCells.Contains(cell.Value))
            {
                return;
            }
            allLetterCells.Remove(cell.Value);
            CheckAdjacency(cell.Value, new Point(0, -1), allLetterCells);
            CheckAdjacency(cell.Value, new Point(0, 1), allLetterCells);
            CheckAdjacency(cell.Value, new Point(-1, 0), allLetterCells);
            CheckAdjacency(cell.Value, new Point(1, 0), allLetterCells);
        }
Exemplo n.º 4
0
 internal Maybe <TilePlacer> Move(DungeonCell cell)
 {
     return(new TilePlacer(cell.Position, Player, TilePlacementDir, WordEntry));
 }
Exemplo n.º 5
0
        public static DungeonLevel New(int level, Random random)
        {
            var lb = LetterBag.New(random);

            var cells = Enumerable.Range(0, Constants.LevelDim)
                        .SelectMany(row => Enumerable
                                    .Range(0, Constants.LevelDim)
                                    .Select(col => new Point(col, row))
                                    .Select(pt => new
            {
                Point = pt,
                Cell  = DungeonCell.Create(pt, random)
            })
                                    )
                        .ToDictionary(
                k => k.Point,
                v => v.Cell
                );

            var mid = Constants.LevelDim / 2;

            if (level == 1)
            {
                var col = mid - 3;
                foreach (var c in "nothing")
                {
                    var pos  = new Point(col, mid);
                    var cell = cells[pos];
                    // this will work, its okay
                    cell       = cell.LayTile(new LetterTile(c)).Value;
                    cells[pos] = cell;

                    if (c == 'h')
                    {
                        var pos2  = new Point(col, mid - 1);
                        var cell2 = cells[pos2];
                        var(r, t)   = lb.PullTiles(20);
                        lb          = r;
                        cell2       = cell2.SetOccupant(new LetterChest(t));
                        cells[pos2] = cell2;
                    }

                    col++;
                }
            }

            if (level == Constants.NumberOfLevels)
            {
                var pos  = new Point(mid, mid);
                var cell = cells[pos];
                // this will work, its okay
                cell       = cell.SetOccupant(new BlankTileOfYendor());
                cells[pos] = cell;
            }

            var d = new DungeonLevel(level, cells);


            for (int i = 0; i < 24; i++)
            {
                var rcell = cells.Values
                            .Where(n => !n.Occupant.HasValue)
                            .Where(n => n.Position.X <4 || n.Position.X> (Constants.LevelDim - 4) || n.Position.Y <4 || n.Position.Y> (Constants.LevelDim - 4))
                            .OrderBy(n => random.Next()).First();
                rcell = rcell.SetOccupant(new Rocks());
                d     = d.SetCell(rcell);
            }

            for (int i = 0; i < 4; i++)
            {
                var rcell = cells.Values.Where(n => !n.Occupant.HasValue)
                            .Where(n => n.Position.X <4 || n.Position.X> (Constants.LevelDim - 4) || n.Position.Y <4 || n.Position.Y> (Constants.LevelDim - 4))
                            .OrderBy(n => random.Next()).First();

                var(r, t) = lb.PullTiles(random.Next(10, 20));
                lb        = r;
                rcell     = rcell.SetOccupant(new LetterChest(t));
                d         = d.SetCell(rcell);
            }


            return(d);
        }
Exemplo n.º 6
0
 public Dungeon ReplaceCell(DungeonCell cell)
 {
     return(new Dungeon(
                ActiveLevel.SetCell(cell),
                levels));
 }