Ejemplo n.º 1
0
    private void ApplyRotateRestriction()
    {
        if (RotationType.STATIC != rotationType)
        {
            if (RotationType.TWO_DIMENSION == rotationType)
            {
                if (angle == 0)
                {
                    desiredAngle = +90;
                }
                else
                {
                    rotateBack   = true;
                    desiredAngle = 0;
                }
            }
            else
            if (RotationType.FREE_ROTATE == rotationType)
            {
                desiredAngle -= 90;
            }

            SetFigureTrigger(true);
            state  = FigureState.Rotation;
            deltaH = gameObject.transform.position.y;

            ScriptManager.SoundController.PlaySound(SoundController.SoundAction.Rotate);
        }
    }
Ejemplo n.º 2
0
    private async void MoveY()
    {
        while (_state == FigureState.Mooving)
        {
            await Task.Delay(_field.GetDelay() * 100);

            try
            {
                foreach (var mini in _miniCubes)
                {
                    if (_field.GetCubes()[new Vector2Int(mini.GetPosition().x, mini.GetPosition().y - 1)] != null)
                    {
                        State = FigureState.Idle;
                        break;
                    }
                }
            }
            catch (KeyNotFoundException k)
            {
            }

            if (_state == FigureState.Idle)
            {
                break;
            }

            foreach (var mini in _miniCubes)
            {
                mini.transform.position += Vector3.down;
                mini.SetNewPosition(new Vector2Int((int)mini.transform.position.x, (int)mini.transform.position.y));
            }
        }
    }
Ejemplo n.º 3
0
 public FieldController(int _fieldWidth, int _fieldHeight, Transform _container)
 {
     fieldWidth  = _fieldWidth;
     fieldHeight = _fieldHeight;
     container   = _container;
     storedCubes = new List <Cube>();
     State       = new FigureState();
 }
Ejemplo n.º 4
0
 public Wawka(sbyte team, Point position, bool damka)
 {
     this.position = position;
     state         = FigureState.usuall;
     if (damka)
     {
         state = FigureState.damka;
     }
     this.team = team;
 }
Ejemplo n.º 5
0
 public FigureState GetState()
 {
     FigureState fs = new FigureState()
       {
     color = this.color,
     field = this.field,
     moveCount = this.moveCount,
     type = this.type
       };
       return fs;
 }
Ejemplo n.º 6
0
 protected void CheckFalled()
 {
     if (ScriptManager.BoardController.CanNotMoveDown(gameObject))
     {
         state = FigureState.Stopped;
         ResetFigureTags();
         Destroy(this);
         ScriptManager.SoundController.PlaySound(SoundController.SoundAction.Falling);
         ScriptManager.GameController.Respawn();
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 改變人物指定狀態的類別,傳回原先狀態
 /// (沒輸入則直接回傳目前狀態不改變原先狀態)
 /// 數字溢位則回傳Null
 /// </summary>
 /// <param name="_newState"></param>
 public FigureState ChangeState(FigureState _newState, int _type)
 {
     if (_newState == null)
     {
         return(myStateList[_type]);
     }
     if (_type > myStateList.Length)
     {
         return(null);
     }
     return(myStateList[_type]);
 }
Ejemplo n.º 8
0
    void SaveGame()
    {
        BinaryFormatter bf       = new BinaryFormatter();
        FileStream      file     = File.Create(Application.persistentDataPath + "/GameInfo.dat");
        SaveInfo        saveData = new SaveInfo();

        if (gameEnd || figures == null)
        {
            saveData.saved = false;
            bf.Serialize(file, saveData);
            file.Close();
        }

        for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                if (figures[i, j] != null)
                {
                    AddToListSaveFigures(figures[i, j], saveData);
                }
            }
        }
        for (int i = 0; i < defeatedBlackFigures.Count; i++)
        {
            AddToListSaveFigures(defeatedBlackFigures[i], saveData);
        }
        for (int i = 0; i < defeatedWhiteFigures.Count; i++)
        {
            AddToListSaveFigures(defeatedWhiteFigures[i], saveData);
        }

        if (becomeKingFigure != null)
        {
            saveData.idBecomeKingFigure = becomeKingFigure.id;
        }
        else
        {
            saveData.idBecomeKingFigure = -1;
        }

        saveData.presentTeam = presentTeam;
        saveData.saved       = true;
        saveData.states.Clear();
        while (stateManager.HaveElementInStack())
        {
            FigureState temp = stateManager.GetState();
            saveData.states.Add(temp);
        }

        bf.Serialize(file, saveData);
        file.Close();
    }
