Example #1
0
        // GET api/values
        public object Get(CCRequestModel request)
        {
            var name = new NameClass();

            name.name = "Bob";
            return(name);
        }
Example #2
0
        ////// GET api/values/5
        //public CCResponseModel Get(CCRequestModel request)
        //{
        //    return new CCResponseModel(5,"Testing", 'y', true);
        //}


        // POST api/values
        /// <summary>
        /// Post a request to the service and generate a response
        /// </summary>
        /// <param name="request">A string containing the request</param>
        /// <returns></returns>
        public object Post([FromBody] CCRequestModel request)
        {
            string response = "";

            try
            {
                //response.text = request.request;
                if (request.MsgId == 1)
                {
                    var name = new NameClass();
                    name.name = "Bob";

                    return(name);
                }
                if (request.MsgId == 2)
                {
                    var radarResult = JsonConvert.DeserializeObject <dynamic>(request.MsgData);

                    var myLocation    = radarResult.yourLocation;
                    var enemyLocation = radarResult.enemies[0].location;


                    var commandList = new List <CommandClass>();
                    var command     = new CommandClass();

                    if (Math.Abs(FindRotationalToEnemy(radarResult)) > 15)
                    {
                        BuildCommandList(ref commandList, (int)Commands.RotateLeft, 100);
                    }
                    else
                    {
                        BuildCommandList(ref commandList, (int)Commands.FireShell, 200);
                        BuildCommandList(ref commandList, (int)Commands.FireShell, 200);
                        BuildCommandList(ref commandList, (int)Commands.FireShell, 200);
                        //   BuildCommandList(ref commandList, (int)Commands.RotateRight, 200);
                        if (FindDistance(radarResult) > 20)
                        {
                            BuildCommandList(ref commandList, (int)Commands.MoveForward, 500);
                        }
                        else
                        {
                            BuildCommandList(ref commandList, (int)Commands.MoveBackwards, 600);
                        }
                    }
                    return(commandList);
                }
            }
            catch (Exception ex)
            {
                return(ex);
            }
            return(response);
        }