Beispiel #1
0
        /// <summary>
        /// Returns a List of all of the currently activated GameMapTiles.
        /// </summary>
        /// <param name="snek"></param>
        /// <param name="food"></param>
        /// <returns></returns>
        public static List <Point> GetActiveTiles(Snekk snek, Food food)
        {
            var activeTiles = new List <Point>()
            {
                food.Location
            };
            var snakeTiles = snek.Body.Select(segment => segment.Location).ToList();

            activeTiles.AddRange(snakeTiles);

            return(activeTiles);
        }
Beispiel #2
0
        /// <summary>
        /// Handles the initialization of game-specific options.
        /// </summary>
        /// <param name="options">Contains the user's desired game options</param>
        public void Initialize(GameOptions options)
        {
            // Get the map size that will be used for the current game.
            mapSize = MapGenerator.SetMapSize(options.MapSize);

            // Configure the round timer and hook up the event handler.
            timer         = new RoundTimer(options.Difficulty);
            timer.OnTick += (source, e) => ExecuteCycle();

            // Set up collision detection.
            colDetector = new CollisionDetector(mapSize);

            // Initialize the random point and food generators.
            randomPointGenerator = RandomPointGenerator.Create(mapSize);
            foodGenerator        = new FoodGenerator(randomPointGenerator);

            // Initialize the game map.
            map = MapGenerator.GenerateMap(mapSize, options.TileStyle);

            // Place the snek and food at their initial locations.
            snek = new Snekk(MapGenerator.GenerateStartingPoint(mapSize));
            food = foodGenerator.Generate(snek.GetSegmentLocations());
        }