public async Task<Game> LoadGameAsync(string id) { var gameSave = await DataProvider.LoadGameAsync(id); IFieldGenerator generator = FieldGeneratorFactory.Create(gameSave.GeneratorParams); DateTime startTime = DateTime.UtcNow.Subtract(gameSave.Timer); var game = new Game(generator, gameSave.Width, gameSave.Height, startTime); var moveResults = new List<MoveResult>(); foreach (var move in gameSave.PlayerMoves) { moveResults.Add(game.MakeMove(move)); } return game; }
public IActionResult Start(StartGameModel model) { try { var generatorParams = new FieldGeneratorParams(SeedGenerator.GenerateSeed(), model.MinesCount); IFieldGenerator fieldGenerator = FieldGeneratorFactory.Create(generatorParams); var game = new Game(fieldGenerator, model.Width, model.Height); Guid gameKey = Guid.NewGuid(); GameStorage.AddGame(gameKey, game); return(Ok(new GameModelBase { GameKey = gameKey })); } catch (Exception ex) { Log.Error(ex, "Couldn't create the game with params {@Model}", model); return(Error("An error occured while creating the game")); } }