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 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
         {
         }
     }
 }
Exemple #3
0
        public override void ApplyTo(SimpleGameServer server)
        {
            Snakes = server
                     .GetObjectsByName("Snake")
                     .Where(@object => @object.ObjectName == "SnakeHead")
                     .ToList();

            Snakes.ForEach(snake =>
            {
                SnakeProperties props = (SnakeProperties)snake.ObjectProperties;
                bool colided          = server.GetObjectAt(props.Head.Position).Any(obj => obj.IsSolid && obj != snake);
                if (colided)
                {
                    LoggingService.LogMessage($"Snake {snake.Owner.ClientHashCode} colided with an object.");

                    ((SnakeProperties)snake.ObjectProperties).Tail
                    .ToList()
                    .ForEach(tailBit => server.RemoveObject(tailBit));
                    server.RemoveObject(snake);
                }
            });
        }