예제 #1
0
 public void ResetPlayer()
 {
     liveState = LiveState.ALIVE;
     controll.Reset();
     shoot.Reset();
     collector.Reset();
 }
예제 #2
0
 public ClientState(Guid clientId, LiveState state)
 {
     Id         = LiveGuid.NewGuid();
     ClientId   = clientId;
     StatusDate = DateTime.Now;
     Status     = state;
 }
예제 #3
0
        public override void Construct(Vector3 spawnPosition, float rotation, CampaignSection section)
        {
            base.Construct(spawnPosition, rotation, section);

            this._state     = AlienState.ALIVE;
            this._livestate = LiveState.ROAMING;
            this._health    = 250;

            this._mesh       = new SkinnedMesh();
            this._mesh.Model = AssetLoader.mdl_alien4;

            this._aplayer = new DurationBasedAnimator(_mesh.SkinningData, _mesh.SkinningData.AnimationClips["Take 001"], null);

            this._aplayer.AddAnimationPackage = AssetLoader.ani_alien4;
            this._aplayer.StartClip(Animation_States.moving);

            this.VerticalOffset = new Vector3(0, 0.8f, 0);
            this.ScaleMatrix    = Matrix.CreateScale(0.6f);

            UpdateAnimations(0);
            UpdateMajorTransform();

            Globals.gameInstance.sceneGraph.Setup(_mesh);
            this._modelReceipt = Globals.gameInstance.sceneGraph.Add(_mesh);

            _collisionRectangle = new RectangleF(
                _position.X - bBWidth,
                _position.Z - bBWidth, bBWidth * 2, bBWidth * 2);
        }
예제 #4
0
 public ClientState(Guid id, LiveState status, DateTime statusDate, Guid?encounterId, Guid?indexClientId) : base(id)
 {
     Status        = status;
     StatusDate    = statusDate;
     EncounterId   = encounterId;
     IndexClientId = indexClientId;
 }
예제 #5
0
        public override void Construct(Vector3 spawnPosition, float rotation, CampaignSection section)
        {
            base.Construct(spawnPosition, rotation, section);

            this._state = AlienState.ALIVE;
            this._livestate = LiveState.ROAMING;
            this._health = 90;

            this._mesh = new SkinnedMesh();
            this._mesh.Model = AssetLoader.mdl_alien1;

            this._aplayer = new DurationBasedAnimator(_mesh.SkinningData, _mesh.SkinningData.AnimationClips["Take 001"], null);

            this._aplayer.AddAnimationPackage = AssetLoader.ani_alien1;
            this._aplayer.StartClip(Animation_States.moving);

            this.VerticalOffset = new Vector3(0, 0.8f, 0);
            this.ScaleMatrix = Matrix.CreateScale(0.6f);

            UpdateAnimations(0);
            UpdateMajorTransform();

            Globals.gameInstance.sceneGraph.Setup(_mesh);
            this._modelReceipt = Globals.gameInstance.sceneGraph.Add(_mesh);

            _collisionRectangle = new RectangleF(
                _position.X - bBWidth,
                _position.Z - bBWidth, bBWidth * 2, bBWidth * 2);
        }
예제 #6
0
        public ShardBuilder AddServer(Server server)
        {
            foreach (var item in collections.Items)
            {
                foreach (var shard in item.Shards)
                {
                    if (shard.Name == server.ShardName)
                    {
                        if (shard.Servers != null && shard.Servers.Contains(server, server as IEqualityComparer <Server>))
                        {
                            throw new UnKnownException(String.Format("server already in shard,server:{0},shardName:{1}", server, shard.Name));
                        }

                        this.shard   = shard;
                        this.range   = shard.Range;
                        this.servers = shard.Servers;
                        this.state   = shard.State;
                        break;
                    }
                }
            }

            servers.Add(server);
            this.name = server.ShardName;
            return(this);
        }
예제 #7
0
 public ClientStateInfo(Guid id, Guid clientId, Guid?encounterId, Guid?indexClientId, LiveState status, DateTime statusDate)
 {
     Id            = id;
     ClientId      = clientId;
     EncounterId   = encounterId;
     IndexClientId = indexClientId;
     Status        = status;
     StatusDate    = statusDate;
 }
