Exemple #1
0
        public Level(string levelFile)
        {
            _arena = Arena.FromFile(levelFile);
            _snakes = new Snake[2];
            _scores = new int[] { 0, 0 };

            _snakes[0] = new Snake(
                GetRandomPoint(_arena, null),
                SnakeDirection.Left,
                _arena.BackgroundColor,
                ConsoleColor.Yellow);

            _snakes[1] = new Snake(
                GetRandomPoint(_arena, null),
                SnakeDirection.Left,
                _arena.BackgroundColor,
                ConsoleColor.Red);
        }
Exemple #2
0
        private static Point GetRandomPoint(Arena arena, Snake otherSnake)
        {
            Point p = new Point()
            {
                X = rnd.Next(Arena.WindowWidth),
                Y = rnd.Next(Arena.WindowHeight)
            };

            while (arena.HasBlockAt(p))
            {
                p = new Point()
                {
                    X = rnd.Next(Arena.WindowWidth),
                    Y = rnd.Next(Arena.WindowHeight)
                };
            }

            return p;
        }
Exemple #3
0
        private static Point GenerateFoodPoint(Arena arena, Snake[] snakes)
        {
            Point p = new Point() { X = rnd.Next(Arena.WindowWidth), Y = rnd.Next(Arena.WindowHeight) };

            while (arena.HasBlockAt(p) ||
                   snakes.Any(sn => sn.BodyCollides(p)))
            {
                p = new Point() { X = rnd.Next(Arena.WindowWidth), Y = rnd.Next(Arena.WindowHeight) };
            }

            return p;
        }