Example #1
0
        void DoSetState(PieceState state)
        {
            switch (state)
            {
            case PieceState.None:
                SetAsNothingToDo();
                break;

            case PieceState.Removable:
                SetAsRemovable();
                break;

            case PieceState.WaitToRemove:
                SetAsWaitToRemove();
                break;

            case PieceState.Movable:
                SetAsMovable();
                break;

            case PieceState.WaitToMove:
                SetAsWaitToMove();
                break;

            case PieceState.Dead:
                SetAsDead();
                break;

            default:
                Debug.LogErrorFormat("Undefined PieceState : {0}", state);
                break;
            }
        }
 public void goToBlock(BlockController block)
 {
     state       = PieceState.RETURNING;
     placePos    = block.transform.position;
     returnPlace = placePos;
     fromBlock   = block;
 }
Example #3
0
    protected virtual IEnumerator MoveToCoroutine(Vector3 destination, System.Action <Piece> onComplete, float speed, float delay = 0, float acceleration = 0)
    {
        if (delay > 0)
        {
            yield return(new WaitForSeconds(delay));
        }

        bool didArrive = false;

        while (!didArrive)
        {
            Vector3 newPosition = Vector3.MoveTowards(transform.localPosition, destination, Time.deltaTime * speed);
            transform.localPosition = newPosition;
            speed += acceleration * Time.deltaTime;

            didArrive = Vector3.Distance(transform.localPosition, destination) < minDistance;
            if (!didArrive)
            {
                yield return(new WaitForEndOfFrame());
            }
        }
        transform.localPosition = destination;
        state = PieceState.Idle;
        onComplete.Invoke(this);
    }
Example #4
0
 //flat 0
 //in -1
 //out 1
 public bool isMatch(PieceState p, char direction)
 {
     if (direction == 'L')
     {
         if (edge(0) + p.edge(2) == 0)
         {
             return(true);
         }
     }
     else if (direction == 'T')
     {
         if (edge(1) + p.edge(3) == 0)
         {
             return(true);
         }
     }
     else if (direction == 'R')
     {
         if (edge(2) + p.edge(0) == 0)
         {
             return(true);
         }
     }
     else if (direction == 'B')
     {
         if (edge(3) + p.edge(1) == 0)
         {
             return(true);
         }
     }
     return(false);
 }
 public void returnToStart()
 {
     state       = PieceState.RETURNING;
     returnPlace = startPos;
     placePos    = Vector3.zero;
     fromBlock   = null;
 }
Example #6
0
    public GameState(Card cardA1, Card cardA2, Card cardB1, Card cardB2, Card freeCard, Piece[][] table)
    {
        cardA1State   = new CardState(cardA1);
        cardA2State   = new CardState(cardA2);
        cardB1State   = new CardState(cardB1);
        cardB2State   = new CardState(cardB2);
        freeCardState = new CardState(freeCard);

        tableState = new PieceState[5][];
        for (int i = 0; i < 5; i++)
        {
            tableState[i] = new PieceState[5];
            for (int j = 0; j < 5; j++)
            {
                if (table[i][j] != null)
                {
                    tableState[i][j] = new PieceState(table[i][j]);
                }
                else
                {
                    tableState[i][j] = null;
                }
            }
        }
    }
Example #7
0
 // contsructor
 public Tetramino(TetraType type, Point loc, PieceState state)
 {
     cType  = type;
     Loc    = loc;
     cState = state;
     this.FillTetra();
 }
Example #8
0
 private string _UpdateBuffer()
 {
     char[] buffer = new char[71];
     buffer[0] = 'U';
     buffer[1] = 'P';
     buffer[2] = 'D';
     buffer[3] = 'T';
     PieceState[,] pieceStates = new PieceState[8, 8];
     _Reversi.CopyState(pieceStates);
     for (var i = 0; i < 8; i++)
     {
         for (var j = 0; j < 8; j++)
         {
             if (pieceStates[i, j] == PieceState.PieceAvailable)
             {
                 if (_Reversi.GetCurrentPlayer() == _Player)
                 {
                     buffer[4 + i * 8 + j] = (char)((int)pieceStates[i, j]);
                 }
                 else
                 {
                     buffer[4 + i * 8 + j] = (char)0;
                 }
             }
             else
             {
                 buffer[4 + i * 8 + j] = (char)((int)pieceStates[i, j]);
             }
         }
     }
     if (_Reversi.GetCurrentPlayer() == _Player)
     {
         if (_Reversi.GetState() == ReversiState.NoAvailableSpaces)
         {
             buffer[4 + 64] = (char)10;
         }
         else if (((byte)_Reversi.GetState() & (byte)ReversiState.InProgress) != 0)
         {
             buffer[4 + 64] = (char)_Reversi.GetCurrentPlayer();
         }
         else
         {
             buffer[4 + 64] = (char)((int)_Reversi.GetState() + 1);
         }
     }
     else
     {
         if (((byte)_Reversi.GetState() & (byte)ReversiState.InProgress) != 0)
         {
             buffer[4 + 64] = (char)_Reversi.GetCurrentPlayer();
         }
         else
         {
             buffer[4 + 64] = (char)((int)_Reversi.GetState() + 1);
         }
     }
     buffer[4 + 65] = (char)_Reversi.GetDarkCount();
     buffer[4 + 66] = (char)_Reversi.GetLightCount();
     return(new string(buffer));
 }
