Beispiel #1
0
 public AIClient(string url, string name)
 {
     _botInfo = new BotUserInformation(name);
     _bot     = new ShootR.BotClient.BotClient(url, _botInfo);
     _tcs     = new TaskCompletionSource <bool>();
     Task     = _tcs.Task;
 }
Beispiel #2
0
        static async Task Main(string[] args)
        {
            var serverUrl      = "http://localhost:5000";
            var botInformation = new BotUserInformation("BotSample");
            var botClient      = new BotClient(serverUrl, botInformation);

            await botClient.ConnectAsync();

            var tcs = new TaskCompletionSource <bool>();


            botClient.OnPayload += (payload) =>
            {
            };


            await tcs.Task;
        }
Beispiel #3
0
        static async Task Main(string[] args)
        {
            var botName        = "SampleBot";
            var serverUrl      = "http://localhost:30567/";
            var botInformation = new BotUserInformation(botName);
            var botClient      = new BotClient(serverUrl, botInformation);

            await botClient.ConnectAsync();

            var tcs = new TaskCompletionSource <bool>();

            var startPosition = new Point(Console.CursorLeft, Console.CursorTop);
            var linesUsed     = 0;

            void WriteLine(string line)
            {
                Console.WriteLine(line);
                linesUsed += 1;
            }

            void BlankLine()
            {
                var blank = new string(' ', Console.BufferWidth - 1);

                Console.WriteLine(blank);
            }

            // Start moving forward
            var forward = true;
            await botClient.StartMovementAsync(Common.GameModel.Movement.Forward);

            var payloadCount = 0;

            botClient.OnUpdateAsync += async(UpdateContext context) =>
            {
                var payload = context.Payload;
                payloadCount += 1;

                // Move back to the start position
                Console.CursorLeft = startPosition.X;
                Console.CursorTop  = startPosition.Y;

                // Blank every line we've used so far
                for (var i = 0; i < linesUsed; i++)
                {
                    BlankLine();
                }

                linesUsed = 0;

                // Move back to the start position again
                Console.CursorLeft = startPosition.X;
                Console.CursorTop  = startPosition.Y;

                ShipData ourShip = null;
                WriteLine("Ships: ");
                foreach (var ship in payload.Ships)
                {
                    WriteLine($"{ship.Name} ({ship.Id}), Level {ship.Level}, {ship.Life.Health}/{ship.MaxLife}, ({ship.Movement.Position.X}, {ship.Movement.Position.Y}) moving ({ship.Movement.Velocity.X},{ship.Movement.Velocity.Y})");

                    if (ship.Name.Equals(botName))
                    {
                        ourShip = ship;
                    }
                }

                WriteLine($"Payloads: {payloadCount}");

                // Change directions when we're near the edge
                if (ourShip != null)
                {
                    if (ourShip.Movement.Position.X > 4500 || ourShip.Movement.Position.X < 500)
                    {
                        forward = !forward;
                        if (forward)
                        {
                            WriteLine("Stopping backward, starting forward.");
                            await botClient.StartAndStopMovementAsync(Common.GameModel.Movement.Backward, Common.GameModel.Movement.Forward);
                        }
                        else
                        {
                            WriteLine("Stopping forward, starting backward.");
                            await botClient.StartAndStopMovementAsync(Common.GameModel.Movement.Forward, Common.GameModel.Movement.Backward);
                        }
                    }
                }
            };


            await tcs.Task;
        }