Ejemplo n.º 9
0
    private void FullEmptySpace(FigureState state, Figure figure)
    {
        if (state == FigureState.Idle)
        {
            foreach (var mini in figure.MiniCubes)
            {
                _model.Cubes[new Vector2Int(mini.GetPosition().x, mini.GetPosition().y)] = mini.gameObject;
            }
        }

        CheckForFull();
        CreateFigure();
    }
Ejemplo n.º 10
0
 private void handle_figure_state_changed(InteractiveFigure figure, FigureState state)
 {
     if (state == FigureState.Closed)
     {
         int index = this.FiguresTyped.FindIndex((x) => figure == x);
         if (index >= 0)
         {
             this.FiguresTyped.RemoveAt(index);
             if (this.ActiveFigureIndex >= index)
             {
                 this.ActiveFigureIndex = Math.Max(this.ActiveFigureIndex - 1, this.FiguresTyped.Count - 1);
             }
             figure.StateChange -= handle_figure_state_changed;
         }
     }
 }
Ejemplo n.º 11
0
    void PerformMoveRight()
    {
        Vector2 position = gameObject.transform.position;

        if (position.x < desiredPosX)
        {
            position.x += DELTA_X;
            gameObject.transform.position = position;
        }
        else
        {
            position.x = desiredPosX;
            gameObject.transform.position = position;
            state = FigureState.Idle;
        }
    }
Ejemplo n.º 12
0
    void StopRotation()
    {
        SetFigureTrigger(false);
        state = FigureState.Idle;

        //BoardGizmos.ClearLog ();
        float delta = deltaH - gameObject.transform.position.y;

        if (delta > maxDeltaH)
        {
            maxDeltaH = delta;
        }
        if (delta < minDeltaH)
        {
            minDeltaH = delta;
        }
        //Debug.Log ("max=" + maxDeltaH + "  min=" + minDeltaH);
    }
Ejemplo n.º 13
0
    /// <summary>
    /// 抽換指定的狀態
    /// </summary>
    /// <param name="_stateIndex"></param>
    public void ChangeState(FigureStateEnum _stateEnum)
    {
        //狀態枚舉
        int stateIndex = (int)_stateEnum;

        //過濾不合理情況
        if (myStateList.Length < (int)_stateEnum)
        {
            return;
        }
        if (myStateList[stateIndex] == null)
        {
            return;
        }
        //如前後一樣也無視
        if (currentStateEnum == _stateEnum)
        {
            return;
        }
        //新的狀態
        FigureStateEnum newEnum  = _stateEnum;
        FigureState     newState = myStateList[(int)_stateEnum];

        //替換掉舊的監聽者
        if (currentState != null)
        {
            currentState.Exit();
            RemoveActionListener = currentState;
            RemoveCombatListener = currentState;
            RemoveValueListener  = currentState;
        }
        //更換成新的
        currentState     = newState;
        currentStateEnum = newEnum;
        currentState.Start();
        AddActionListener = currentState;
        AddValueListener  = currentState;
        AddCombatListener = currentState;
    }
Ejemplo n.º 14
0
    /// <summary>
    /// 初始化狀態
    /// </summary>
    protected virtual void InitialState()
    {
        int index = 0;

        FigureStateEnum[] figureStateEnum = Enum.GetValues(typeof(FigureStateEnum)) as FigureStateEnum[];
        myStateList = new FigureState[figureStateEnum.Length];
        foreach (FigureStateEnum _states in figureStateEnum)
        {
            var  stateString = _states.ToString();
            Type stateType   = Type.GetType(stateString);
            var  stateObject = Activator.CreateInstance(stateType) as FigureState;
            stateObject.Figure = this;
            if (stateObject == null)
            {
                MyLog.Log(" state : " + stateString + " is null");
                break;
            }
            myStateList[index++] = stateObject;
        }
        //initial state is normal state
        ChangeState((int)FigureStateEnum.NormalState);
    }