Example #9
0
        protected void Move(Field moveableField)
        {
            if (moveableField.Piece != null)
            {
                if (moveableField.Piece.Color == Color)
                {
                    // Don't Move.
                    _moveableFields.Clear();
                    return;
                }
                // Kill the other piece.

                moveableField.Piece.Kill();
            }

            this._selected = false;

            this._hasMoved = true;

            ResourceManager.Instance.Fields[(int)_position.X, (int)_position.Y].Piece = null;

            moveableField.Piece = this;

            this._position = moveableField.Id;

            this._pixelPosition = moveableField.Rect.Location.ToVector2();

            PieceState pieceState = new PieceState(_id, _color, _position);

            NetworkManager.Instance.Self.SendChange(pieceState);


            _moveableFields.Clear();
        }
Example #10
0
    public void InitPlayArea()
    {
        Debug.Log("OthelloPieces Start InitPlayArea ");

        isMyTurn       = "false";
        isSelectLocked = false;
        pieces         = new Dictionary <string, PieceState> ();
        var layers = GameObject.FindGameObjectsWithTag("Layer");

        for (var k = 0; k < layers.Length; k++)
        {
            for (var i = 0; i < 8; i++)
            {
                for (var j = 0; j < 8; j++)
                {
                    //Debug.Log (layers[k].name + "-" + layers[k].transform.GetChild (i).name + "-" + layers[k].transform.GetChild (i).GetChild(j).name);
                    var key = layers [k].name + "-" + layers [k].transform.GetChild(i).name + "-" + layers [k].transform.GetChild(i).GetChild(j).name;

                    layers [k].transform.GetChild(i).GetChild(j).GetComponent <Renderer> ().material.color = baseColor.color;
                    layers [k].transform.GetChild(i).GetChild(j).GetComponent <BoxCollider> ().enabled     = false;

                    var pieceState = new PieceState(layers [k].transform.GetChild(i).GetChild(j).gameObject, baseColor, false);
                    pieces.Add(key, pieceState);
                }
            }
        }

        Debug.Log("OthelloPieces End InitPlayArea ");
    }
Example #11
0
 public void ResetBuffer(PieceState s)
 {
     if (twine != null)
     {
         twine.ShutDown();
         twine = null;
     }
     if (ice != null)
     {
         ice.ShutDown();
         ice = null;
     }
     if (coke)
     {
         coke = false;
         new TurnColor().Init(this.gameObject, .2f, defaultColor, null);
     }
     if (clock != null)
     {
         if (s == PieceState.Coke && !clock.triggered)
         {
             clock.Shake();
         }
         else
         {
             clock.ShutDown();
             clock = null;
         }
     }
 }
Example #12
0
    public GameBoardState Clone()
    {
        GameBoardState newGbs = new GameBoardState(this.levels, this.rows, this.cols);

        IGameBoardState igbs = this;

        for (int lvl = 0; lvl < (igbs.GetNumLevels()); lvl++)
        {
            for (int row = 0; row < (igbs.GetNumRows()); row++)
            {
                for (int col = 0; col < (igbs.GetNumCols()); col++)
                {
                    ISpaceState iss = igbs.GetSpaceState(lvl, row, col);
                    newGbs.spaces[lvl][row][col].occupied = iss.IsOccupied();
                    IPieceState ips = iss.Occupier();

                    if (ips != null)
                    {
                        PieceState ps = ips.CreatePieceState();
                        newGbs.spaces[lvl][row][col].occupier = ps;
                        newGbs.AlivePieces.Add(ps);
                        ps.space = newGbs.spaces[lvl][row][col];
                    }
                }
            }
        }

        foreach (IPieceState piece in DeadPieces)
        {
            newGbs.DeadPieces.Add(piece.CreatePieceState());
        }

        return(newGbs);
    }
