Example #1
0
        async Task SaveGame()
        {
            try
            {
                if (Helper.Confirm("Do you need to save the game?"))
                {
                    var index     = 0;
                    var playGames = new PlayGameModel(_selectedGameId);
                    Codes.ForEach(item =>
                    {
                        var codeType = GetCodeType(item, out var payload);
                        playGames.AddGameCode(index++, codeType, payload);
                    });
                    await _gameServiceRepository.CreateGamePlays(new Request <PlayGameModel>(playGames).SetToken());

                    MessageBox.Show("Saved");

                    if (!_useToSubmitDefault)
                    {
                        this.Close();
                    }
                }
            }
            catch (Exception exception)
            {
                new ExceptionHandler(exception);
            }
        }
Example #2
0
        private void LoadPlayGame(PlayGameModel playGameModel)
        {
            try
            {
                //if (!Helper.Confirm("Do you need to load the game"))
                //    return;

                ClearCode();
                var gameCodes = playGameModel.GameCodes.OrderBy(p => p.Order).ToList();

                for (var i = 0; i < gameCodes.Count; i++)
                {
                    var item  = gameCodes[i];
                    var movex = new UserControl();
                    if (item.CodeType == UcMoveForward.Identify)
                    {
                        movex = new UcMoveForward(this)
                                .SetPayload(item.Payload.ToObject <Statement>());
                        codeIndex += UcMoveForward.Height;
                    }
                    else if (item.CodeType == UcTurn.Identify)
                    {
                        movex      = new UcTurn(this).SetPayload(item.Payload.ToObject <Turn>());
                        codeIndex += UcTurn.Height;
                    }
                    else if (item.CodeType == UCLoop2.Identify)
                    {
                        movex      = new UCLoop2(this).SetPayload(item.Payload.ToObject <Loop2>());
                        codeIndex += UCLoop2.Height;
                    }
                    else if (new List <int> {
                        UcLoop.Identify, UcFunction.Identify
                    }.Contains(item.CodeType))
                    {
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                    movex.Location = new Point(10, codeIndex);
                    codeCore.Controls.Add(movex);
                    Codes.Add(movex);
                }
            }
            catch (Exception exception)
            {
                new ExceptionHandler(exception);
            }
        }
Example #3
0
        public async Task <IActionResult> CreateGamePlays([FromBody] PlayGameModel model)
        {
            try
            {
                _httpContext = HttpContext;
                var dto = _mapper.Map <PlayGameModel, PlayGameDto>(model);
                await _gameRunnerAppService.Create(Request(dto));

                return(Ok());
            }
            catch (Exception e)
            {
                return(HandleException(e));
            }
        }
Example #4
0
        private async Task LoadSolution()
        {
            try
            {
                this._correctSolution = await _gameServiceRepository.GetGameSolution(new Request <int>(_selectedGameId).SetToken());

                LoadPlayGame(_correctSolution);
            }
            catch (Exception exception)
            {
                if (!_useToSubmitDefault)
                {
                    new ExceptionHandler(exception);
                }
            }
        }