예제 #8
0
        public static ILiveState <T> NewLive <T>(
            this IStateFactory factory,
            Func <ILiveState <T>, CancellationToken, Task <T> > computer,
            object?argument = null)
        {
            var options = new LiveState <T> .Options();

            return(factory.NewLive(options, computer, argument));
        }
예제 #9
0
 /// <summary>
 /// Changes the cell's living state.
 /// </summary>
 /// <param name="state">New value for the cell living state.</param>
 public void ChangeState(LiveState state)
 {
     //Prevent dead turning to unused
     if (this.state == LiveState.DEAD && state == LiveState.INTIAL)
     {
         return;
     }
     this.state = state;
     ReColor();
 }
예제 #10
0
        public static ILiveState <T, TOwn> NewLive <T, TOwn>(
            this IStateFactory factory,
            Action <LiveState <T, TOwn> .Options> optionsBuilder,
            Func <ILiveState <T, TOwn>, CancellationToken, Task <T> > computer,
            object?argument = null)
        {
            var options = new LiveState <T, TOwn> .Options();

            optionsBuilder.Invoke(options);
            return(factory.NewLive(options, computer, argument));
        }
예제 #11
0
        // private static void CallGlobalEventStaging(GlobalEvent globalEvent, SimplePrecedence stage)
        // {
        // try
        // {
        // if (GlobalEventStaging != null)
        // {
        // GlobalEventStaging(globalEvent, stage);
        // }
        // }
        // catch (Exception exception)
        // {
        // FomsLogger.WriteError(exception, null);
        // }
        // }

        /// <summary>
        /// The can change live state.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private static bool CanChangeLiveState(LiveState state)
        {
            switch (liveState)
            {
            case LiveState.Normal:
                switch (state)
                {
                case LiveState.Fatal:
                case LiveState.ExitExpected:
                case LiveState.RestartExpected:
                case LiveState.FatalRestartExpected:
                    return(true);
                }

                break;

            case LiveState.Fatal:
                switch (state)
                {
                case LiveState.ExitExpected:
                case LiveState.RestartExpected:
                case LiveState.FatalRestartExpected:
                    return(true);
                }

                break;

            case LiveState.RestartExpected:
                switch (state)
                {
                case LiveState.ExitExpected:
                case LiveState.FatalRestartExpected:
                    return(true);
                }

                break;

            case LiveState.FatalRestartExpected:
                if (state != LiveState.ExitExpected)
                {
                    break;
                }

                return(true);
            }

            return(false);
        }
예제 #12
0
 public static IServiceCollection AddLiveState <TState>(
     this IServiceCollection services,
     Func <IServiceProvider, ILiveState <TState>, CancellationToken, Task <TState> > updater,
     Action <IServiceProvider, LiveState <TState> .Options>?optionsBuilder = null)
 {
     services.TryAddSingleton(c => {
         var options = new LiveState <TState> .Options()
         {
             Updater = (live, cancellationToken) => updater.Invoke(c, live, cancellationToken),
         };
         optionsBuilder?.Invoke(c, options);
         return(options);
     });
     services.TryAddTransient <ILiveState <TState>, LiveState <TState> >();
     return(services);
 }
예제 #13
0
        public static List <LiveState> GetNext(this LiveState current)
        {
            var list = new List <LiveState>();

            //HTS

            if (current == LiveState.HtsTestedPos || current == LiveState.HtsTestedInc)
            {
                list.Add(LiveState.HtsReferred);
                list.Add(LiveState.HtsFamAcceptedYes);
            }

            if (current == LiveState.HtsTestedNeg)
            {
                list.Add(LiveState.HtsFamAcceptedYes);
            }

            return(list);
        }
