Esempio n. 1
0
        public static LetterBag New(Random random)
        {
            var letters = MakeSet(random);
            var lb      = new LetterBag(random, letters);

            return(lb);
        }
Esempio n. 2
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);
        }