コード例 #1
0
        static async Task Main(string[] args)
        {
            var botClient = new BotClient("http://localhost:30567", new BotUserInformation("Team Green"));

            Console.WriteLine("Starting connection. Press Ctrl-C to close.");
            await botClient.ConnectAsync();

            var lastSeenHealth = -1.0;

            botClient.OnUpdateAsync = async context =>
            {
                if (!context.YourShip.Movement.Moving.RotatingRight)
                {
                    await botClient.StartMovementAsync(Movement.RotatingRight);
                }

                var currentHealth = context.YourShip.Life.Health;

                if (lastSeenHealth == -1)
                {
                    lastSeenHealth = currentHealth;
                }

                if (lastSeenHealth != currentHealth)
                {
                    lastSeenHealth = currentHealth;
                    await botClient.SendMessage("LET ME LANDDDD!!");

                    await botClient.BoostAsync();
                }

                await botClient.FireAsync();
            };

            var tcs = new TaskCompletionSource <bool>();

            Console.CancelKeyPress += async(sender, a) =>
            {
                await botClient.DisconnectAsync();

                tcs.SetResult(true);
            };

            await tcs.Task;
        }
コード例 #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;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: anurse/HungRGames
        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;
        }