Example #13
0
 public void SetState(PieceState state)
 {
     info       = state.info;
     this.state = state;
     GetComponent <SpriteRenderer>().sprite = state.info.sprite;
     transform.Rotate(Vector3.forward * 90 * state.rotation);
 }
Example #14
0
 public void SetState(List <BasePiece> allUnits, PieceState newstate) //also resets Bliss, Dance
 {
     foreach (BasePiece piece in allUnits)
     {
         piece.pieceState = newstate;
     }
 }
Example #15
0
    public void LerpToHighlightPosition()
    {
        float lerpSpeed = 0.7f;

        float xOffset = blocks[0].GetComponent <Drag>().matchedFillableTile.transform.position.x - blocks[0].transform.position.x;

        float yOffset = blocks[0].GetComponent <Drag>().matchedFillableTile.transform.position.y - blocks[0].transform.position.y;

        Vector2 towardsPostion = new Vector2(this.transform.position.x + xOffset, this.transform.position.y + yOffset);

        this.transform.position = Vector2.Lerp(this.transform.position, towardsPostion, lerpSpeed);

        // Lerp finished, piece stays in fillable area:
        if ((Vector2)this.transform.position == towardsPostion)
        {
            currentState = PieceState.inFill;

            /*
             * Should keep the fillableTile's matched blocks,
             * so these fillableTiles won't be matched again by other pieces
             */
            board.RemoveAllFillableHighlights();

            SetAllFillableOccupied();

            if (board.IsPuzzleSovled())
            {
                gameManager.LevelComplete();
            }
        }
    }
Example #16
0
    IEnumerator GoToSlot()
    {
        state = PieceState.MovingToSLot;

        rb.isKinematic      = true;
        rb.detectCollisions = false;

        while ((slot.pieceCenter.position - transform.position).sqrMagnitude > 0.0001)
        {
            transform.position = Vector3.Lerp(transform.position, slot.pieceCenter.position, 0.1f);
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.identity, 0.3f);
            yield return(0);
        }
        transform.position = slot.pieceCenter.position;
        transform.rotation = Quaternion.identity;

        rb.detectCollisions = true;
        rb.isKinematic      = false;

        meshRenderer.material = GameManager.gm.playersData[playerIndex].normalMat;

        state = PieceState.OnSlot;

        slot.SetPiece(this, slotOwnerMat);
    }
Example #17
0
    public void PutNewPostion(string posKey)
    {
        var piece      = pieces [posKey].piece;
        var pieceState = new PieceState(piece, player1Color, false);

        pieces [posKey] = pieceState;
        isMyTurn        = false.ToString();
    }
Example #18
0
    public bool IsEqual(PieceState pieceState)
    {
        if (team != pieceState.team || type != pieceState.type)
        {
            return(false);
        }

        return(true);
    }
Example #19
0
    private void Update()
    {
        if (_pieceState == PieceState.Resting)
        {
            return;                                    //do nothing if this piece is resting
        }
        if (_pieceState == PieceState.Exploding)
        {
            explodedTimeout -= Time.deltaTime;
            if (explodedTimeout <= 0)
            {
                Destroy(this.gameObject); //clear up some resorces after win
            }
        }



        switch (LevelStateMachine.Instance.state)
        {
        case LevelStateMachine.State.Idle:     //touching the screen makes the object fall toward the planet
            //foreach (Touch touch in Input.touches)
            //{
            //    if (touch.phase == TouchPhase.Began)
            //    {
            //        _pieceState = PieceState.Moving;
            //        LevelStateMachine.Instance.state = LevelStateMachine.State.Playing;
            //    }
            //}

            break;

        case LevelStateMachine.State.Playing:                          //We wait for the object to come to a rest
            if (rb.velocity.magnitude <= _acceptable_Resting_Velocity) //if the object is moving super slow we can pretty much say were resting
            {
                waitTime -= Time.deltaTime;
                if (waitTime <= 0)     //we waited long enough for movement, we are resting
                {
                    _pieceState = PieceState.Resting;
                    if (Physics2D.IsTouching(myCollider, GameAssets.Instance.limitInScene))     //check if we are touching the limit
                    {
                        LevelStateMachine.Instance.OnLose();
                    }
                    else
                    {
                        LevelStateMachine.Instance.ReadyNextPiece();
                    }
                }
            }
            else
            {
                waitTime = WaitTimeMax;     //reset timer if we suddenly move while attempting to rest
                _acceptable_Resting_Velocity += Time.deltaTime * 0.01f;
            }

            break;
        }
    }