예제 #14
0
 public static IServiceCollection AddLiveState <TState, TUpdater>(
     this IServiceCollection services,
     Action <IServiceProvider, LiveState <TState> .Options>?optionsBuilder = null)
     where TState : class
     where TUpdater : class, ILiveStateUpdater <TState>
 {
     services.TryAddSingleton(c => {
         var updater = c.GetRequiredService <ILiveStateUpdater <TState> >();
         var options = new LiveState <TState> .Options()
         {
             Updater = (live, cancellationToken) => updater.UpdateAsync(live, cancellationToken),
         };
         optionsBuilder?.Invoke(c, options);
         return(options);
     });
     services.TryAddTransient <ILiveState <TState>, LiveState <TState> >();
     services.AddLiveStateUpdater <TState, TUpdater>();
     return(services);
 }
예제 #15
0
        /// <summary>
        /// Cell constructor
        /// </summary>
        public Cell(int x, int y)
        {
            coords.x = x;
            coords.y = y;
            if (x > maxX)
            {
                maxX = x;
            }
            if (y > maxY)
            {
                maxY = y;
            }

            isRunning = false;
            Dock      = DockStyle.Fill;
            BackColor = System.Drawing.Color.GhostWhite;
            Click    += Clicked;        //Add Click Event Handler
            state     = LiveState.INTIAL;
            _cells.Add(coords, this);
        }
예제 #16
0
        // Правило для нового состояния
        public static LiveState GetNewState(LiveState currentState, int liveNeighbors)
        {
            switch (currentState)
            {
            case LiveState.Alive:
                if (liveNeighbors < 2 || liveNeighbors > 3)
                {
                    return(LiveState.Dead);
                }
                break;

            case LiveState.Dead:
                if (liveNeighbors == 3)
                {
                    return(LiveState.Alive);
                }
                break;
            }
            return(currentState);
        }
예제 #17
0
        /// <summary>
        /// Click Event Handler
        /// </summary>
        /// <param name="sender">Object that sends the event.</param>
        /// <param name="e">The event arguments.</param>
        private void Clicked(object sender, EventArgs e)
        {
            if (state == LiveState.INTIAL)
            {
                state = LiveState.LIVING;
            }
            else if (state == LiveState.LIVING)
            {
                state = LiveState.DEAD;
            }
            else if (state == LiveState.DEAD)
            {
                state = LiveState.INTIAL;
            }

            ReColor();
            //} else {
            //    Simulation.Instance.Pause();
            //    MessageBox.Show("Cell : " + coords.x + ", " + coords.y + " is in state: " + state.ToString(), "Cell State");
            //    Simulation.Instance.Run();
            //}
        }
예제 #18
0
        // private static void SystemEvents_TimeChanged(object sender, EventArgs e)
        // {
        // CultureInfo.CurrentCulture.ClearCachedData();
        // if (SystemTimeChanged != null)
        // {
        // SystemTimeChanged();
        // }
        // }

        /// <summary>
        /// The try change live state.
        /// </summary>
        /// <param name="state">
        /// The state.
        /// </param>
        /// <param name="forceSeparateThreadEvent">
        /// The force separate thread event.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool TryChangeLiveState(LiveState state, bool forceSeparateThreadEvent = false)
        {
            bool flag;

            lock (runningEvents)
            {
                if (CanChangeLiveState(state))
                {
                    liveState = state;
                    flag      = true;
                }
                else
                {
                    flag = false;
                }
            }

            if (flag)
            {
                RaiseGlobalEvent(GlobalEvent.LiveStateChanged, forceSeparateThreadEvent);
            }

            return(flag);
        }
예제 #19
0
 protected virtual void ConfigureState(LiveState <T> .Options options)
 {
 }
예제 #20
0
 public static void DefaultLiveStateOptionsBuilder(LiveState <AuthState> .Options options)
 => options.WithUpdateDelayer(0.1, 10);
