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
         {
         }
     }
 }
Beispiel #3
0
 public SimpleGameEngine
 (
     IGameEngineConfig config,
     ILoggingService loggingService,
     SimpleGameServer server,
     InternalWebSocketClient webSocketClient
 )
 {
     LoggingService = loggingService;
     Config         = config;
     Server         = server;
     Client         = webSocketClient;
 }
        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);
        }
Beispiel #5
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);
                }
            });
        }
        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);
            }
        }
        public override void ApplyTo(SimpleGameServer server)
        {
            Snakes = server.GetObjectsByName("Snake").Where(@object => @object.ObjectName == "SnakeHead").ToList();
            Apples = server.GetObjectsByName("Apple").ToList();

            Snakes.ForEach(snake =>
            {
                SnakeProperties properties = (SnakeProperties)snake.ObjectProperties;
                Apples.ForEach(apple =>
                {
                    if (apple.Position == properties.Head.Position)
                    {
                        LoggingService.LogMessage($"Player picked up an Apple.{snake.Owner.ClientHashCode}");
                        server.RemoveObject(apple);
                        properties.Length += 1;
                        properties.Score  += 1;
                        if (server.TickInterval - 20 > 0)
                        {
                            server.SetTickInterval(server.TickInterval - 20);
                        }
                    }
                });
            });
        }
Beispiel #8
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;
            });
        }
 public ServerOnlyRunningStrategy(SimpleGameServer server, IEnumerable <GameLogicBehaviour> behavioues) : base(server, behavioues)
 {
 }
Beispiel #10
0
 protected RunningStrategy(SimpleGameServer server, IEnumerable <GameLogicBehaviour> behavioues)
 {
 }
Beispiel #11
0
 public abstract void ApplyTo(SimpleGameServer server);
Beispiel #12
0
 public ConsoleRenderer(SimpleGameServer server, ILoggingService loggingService)
 {
     LoggingService = loggingService;
     Server         = server;
 }
 public CreateObjectCommand(SimpleGameServer server, CreateObjectCommandParameters parameters) : base(server)
 {
     Parameters = parameters;
 }
Beispiel #14
0
 protected Command(SimpleGameServer server) => Server = server;
Beispiel #15
0
 public RegisterConnectionCommand(SimpleGameServer server, RegisterConnectionCommandParameters parameters) : base(server)
 {
     Parameters = parameters;
 }
 public InternalWebSocketClient(SimpleGameServer server)
 {
     Server = server;
 }
Beispiel #17
0
 public MovePlayerCommand(SimpleGameServer server, MovePlayerCommandParameters parameters) : base(server)
 {
     Parameters = parameters;
 }