Example #20
0
    /*! ピースを選択された	*/
    public void Catch()
    {
        mState = PieceState.SELECT;

        // 描画順を変える
        mRender.sortingOrder = 1;

        // 当たり判定のレイヤーを変える
        gameObject.layer = LayerMask.NameToLayer("Select");
    }
Example #21
0
    public void ReplacePieceOnSlot()
    {
        state = PieceState.BeingDestroyed;

        slot.hasPiece         = false;
        meshRenderer.material = GameManager.gm.playersData[playerIndex].lostMat;
        canvas.gameObject.SetActive(false);

        StartCoroutine(ReplacePieceOnSlotCoroutine());
    }
Example #22
0
    PieceState IPieceState.CreatePieceState()
    {
        PieceState ps = new PieceState();

        ps.Alive     = this.Alive;
        ps.pieceType = this.pieceType;
        ps.player    = this.player;

        return(ps);
    }
Example #23
0
        public void SetState(PieceState state)
        {
            if (!m_Initialized)
            {
                Awake();
            }

            if (state == PieceState.Preview)
            {
                SetMaterials(m_PreviewMat);

                foreach (var col in m_Colliders)
                {
                    if (col)
                    {
                        col.enabled = false;
                    }
                    else
                    {
                        Debug.LogError("A collider was found null in the collider list!", this);
                    }
                }

                foreach (var socket in m_Sockets)
                {
                    socket.gameObject.SetActive(false);
                }
            }
            else if (state == PieceState.Placed)
            {
                SetMaterials(m_InitialMaterials);

                foreach (var col in m_Colliders)
                {
                    col.enabled = true;
                }

                foreach (var socket in m_Sockets)
                {
                    socket.gameObject.SetActive(true);
                }

                if (m_CheckStability && AttachedOn != null)
                {
                    //print(AttachedOn);
                    var eventHandler = AttachedOn.GetComponent <EntityEventHandler>();
                    if (eventHandler != null)
                    {
                        eventHandler.Death.AddListener(On_SocketDeath);
                    }
                }
            }

            m_State = state;
        }
Example #24
0
    /*
     * METOD ADI :  SetUnColored
     * AÇIKLAMA  :  Piece objesini boyanmamış haline döndürür.
     */
    public void SetUnColored(bool nearMiss = false)
    {
        _meshRenderer.enabled = false;

        State = PieceState.UnColored;
        _uiManager.UpdateScoreText();
        if (nearMiss)
        {
            StartCoroutine(_uiManager.UpdateNearMissSlider());
        }
    }
Example #25
0
    public void Initialize(Slot slot)
    {
        this.slot = slot;
        slot.SetPiece(this, slotOwnerMat);
        rb = GetComponent <Rigidbody>();

        meshRenderer.material = GameManager.gm.playersData[playerIndex].normalMat;

        canvas.gameObject.SetActive(false);
        state = PieceState.OnSlot;
    }
Example #26
0
 public bool isSame(PieceState p)
 {
     for (int i = 0; i < 4; i++)
     {
         if (edge(i) != p.edge(i))
         {
             return(false);
         }
     }
     return(true);
 }
Example #27
0
    public void ReturnToInitPosition()
    {
        float lerpSpeed = 0.5f;

        this.transform.position = Vector2.Lerp(this.transform.position, initialPosition, lerpSpeed);

        // Returning finished:
        if ((Vector2)this.transform.position == initialPosition)
        {
            currentState = PieceState.origin;
        }
    }
Example #28
0
    public void MoveToBack()
    {
        row    = prevRow;
        column = prevColumn;

        moveToPos = new Vector2(prevRow, prevColumn);

        isTunning = true;

        currState = PieceState.MOVE;
        board.movedPieces.Add(this);
    }
Example #29
0
 public Piece(Vector3 pos, int x, int y, int z, int type)
 {
     //_frame = ResourceMgr.Instance.Game.Content.Load<Model>("arame");
     _interior         = ResourceMgr.Instance.Game.Content.Load <Model>("esfera");
     _3dPosition       = pos;
     _indexPosition[0] = x;
     _indexPosition[1] = y;
     _indexPosition[2] = z;
     _type             = type;
     _state            = PieceState.INSTABLE;
     _visited          = false;
     UpdateColor();
 }