예제 #21
0
        public override void Update(float ms)
        {

            if (_state == AlienState.ALIVE)
            {
                // check bullet collision
                // check for collision with bullet
                IProjectile p = Globals.gameInstance.projectileManager.CheckHit(this);
                if (p != null)
                {
                    p.PreDestroy();
                    p.Destroy();
                    this._health -= p.GetDamage();
                    if (this._health <= 0)
                    {
                        this._state = AlienState.DYING;
                        this._aplayer.StartClip(Animation_States.death);
                        Globals.audioManager.PlayGameSound("aliendeath1");
                    }
                }

                if (_livestate == LiveState.ROAMING)
                {
                    // check distance to target
                    if (Vector3.DistanceSquared(_targetPosition, _position) < 0.3f)
                    {
                        // new target
                        _targetPosition = new Vector3(
                            MathHelper.Clamp(
                                _position.X + (float)Globals.random.NextDouble() * 10 - 5, 
                                _section.Index * 32, 
                                _section.Index * 32 + 32
                            ),
                            _position.Y,
                            _position.Z + (float)Globals.random.NextDouble() * 10 - 5                            
                        );
                    }

                    // check player LOS
                    PlayerObject closestPlayer = Globals.gameInstance.GetClosestPlayer(_position);
                    if (Vector3.DistanceSquared(closestPlayer.Position, _position) <= 6*6)
                    {
                        //check LOS
                        _livestate = LiveState.CHASING;
                        _targetPlayer = closestPlayer;
                    }
                }

                if (_livestate == LiveState.CHASING)
                {
                    _targetPosition = _targetPlayer.Position;
                    float d = Vector3.DistanceSquared(_targetPosition, _position);
                    if (d > 6 * 6)
                    {
                        _livestate = LiveState.ROAMING;
                        _targetPosition = _position;
                    }
                    else 
                    {
                        //check LOS
                        bool LOS = true;
                        if (LOS)
                        {
                            if (d < 1.0f)
                            {
                                _livestate = LiveState.ATTACKING;
                                if (_targetPlayer.alive == true)
                                {
                                    _targetPlayer.health = _targetPlayer.health - 2;
                                }
                                
                                _aplayer.StartClip(Animation_States.attacking);
                            }
                        }
                        else
                        {
                            _livestate = LiveState.ROAMING;
                            _targetPosition = _position;
                        }
                    }               
                }
                if (_livestate == LiveState.ATTACKING)
                {
                    _targetPosition = _targetPlayer.Position;
                    if (_aplayer.GetLoopCount() > 0)
                    {
                        _livestate = LiveState.CHASING;
                        _aplayer.StartClip(Animation_States.moving);
                    }
                }
                
                if (_targetPosition != _position)
                {
                    _velocity = _targetPosition - _position;
                    _velocity.Normalize();
                    if (RotateToFacePosition(_velocity, ms))
                    {
                        bool collided = false;
                        Vector3 newpos = _position + _velocity * (ms / 200);

                        // FIRST DO TEH X
                        RebuildCollisionRectangle(newpos);
                        if (Globals.gameInstance.cellCollider.RectangleCollides(_collisionRectangle))
                        {
                            collided = true;
                        }
                        else if (Globals.gameInstance.campaignManager.CollideCurrentEntities(this))
                        {
                            collided = true;
                        }
                        else if (Globals.gameInstance.CollidesPlayers(this))
                        {
                            collided = true;
                        }

                        if (!collided)
                        {
                            _position = newpos;
                        }
                        else if (_livestate == LiveState.ROAMING)
                        {
                            _targetPosition = new Vector3(
                                MathHelper.Clamp(
                                    _position.X + (float)Globals.random.NextDouble() * 10 - 5,
                                    _section.Index * 32,
                                    _section.Index * 32 + 32
                                ),
                                _position.Y,
                                _position.Z + (float)Globals.random.NextDouble() * 10 - 5
                            );
                        }
                        else
                        {
                            Vector3 newposX = _position + Vector3.Right * _velocity * (ms / 200);
                            RebuildCollisionRectangle(newposX);
                            if (Globals.gameInstance.cellCollider.RectangleCollides(_collisionRectangle))
                            {
                                newposX.X = _position.X;
                            }
                            else if (Globals.gameInstance.campaignManager.CollideCurrentEntities(this))
                            {
                                newposX.X = _position.X;
                            }
                            else if (Globals.gameInstance.CollidesPlayers(this))
                            {
                                newposX.X = _position.X;
                            }

                            Vector3 newposZ = _position + Vector3.Backward * _velocity * (ms / 200);
                            RebuildCollisionRectangle(newposX);
                            if (Globals.gameInstance.cellCollider.RectangleCollides(_collisionRectangle))
                            {
                                newposZ.Z = _position.Z;
                            }
                            else if (Globals.gameInstance.campaignManager.CollideCurrentEntities(this))
                            {
                                newposZ.Z = _position.Z;
                            }
                            else if (Globals.gameInstance.CollidesPlayers(this))
                            {
                                newposZ.Z = _position.Z;
                            }

                            _position = new Vector3(newposX.X, _position.Y, newposZ.Z);


                        }

                    }
                }
                UpdateAnimations(ms * 1.5f);
                UpdateMajorTransform();
                _modelReceipt.graph.Renew(_modelReceipt);
            }
            else
            {
                UpdateAnimations(ms * 1.5f); // animations are accelerated a bit

                if (this._aplayer.GetLoopCount() > 0)
                {
                    this._state = AlienState.DEAD;
                    this._mustBeDeleted = true;
                    this.DestroyReceipt();
                }
            }
        }