Ejemplo n.º 15
0
    IEnumerator BackToTheStart()
    {
        speed = 1f;

        while (stateManager.HaveElementInStack())
        {
            FigureState tempState  = stateManager.GetState();
            ChessFigure tempFigure = FindFigure(tempState.id);

            bool destroy = tempState.numberTurn == 0 && tempState.beforeFigure;
            tempFigure.AnimateTurn(new Vector3(tempState.positionX, tempState.positionY, tempState.positionZ), speed, TypeAnimation.Back, destroy);

            //Debug.Log("coroutine" + Time.time);

            yield return(new WaitForSeconds(speed));

            if (speed >= .1f)
            {
                speed *= .9f;
            }
        }

        ReInitGame();       //есть лишнее
    }
Ejemplo n.º 16
0
    void Update()
    {
        if (FigureState.Stopped == state)
        {
            return;
        }

        // Level menu invokation
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            ScriptManager.GameController.PauseResume();
        }


        if (isPause)
        {
            return;
        }

        if (FigureState.MoveDownFast == state)
        {
            CheckFalled();
            PerformTransformation();
            return;
        }


        if (FigureState.Idle == state || FigureState.MoveDown == state)
        {
            CheckFalled();

            if (Input.GetKey(KeyCode.LeftArrow))
            {
                if (ScriptManager.BoardController.CanMoveLeft(gameObject))
                {
                    Vector2 pos = gameObject.transform.position;
                    desiredPosX = pos.x - BoardController.BRICK_SIZE;
                    state       = FigureState.MoveLeft;
                }
            }
            else if (Input.GetKey(KeyCode.RightArrow))
            {
                if (ScriptManager.BoardController.CanMoveRight(gameObject))
                {
                    Vector2 pos = gameObject.transform.position;
                    desiredPosX = pos.x + BoardController.BRICK_SIZE;
                    state       = FigureState.MoveRight;
                }
            }
            else if (Input.GetKey(KeyCode.UpArrow))
            {
                if (FigureState.Idle == state && ScriptManager.BoardController.CanRotate(gameObject))
                {
                    ApplyRotateRestriction();
                }
            }
            else if (Input.GetKey(KeyCode.DownArrow))
            {
                if (ScriptManager.BoardController.CanMoveDown(gameObject))
                {
                    state = FigureState.MoveDown;
                }
            }
            else if (Input.GetKeyUp(KeyCode.DownArrow))
            {
                if (FigureState.MoveDown == state)
                {
                    state = FigureState.Idle;
                }
            }
            else if (Input.GetKeyDown(KeyCode.Space))
            {
                if (ScriptManager.BoardController.CanMoveDown(gameObject))
                {
                    state = FigureState.MoveDownFast;
                }
            }
        }

        PerformTransformation();
    }
Ejemplo n.º 17
0
 public Wawka(sbyte team, Point position)
 {
     this.position = position;
     state         = FigureState.usuall;
     this.team     = team;
 }
Ejemplo n.º 18
0
 public Wawka(sbyte team)
 {
     position  = new Point(0, 0);
     state     = FigureState.usuall;
     this.team = team;
 }
Ejemplo n.º 19
0
 public Wawka()
 {
     position = new Point(0, 0);
     state    = FigureState.usuall;
     team     = 0;
 }
Ejemplo n.º 20
0
 public void AddState(FigureState figure)
 {
     states.Push(figure);
     //Debug.Log(figure.type.ToString() + "  " + states.Peek().position + "  " + states.Peek().numberTurn);
 }
Ejemplo n.º 21
0
 void BaseImperativeFigure_StateChanged(InteractiveFigure arg1, FigureState arg2)
 {
     this.State = arg2;
 }