예제 #1
0
        public void GameLiveCanIterateValidTest()
        {
            var world = new World(5, 5);

            // 1 0 0 0 0
            // 0 1 0 0 1
            // 0 0 1 0 0
            // 1 0 0 1 1
            // 0 0 0 1 0

            var points = new[]
            {
                new Point(0, 0), new Point(1, 1), new Point(1, 4),
                new Point(2, 2), new Point(2, 3),
                new Point(3, 0), new Point(3, 3), new Point(3, 4),
                new Point(4, 3)
            };

            foreach (var point in points)
            {
                world.Live.Add(point);
            }

            var game = new GameLifeProvider(world);

            game.IterateWorld();

            Assert.IsTrue(game.CanIterate);
        }
예제 #2
0
        public void GameLiveIterateEmptyTest()
        {
            var world = new World(5, 5);

            var game = new GameLifeProvider(world);

            game.IterateWorld();

            Assert.IsFalse(game.CanIterate);
        }
예제 #3
0
        public AutoIteratedGameWorld(GameLifeProvider gameLifeProvider, int intervalMs, String id)
        {
            _timer = new Timer();

            GameLifeProvider = gameLifeProvider;
            ID = id;

            _timer.Interval = intervalMs;
            _timer.Elapsed += _timer_Elapsed;
        }
예제 #4
0
        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            lock (GameLifeProvider)
            {
                GameLifeProvider.IterateWorld();

                OnUpdate?.Invoke(GameLifeProvider, ID);

                if (!GameLifeProvider.CanIterate)
                {
                    _timer.Enabled = false;
                }
            }
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        public void GameLiveIterateValidTest()
        {
            var world = new World(5, 5);

            // 1 0 0 0 0
            // 0 1 0 0 1
            // 0 0 1 0 0
            // 1 0 0 1 1
            // 0 0 0 1 0

            var points = new[]
            {
                new Point(0, 0), new Point(1, 1), new Point(1, 4),
                new Point(2, 2), new Point(2, 3),
                new Point(3, 0), new Point(3, 3), new Point(3, 4),
                new Point(4, 3)
            };

            foreach (var point in points)
            {
                world.SetAlive(point);
            }

            var game = new GameLifeProvider(world);

            game.IterateWorld();

            var iteratedWorld = game.GetWorld();

            //var result2 = GetStringWorld(iteratedWorld);

            var resultPoints = new[]
            {
                new Point(0, 0), new Point(0, 4),
                new Point(1, 0), new Point(1, 1), new Point(1, 2), new Point(1, 3), new Point(1, 4),
                new Point(2, 1), new Point(2, 2),
                new Point(4, 0), new Point(4, 3)
            };

            foreach (var point in resultPoints)
            {
                Assert.IsTrue(iteratedWorld.IsAlive(point));
            }
        }
예제 #7
0
        private void UpdateClientWorld(GameLifeProvider workProvider, String id)
        {
            var result = new GameState
            {
                Live = workProvider.GetWorld().Live.Select(x => new Models.Point()
                {
                    X = x.X, Y = x.Y
                }),
                IsStoped       = !workProvider.CanIterate,
                IterationCount = workProvider.IterationCount,
                GameStateError = EGameStateError.None,
            };

            var connections = _connectionMapping.GetConnections(id);

            foreach (var connection in connections)
            {
                _worldHub.Clients.Client(connection).SendAsync("WorldUpdate", result);
            }
        }
예제 #8
0
 private void UpdateAction(GameLifeProvider worldIterator, String id)
 {
     Update(id);
 }