예제 #22
0
 /// <summary>
 /// Resets cell's living state to intial.
 /// </summary>
 public void ResetCell()
 {
     state = LiveState.INTIAL;
     ReColor();
 }
예제 #23
0
        public override void Update(float ms)
        {
            if (_state == AlienState.ALIVE)
            {
                // check bullet collision
                // check for collision with bullet
                IProjectile p = Globals.gameInstance.projectileManager.CheckHit(this);
                if (p != null)
                {
                    p.PreDestroy();
                    p.Destroy();
                    this._health -= p.GetDamage();
                    if (this._health <= 0)
                    {
                        this._state = AlienState.DYING;
                        this._aplayer.StartClip(Animation_States.death);
                        Globals.audioManager.PlayGameSound("aliendeath1");
                    }
                }

                if (_livestate == LiveState.ROAMING)
                {
                    // check distance to target
                    if (Vector3.DistanceSquared(_targetPosition, _position) < 0.3f)
                    {
                        // new target
                        _targetPosition = new Vector3(
                            MathHelper.Clamp(
                                _position.X + (float)Globals.random.NextDouble() * 10 - 5,
                                _section.Index * 32,
                                _section.Index * 32 + 32
                                ),
                            _position.Y,
                            _position.Z + (float)Globals.random.NextDouble() * 10 - 5
                            );
                    }

                    // check player LOS
                    PlayerObject closestPlayer = Globals.gameInstance.GetClosestPlayer(_position);
                    if (Vector3.DistanceSquared(closestPlayer.Position, _position) <= 6 * 6)
                    {
                        //check LOS
                        _livestate    = LiveState.CHASING;
                        _targetPlayer = closestPlayer;
                    }
                }

                if (_livestate == LiveState.CHASING)
                {
                    _targetPosition = _targetPlayer.Position;
                    float d = Vector3.DistanceSquared(_targetPosition, _position);
                    if (d > 6 * 6)
                    {
                        _livestate      = LiveState.ROAMING;
                        _targetPosition = _position;
                    }
                    else
                    {
                        //check LOS
                        bool LOS = true;
                        if (LOS)
                        {
                            if (d < 2.0f)
                            {
                                _livestate = LiveState.ATTACKING;
                                if (_targetPlayer.alive == true)
                                {
                                    _targetPlayer.health = _targetPlayer.health - 10;
                                }

                                _aplayer.StartClip(Animation_States.attacking);
                            }
                        }
                        else
                        {
                            _livestate      = LiveState.ROAMING;
                            _targetPosition = _position;
                        }
                    }
                }
                if (_livestate == LiveState.ATTACKING)
                {
                    _targetPosition = _targetPlayer.Position;
                    if (_aplayer.GetLoopCount() > 0)
                    {
                        _livestate = LiveState.CHASING;
                        _aplayer.StartClip(Animation_States.charging);
                    }
                }

                if (_targetPosition != _position)
                {
                    _velocity = _targetPosition - _position;
                    _velocity.Normalize();
                    if (RotateToFacePosition(_velocity, ms))
                    {
                        bool    collided = false;
                        Vector3 newpos   = _position + _velocity * (ms / 180);

                        // FIRST DO TEH X
                        RebuildCollisionRectangle(newpos);
                        if (Globals.gameInstance.cellCollider.RectangleCollides(_collisionRectangle))
                        {
                            collided = true;
                        }
                        else if (Globals.gameInstance.campaignManager.CollideCurrentEntities(this))
                        {
                            collided = true;
                        }
                        else if (Globals.gameInstance.CollidesPlayers(this))
                        {
                            collided = true;
                        }

                        if (!collided)
                        {
                            _position = newpos;
                        }
                        else if (_livestate == LiveState.ROAMING)
                        {
                            _targetPosition = new Vector3(
                                MathHelper.Clamp(
                                    _position.X + (float)Globals.random.NextDouble() * 10 - 5,
                                    _section.Index * 32,
                                    _section.Index * 32 + 32
                                    ),
                                _position.Y,
                                _position.Z + (float)Globals.random.NextDouble() * 10 - 5
                                );
                        }
                        else
                        {
                            Vector3 newposX = _position + Vector3.Right * _velocity * (ms / 350);
                            RebuildCollisionRectangle(newposX);
                            if (Globals.gameInstance.cellCollider.RectangleCollides(_collisionRectangle))
                            {
                                newposX.X = _position.X;
                            }
                            else if (Globals.gameInstance.campaignManager.CollideCurrentEntities(this))
                            {
                                newposX.X = _position.X;
                            }
                            else if (Globals.gameInstance.CollidesPlayers(this))
                            {
                                newposX.X = _position.X;
                            }

                            Vector3 newposZ = _position + Vector3.Backward * _velocity * (ms / 350);
                            RebuildCollisionRectangle(newposX);
                            if (Globals.gameInstance.cellCollider.RectangleCollides(_collisionRectangle))
                            {
                                newposZ.Z = _position.Z;
                            }
                            else if (Globals.gameInstance.campaignManager.CollideCurrentEntities(this))
                            {
                                newposZ.Z = _position.Z;
                            }
                            else if (Globals.gameInstance.CollidesPlayers(this))
                            {
                                newposZ.Z = _position.Z;
                            }

                            _position = new Vector3(newposX.X, _position.Y, newposZ.Z);
                        }
                    }
                }
                UpdateAnimations(ms * 1.5f);
                UpdateMajorTransform();
                _modelReceipt.graph.Renew(_modelReceipt);
            }
            else
            {
                UpdateAnimations(ms * 1.5f); // animations are accelerated a bit

                if (this._aplayer.GetLoopCount() > 0)
                {
                    this._state         = AlienState.DEAD;
                    this._mustBeDeleted = true;
                    this.DestroyReceipt();
                }
            }
        }