Example #30
0
    /*
     * METOD ADI :  SetColored
     * AÇIKLAMA  :  Piece objesini boyanması işlemlerini yapar.
     */
    public void SetColored()
    {
        _meshRenderer.enabled = true;

        if (State == PieceState.UnColored)
        {
            State = PieceState.Colored;
            ScoreManager.Instance.AddScore();
            StartCoroutine(ScaleLerp());
        }
        _uiManager.UpdateScoreText();
        StageManager.Instance.RotateAndCheckCakePart();
    }
Example #31
0
    public void UndoMove()
    {
        if (States.Count > 0)
        {
            PieceState previousState = States[States.Count - 1];

            SquareIndex         = previousState.SquareIndex;
            PreviousSquareIndex = previousState.PreviousSquareIndex;
            MovedFirstTime      = previousState.MovedForTheFirstTime;

            States.RemoveAt(States.Count - 1);
        }
    }
Example #32
0
 public void SetState(PieceState state)
 {
     if (IsEmpty(this))
         throw new InvalidOperationException("Changing an empty objects state is not allowed");
     State = state;
 }
Example #33
0
 /*! ピースに指定の座標をセット
     @param	x		x軸
     @param	y		y軸
     @param	speed	移動速度
 */
 public void SetPosition(PiecePos pos, float speed)
 {
     mState = PieceState.MOVE;
     mMoveSpeed = speed;
     mPos = pos;
     mTargetPos = new Vector2(mPos.x * 1.05f, mPos.y * 1.05f);
 }
Example #34
0
    // Use this for initialization
    void Awake()
    {
        mAnime = GetComponent<Animator>();
        mRender = GetComponent<SpriteRenderer>();
        mMoveSpeed = 0;
        mTargetPos = new Vector2(0,0);
        mState = PieceState.STOP;

        mDead = false;
    }
Example #35
0
    /*! ピースを消す	*/
    private void DeathUpdate()
    {
        Vector3 s = transform.localScale;

        s = new Vector3(s.x - (0.1f * Time.deltaTime * 60), s.y - (0.1f * Time.deltaTime * 60), 1);
        transform.localScale = s;

        if (transform.localScale.x < 0.1f)
        {
            mDead = true;
            mState = PieceState.STOP;
        }
    }
Example #36
0
    /*! ピースの移動遷移	*/
    private void MoveUpdate()
    {
        Vector2 nowPos = transform.position;

        // ターゲットにたどり着いたらストップ
        if (nowPos == mTargetPos)
        {
            mState = PieceState.STOP;
            return;
        }

        mMoveSpeed ++;

        // x軸の移動
        if (nowPos.x != mTargetPos.x)
            nowPos.x = PieceMove(nowPos.x, mTargetPos.x, mMoveSpeed);

        // y軸の移動
        if (nowPos.y != mTargetPos.y)
            nowPos.y = PieceMove(nowPos.y, mTargetPos.y, mMoveSpeed);

        transform.position = nowPos;
    }
Example #37
0
    /* ピースを殺す	*/
    public void Death()
    {
        mState = PieceState.DEATH;

        // 描画順を変える
        mRender.sortingOrder = -1;

        // 当たり判定のレイヤーを変える
        gameObject.layer = LayerMask.NameToLayer("Default");
    }
Example #38
0
        public void SetPiece(int x, int y, PieceState state)
        {
            var piece = GetPiece(x, y);
            var dummy = new Piece(piece.X, piece.Y);
            dummy.SetState(state);

            // Throw an exception if the location has already been set
            if (piece.State != PieceState.Open)
                throw new ArgumentException("Location already set");

            // Throw an exception if placement is invalid
            if (!IsPlacingAllowed(dummy))
                throw new ArgumentException("The piece does not have any valid adjacent pieces");

            // Place the piece
            piece.SetState(state);

            // Turn connecting pieces
            var connectingPieces = GetValidConnectingPieces(piece);
            foreach (var p in connectingPieces)
            {
                p.SetState(state);
            }
        }
Example #39
0
 public bool Is(PieceState state)
 {
     return _state == state;
 }
Example #40
0
 public void Make(PieceState state)
 {
     _state = state;
     UpdateMaterial();
 }