public override void ApplyTo(SimpleGameServer server)
 {
     while (server.GetCountByObjectName("Obstacle") < ObstaclesCount)
     {
         LoggingService.LogMessage("Spawning Obstacles.");
         Vector2D obstaclePosition = new Vector2D(x: random.Next(0, 60) * 32, y: random.Next(0, 32) * 32);
         if (!server.GetObjectAt(obstaclePosition).Any())
         {
             GameObject apple = GameObject.Create
                                (
                 objectName: "Obstacle",
                 playable: false,
                 isSolid: true,
                 bitmapName: "obstacle.png",
                 position: obstaclePosition,
                 velocity: new Vector2D(x: 0, y: 0),
                 roration: 0,
                 scale: 1,
                 objectTypeName: "Obstacle",
                 owner: null,
                 properties: null
                                );
             server.AddObject(apple);
         }
         else
         {
         }
     }
 }
 public override void ApplyTo(SimpleGameServer server)
 {
     while (server.GetCountByObjectName("Apple") < AppleLimit)
     {
         Vector2D applePosition = new Vector2D(x: random.Next(0, 60) * 32, y: random.Next(0, 32) * 32);
         LoggingService.LogMessage("Spawning Apple(s).");
         if (!server.GetObjectAt(applePosition).Any())
         {
             GameObject apple = GameObject.Create
                                (
                 objectName: "Test",
                 playable: false,
                 isSolid: false,
                 bitmapName: "apple.png",
                 position: applePosition,
                 velocity: new Vector2D(x: 0, y: 0),
                 roration: 0,
                 scale: 1,
                 objectTypeName: "Apple",
                 owner: null,
                 properties: new AppleProperties()
                                );
             server.AddObject(apple);
         }
     }
 }
        public static void CreatePlayer(SimpleGameServer server, Engine.Network.Client client)
        {
            GameObject player = GameObject.Create
                                (
                objectName: "SnakeHead",
                playable: true,
                isSolid: true,
                bitmapName: "snake.png",
                position: new Vector2D(x: random.Next(0, 30) * 32, y: random.Next(0, 30) * 32),
                velocity: new Vector2D(x: 32, y: 0),
                roration: 0,
                scale: 1,
                objectTypeName: "Snake",
                owner: client,
                properties: null
                                );

            player.ObjectProperties = new SnakeProperties(player);
            server.AddObject(player);
        }
        public override void ApplyTo(SimpleGameServer server)
        {
            while (server.GetCountByObjectName("Snake") < SnakeLimit)
            {
                GameObject snake = GameObject.Create
                                   (
                    objectName: "SnakeHead",
                    playable: false,
                    isSolid: true,
                    bitmapName: "snake.png",
                    position: new Vector2D(x: random.Next(0, 60) * 32, y: random.Next(0, 32) * 32),
                    velocity: new Vector2D(x: 32, y: 0),
                    roration: 0,
                    scale: 1,
                    objectTypeName: "Snake",
                    owner: null,
                    properties: null
                                   );

                snake.ObjectProperties = new SnakeProperties(snake);
                server.AddObject(snake);
            }
        }
Esempio n. 5
0
        public override void ApplyTo(SimpleGameServer server)
        {
            Snakes = server
                     .GetObjectsByName("Snake")
                     .Where(@object => @object.ObjectName == "SnakeHead")
                     .ToList();

            Snakes.ForEach(snake =>
            {
                server.LoggingService.LogMessage("Moving snake");
                SnakeProperties snakeProperties = (SnakeProperties)snake.ObjectProperties;

                if (snakeProperties.Tail.Any())
                {
                    server.RemoveObject(snakeProperties.Tail.Last.Value);
                    snakeProperties.Tail.RemoveLast();
                }

                while (snakeProperties.Tail.Count < snakeProperties.Length)
                {
                    GameObject copy = snakeProperties.Head.Copy();
                    snakeProperties.Tail.AddFirst(copy);
                    server.AddObject(copy);
                }
                if (!snake.Playable)
                {
                    Vector2D newVelocity = new Vector2D(random.Next(-1, 1) * 32, random.Next(-1, 1) * 32);
                    if (AvailableDirections[snakeProperties.Head.Velocity].Contains(newVelocity))
                    {
                        snakeProperties.Head.Velocity = newVelocity;
                    }
                }

                snakeProperties.Head.Position += snakeProperties.Head.Velocity;
            });
        }