예제 #24
0
        public static bool CanBeMutliple(this LiveState current)
        {
            return(false);

            return(current == LiveState.FamilyTracedContacted);
        }
예제 #25
0
 public ClientState(Guid clientId, Guid encounterId, LiveState state) : this(clientId, state)
 {
     EncounterId = encounterId;
 }
예제 #26
0
 public static bool HasNext(this LiveState current)
 {
     return(current == LiveState.HtsTestedPos);
 }
예제 #27
0
 public void Hit()
 {
     liveState = LiveState.DEAD;
     EventMessenger.TriggerEvent(GameEvents.DEFEATE);
 }
예제 #28
0
 public ClientState(Guid clientId, Guid encounterId, LiveState state, Guid indexClientId) : this(clientId, state, indexClientId)
 {
     EncounterId = encounterId;
 }
예제 #29
0
파일: Program.cs 프로젝트: FaustVX/GameLife
        private static KeyValuePair <LiveState, Drawable> Switch(KeyValuePair <LiveState, Drawable> item, LiveState newState)
        {
            if (item.Key == newState)
            {
                return(item);
            }

            var newItem = new KeyValuePair <LiveState, Drawable>(newState, item.Value);

#if QUICK
            Quick[item.Key].Remove(item);
            Quick[newState].Add(newItem);
#endif

            return(newItem);
        }
