public HttpResponseMessage AddGame()
        {
            gameLogs = new GameLogs();

            try
            {
                frameList = gameLogs.AddNewGame();
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
            }

            var responseMessage = Request.CreateResponse(HttpStatusCode.Created, frameList);

            for (var i = 0; i < Request.RequestUri.Segments.Length - 1; i++)
            {
                request += Request.RequestUri.Segments[i];
            }

            response = Request.RequestUri.Scheme + "://" + Request.RequestUri.Authority + request + frameList.Id;

            responseMessage.Headers.Location = new Uri(response);
            return(responseMessage);
        }
        public HttpResponseMessage AddFrame(string id, [FromBody] Rolls frame)
        {
            gameLogic = new GameLogic();
            gameLogs  = new GameLogs();

            if (frame == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No Input"));
            }
            frameList = gameLogs.GameId(id);
            if (frameList == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Please create a game first!"));
            }

            try
            {
                gameLogic.ControllInput(frame);
                frameList.RollsList.Add(frame);
                AddRollsFrame(frame);
            }

            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
            }
            gameLogs.SaveLogs();

            return(Request.CreateResponse(HttpStatusCode.Created, frameList));
        }
Esempio n. 3
0
        public int Spare(int i, FrameList frameList)
        {
            try
            {
                score += frameList.RollsList[i + 1].RollOne;
            }
            catch (Exception e)
            {
                return(score);
            }

            return(score);
        }
Esempio n. 4
0
        public int Strike(int i, FrameList frameList)
        {
            try
            {
                score += frameList.RollsList[i + 1].RollOne + frameList.RollsList[i + 1].RollTwo + frameList.RollsList[i + 2].RollOne + frameList.RollsList[i + 2].RollTwo;
            }
            catch (Exception e)
            {
                return(score);
            }

            return(score);
        }