Example #1
0
 public LevelContext(SnakePiece snakeHead,
                     LevelSettings settings,
                     Spawner<SnakePiece> tailSpawner,
                     Direction initialDirection,
                     Action restart,
                     Action nextLevel,
                     Predicate<Vector2> cellIsEmpty,
                     int lives)
 {
     this.cellIsEmpty = cellIsEmpty;
     this.settings = settings;
     this.nextLevel = nextLevel;
     this.tailSpawner = tailSpawner;
     this.snakeHead = snakeHead;
     this.restart = restart;
     Direction = initialDirection;
     Lives = lives;
 }
Example #2
0
File: Level.cs Project: gmich/Snake
        public Level(ILevelProvider levelProvider, Action next, Action restart)
        {
            this.levelProvider = levelProvider;
            grid = levelProvider.Grid;
            levelSettings = levelProvider.LevelSettings;
            adjustmentRules = AdjustmentRules.Default(levelProvider.LevelSettings.HorizontalTileCount - 1,
                                                           levelProvider.LevelSettings.VerticalTileCount - 1);

            context = new LevelContext(levelProvider.Head,
                                       levelProvider.LevelSettings,
                                       levelProvider.TailSpawner,
                                       Direction.Left,
                                       restart,
                                       next,
                                       location =>
                                       {
                                           bool intersects = grid[(int)location.X, (int)location.Y].Collide();
                                           elements.ForEach(element => intersects|= element.Intersects(location));
                                           return intersects;
                                       },
                                       levelProvider.LevelSettings.MaxLives);
            elements.Add(levelProvider.Head);
        }