コード例 #1
0
        public static GameModel StartNewGame()
        {
            var gameModel = new GameModel()
            {
                Id         = Guid.NewGuid(),
                StatusGame = StatusGameEnum.Iniciada
            };

            FileLib.CreateJsonFile(gameModel);

            return(gameModel);
        }
コード例 #2
0
        public IComandoResposta Exec(ComandoExecutarMovimento comando, Guid id)
        {
            var result = new MovementMessageModel();

            try
            {
                //Recupera o jogo
                var gameModel = FileLib.GetJsonFile(id);


                //Executa as validações do movimento
                ValidaMovimento(comando, gameModel, result);
                if (result.Invalid)
                {
                    return(new ComandoGenericoResposta(false, "Erro ao executar movimento.", result));
                }


                //Executa o movimento
                GameEngine.ExecutarMovimento(gameModel, comando.Position.X.ToInt32(0), comando.Position.Y.ToInt32(0), comando.Player);


                //Verifica o Termino da partida
                GameEngine.VerificarStatusPartida(gameModel);

                //Atualiza o jsonFile
                FileLib.CreateJsonFile(gameModel);


                result.PlayerTurn = gameModel.PlayerTurn;
                result.Winner     = gameModel.Winner;
                result.Status     = gameModel.StatusGame.GetDescription();


                return(new ComandoGenericoResposta(true, "Movimento executado com sucesso.", result));
            }
            catch (Exception ex)
            {
                result.AddNotification("", ex.Message);
                return(new ComandoGenericoResposta(false, $@"Erro ao executar movimento.", result));
            }
        }