/// <summary> /// Получить мир /// </summary> /// <param name="id">Ключ мира</param> /// <param name="worldConnection">Мир</param> /// <returns></returns> public Boolean Get(String id, out AutoIteratedGameWorld worldConnection) { KeyValuePair <AutoIteratedGameWorld, DateTime> worldConnectionResult; if (_worlds.TryGetValue(id, out worldConnectionResult)) { worldConnection = worldConnectionResult.Key; } else { worldConnection = null; } return(worldConnection != null); }
/// <summary> /// Добавить новый мир /// </summary> /// <param name="id">Ключ мира</param> /// <param name="live">Список живых клеток</param> /// <returns></returns> public AutoIteratedGameWorld Add(String id, IEnumerable <GameLife.Core.Point> live) { Actualize(); var world = new World(new HashSet <GameLife.Core.Point>(live), _width, _height); var gameWorld = new GameLifeProvider(world); var worldConnection = new AutoIteratedGameWorld(gameWorld, _worldUpdateIntervalMs, id); if (!Add(worldConnection)) { throw new InvalidOperationException(); } return(worldConnection); }
/// <summary> /// Добавить новый мир /// </summary> /// <param name="world">Мир</param> /// <returns></returns> public Boolean Add(AutoIteratedGameWorld world) { Boolean result; if (_worlds.ContainsKey(world.ID)) { result = false; } else { _worlds.AddOrUpdate(world.ID, new KeyValuePair <AutoIteratedGameWorld, DateTime>(world, DateTime.Now), (o1, o2) => o2); world.OnUpdate += UpdateAction; result = true; } return(result); }