예제 #30
0
파일: Program.cs 프로젝트: FaustVX/GameLife
        /// <summary>
        /// Point d'entrée principal de l'application.
        /// </summary>
        private static void Main()
        {
            //int nbGeneration = 0;
            while (Window.IsOpen())
            {
                //for (int i = 1; i <= States.Count; i++)
                //{
                //	var rect = new RectangleShape(new Window.Vector2f(Offset.X, StateButtonSize))
                //		{
                //			Position = new Window.Vector2f(0, i * StateButtonSize)
                //		};
                //	Window.Draw(rect);
                //}

                if (running)
                {
                    LiveState[][] newCells = new LiveState[NbCells.X][];
                    for (int i = 0; i < NbCells.X; i++)
                    {
                        newCells[i] = new LiveState[NbCells.Y];
                    }

                    Cells.ForEach((i, j, cell) =>
                    {
                        int living = Cells.Arround(i, j);
                        switch (cell.Key)
                        {
                        case LiveState.Emerging:
                            if (living == 2 || living == 3)
                            {
                                newCells[i][j] = LiveState.Live;
                            }
                            else
                            {
                                newCells[i][j] = LiveState.Dying;
                            }
                            break;

                        case LiveState.Live:
                            if (living == 2 || living == 3)
                            {
                                newCells[i][j] = cell.Key;
                            }
                            else
                            {
                                newCells[i][j] = LiveState.Dying;
                            }
                            break;

                        case LiveState.Dying:
                            if (living == 3)
                            {
                                newCells[i][j] = LiveState.Emerging;
                            }
                            else
                            {
                                newCells[i][j] = LiveState.Dead;
                            }
                            break;

                        case LiveState.Dead:
                            if (living == 3)
                            {
                                newCells[i][j] = LiveState.Emerging;
                            }
                            else
                            {
                                newCells[i][j] = cell.Key;
                            }
                            break;
                        }
                    });
                    newCells.ForEach((x, y, state) =>
                    {
                        Cells[x][y] = Switch(Cells[x][y], state);
                    });
                }

                Window.DispatchEvents();
                Window.Clear(PauseColor[running]);
#if WINDOWS
                ZommedWindow.DispatchEvents();
                ZommedWindow.Clear();
#endif

                for (int i = 0; i < Cells.Length; ++i)
                {
                    for (int j = 0; j < Cells[i].Length; ++j)
                    {
                        var            cell = Cells[i][j];
                        RectangleShape rect = cell.Value as RectangleShape;
                        if (rect == null)
                        {
                            return;
                        }
                        if (selectedCell.X >= 0 && selectedCell.Y >= 0 && cell.Value.Equals(Cells[selectedCell.X][selectedCell.Y].Value))
                        {
                            rect.FillColor = SelectedColors[cell.Key];
                        }
                        else
                        {
                            rect.FillColor = Colors[cell.Key];
                        }
                        rect.Position         = new Window.Vector2f(i * CellSize.X + Offset.X, j * CellSize.Y + Offset.Y);
                        rect.OutlineThickness = 0f;
                        Window.Draw(rect);
                    }
                }

#if WINDOWS
                Cells.Square(ToIntRect(selectedCell.X, selectedCell.Y, NbZoomedCells.X, NbZoomedCells.Y, ZoomedOffset.X,
                                       ZoomedOffset.Y))
                .ForEach((
                             x, y, item) =>
                {
                    RectangleShape rect = item.Value as RectangleShape;
                    if (rect == null)
                    {
                        return;
                    }
                    if (selectedCell.X >= 0 && selectedCell.Y >= 0 && item.Value.Equals(Cells[selectedCell.X][selectedCell.Y].Value))
                    {
                        rect.FillColor = SelectedColors[item.Key];
                    }
                    else
                    {
                        rect.FillColor = Colors[item.Key];
                    }
                    rect.Size             = ZoomedCellSize;
                    rect.Position         = new Window.Vector2f(x * ZoomedCellSize.X, y * ZoomedCellSize.Y);
                    rect.OutlineThickness = 1f;
                    ZommedWindow.Draw(rect);
                });
#endif



                //if (running)
                //	if (nbGeneration++ >= 111)
                //		continue;
                Window.Display();
#if WINDOWS
                ZommedWindow.Display();
#endif
            }
        }
예제 #31
0
 public ShardBuilder State(LiveState state)
 {
     this.state = state;
     return(this);
 }