예제 #1
0
    public PowerUpState OneRewind()
    {
//        PowerUpState newState = _states[_states.Count - 1];
//      _states.RemoveAt(_states.Count - 1);
        //  return newState;



        ChangedFieldsCollection psd = _stateTransitions[_stateTransitions.Count - 1];

        PowerUpState previousState = (PowerUpState)sd.CurrentState.RetrievePreviousState(psd);// PlayerState.SubtractFromPlayerState(new PlayerState(), psd);



        //Debug.Log("previous state powerups " + previousState.NumOfPowerUps);//.Count);

        sm.PutObjectInState(previousState);// new PlayerState(newState));



        _stateTransitions.RemoveAt(_stateTransitions.Count - 1);
        //        _statesRemovedDuringRewinding++;

        _numOfStates--; //   _linePositions.RemoveAt(_linePositions.Count - 1);
                        //      StatesChangedSoUpdateLineRenderer();


        return(previousState);
        //  return -1; //minus one indicates that we haven't finished rewinding yet
    }
    public int Rewind()
    {
        //Debug.Log("inside rewind");
        if (_stateTransitions.Count > 0)
        {
            ChangedFieldsCollection psd = _stateTransitions[_stateTransitions.Count - 1];

            PlayerState previousState = (PlayerState)StateManager.CurrentState.PlayerState.RetrievePreviousState(psd);// PlayerState.SubtractFromPlayerState(new PlayerState(), psd);



            //Debug.Log("previous state powerups " + previousState.NumOfPowerUps);//.Count);

            PlayerController.Instance.PutPlayerInState(previousState);// new PlayerState(newState));



            _stateTransitions.RemoveAt(_stateTransitions.Count - 1);
            _statesRemovedDuringRewinding++;

            _linePositions.RemoveAt(_linePositions.Count - 1);
            StatesChangedSoUpdateLineRenderer();



            return(-1); //minus one indicates that we haven't finished rewinding yet
        }
        else
        {
            //StopRewind();
            return(_statesRemovedDuringRewinding);
        }
    }
예제 #3
0
    public IState RetrievePreviousState(ChangedFieldsCollection cfc)
    {//it doesn't affect the original object, it creates a clone
        PowerUpState clone = new PowerUpState(this);

        foreach (ChangedField cf in cfc.ChangedFields)
        {
            typeof(PowerUpState).GetField(cf.Name).SetValue(clone, cf.OldValue);
        }

        return(clone);
    }
예제 #4
0
    public ChangedFieldsCollection FindChangedFieldsComparedTo(IState statef)// PlayerState state)
    {
        ChangedFieldsCollection result = new ChangedFieldsCollection();


        PowerUpState state = (PowerUpState)statef;



        if (Collected != state.Collected)
        {
            result.AddChangedField(new ChangedField(Collected, "Collected", typeof(bool)));
        }

        return(result);
    }
예제 #5
0
    public ChangedFieldsCollection FindChangedFieldsComparedTo(IState statef)// PlayerState state)
    {
        ChangedFieldsCollection result = new ChangedFieldsCollection();


        PlayerState state = (PlayerState)statef;

        //todo: dynamically find fields
        //var fieldNames = typeof(PlayerState).GetFields()
        //                  .Select(field => field.Name)
        //                .ToList();



        if (IsTrailCyan != state.IsTrailCyan)
        {
            result.AddChangedField(new ChangedField(IsTrailCyan, "IsTrailCyan", typeof(bool)));
        }

        if (PlayerColor != state.PlayerColor)
        {
            result.AddChangedField(new ChangedField(PlayerColor, "PlayerColor", typeof(PlayerColor)));
        }

        if (IsTrailInForeground != state.IsTrailInForeground)
        {
            result.AddChangedField(new ChangedField(IsTrailInForeground, "IsTrailInForeground", typeof(bool)));
        }

        if (Position != state.Position)
        {
            result.AddChangedField(new ChangedField(Position, "Position", typeof(Vector3)));
        }

        if (Velocity != state.Velocity)
        {
            result.AddChangedField(new ChangedField(Velocity, "Velocity", typeof(Vector3)));
        }

        if (HelperClass.AreTheyDifferent(CollectedPowerUpTypes, state.CollectedPowerUpTypes))
        {
            result.AddChangedField(new ChangedField(HelperClass.CloneTrick(CollectedPowerUpTypes), "CollectedPowerUpTypes", typeof(List <PowerUpType>)));
        }

        return(result);
    }
예제 #6
0
    public IState RetrievePreviousState(ChangedFieldsCollection cfc)
    {//it doesn't affect the original object, it creates a clone
        PlayerState clone = new PlayerState(this);

        foreach (ChangedField cf in cfc.ChangedFields)
        {
            typeof(PlayerState).GetField(cf.Name).SetValue(clone, cf.OldValue);

            /*
             * switch (cf.ChangedFieldName)
             * {
             *  case ChangedFieldName.Velocity:
             *      clone.Velocity = (Vector3)cf.OldValue;
             *      break;
             *  case ChangedFieldName.PowerUpTypes:
             *      clone.CollectedPowerUpTypes = HelperClass.CloneTrick((List<PowerUpType>)cf.OldValue);
             *      break;
             * }*/
        }

        return(clone);
    }