public Row Fetch(FetchDirection direction, int offset)
        {
            Evaluate();

            if (Result == null)
            {
                return(null);
            }

            if (direction != FetchDirection.Absolute &&
                direction != FetchDirection.Relative &&
                offset > -1)
            {
                throw new ArgumentException("Cannot set the offset for a non-relative and non-absolute fetch direction.");
            }

            int realOffset;

            if (direction == FetchDirection.Next)
            {
                realOffset = currentOffset + 1;
            }
            else if (direction == FetchDirection.Prior)
            {
                realOffset = currentOffset - 1;
            }
            else if (direction == FetchDirection.First)
            {
                realOffset = 0;
            }
            else if (direction == FetchDirection.Last)
            {
                realOffset = Result.RowCount - 1;
            }
            else if (direction == FetchDirection.Absolute)
            {
                realOffset = offset;
            }
            else if (direction == FetchDirection.Relative)
            {
                realOffset = offset + currentOffset;
            }
            else
            {
                throw new ArgumentException();
            }

            if (realOffset >= Result.RowCount || realOffset < 0)
            {
                Status = CursorStatus.Closed;
                return(null);
            }

            var row = Result.GetRow(realOffset);

            currentOffset = realOffset;
            Status        = CursorStatus.Fetching;

            return(row);
        }
Beispiel #2
0
 internal DjondbCursor(Command cmd, string cursorId, BSONArrayObj arr)
 {
     // TODO: Complete member initialization
     this._command  = cmd;
     this._cursorId = cursorId;
     this._rows     = arr;
     if (_rows == null)
     {
         _rows = new BSONArrayObj();
     }
     this._pos     = 0;
     this._current = null;
     if (this._rows == null)
     {
         this._count = 0;
     }
     else
     {
         this._count = this._rows.Count;
     }
     if (cursorId != null)
     {
         this._status = CursorStatus.CS_LOADING;
     }
     else
     {
         this._status = CursorStatus.CS_RECORDS_LOADED;
     }
 }
        public void Reset()
        {
            ReleaseReferences();

            Status        = CursorStatus.Open;
            currentOffset = -1;
            Result        = null;
            evaluated     = false;
        }
    public void SetCursorStatus(CursorStatus cursorStatus)
    {
        this.cursorStatus = cursorStatus;

        if (this.cursorStatus == CursorStatus.EMPTY)
        {
            cursor.SetActive(true);
        }
        else
        {
            cursor.SetActive(true);
        }
    }
 public TestPlayAreaServie()
 {
     // 固定値
     this._playAreaSize = new Matrix(12, 6);
     this.BorderLine    = 100;
     // 更新ごとに変動  簡単な値の変化
     this.ElapseFrame = 0;
     this.ScrollLine  = 0;
     this.ScrollPer   = 0;
     // 更新ごとに変動  大事な値
     this._cellArray             = new RectangleArray <CellInfo>(18, 6);
     this._cursorStatus          = new CursorStatus(PlayAreaSize.Row, PlayAreaSize.Column - 1);
     _cursorStatus.Matrix.Row    = 0;
     _cursorStatus.Matrix.Column = 0;
     this._swapArray             = new RectangleArray <Matrix?>(CellArray.Matrix);
     // セルの初期化
     _cellArray[0, 0] = RedCell;
 }
    void Awake()
    {
        cursorStatus = CursorStatus.EMPTY;

        cursor = Instantiate(cursorPrefab, GameObject.Find("/Canvas/Board").transform);
        cursor.transform.localScale = new Vector3(50, 50, 0);
        playerObject = GameObject.Find("/Player");
        player       = playerObject.GetComponent <Player> ();
        if (player.playerRole == GridSpaceStatus.SHEEP)
        {
            cursor.GetComponent <SpriteRenderer> ().sprite = sheep;
        }
        else
        {
            cursor.GetComponent <SpriteRenderer> ().sprite = wolf;
        }

        cursor.SetActive(true);
    }
Beispiel #7
0
        public void Update(TouchLocation tc)
        {
            PrevPosition = Position;
            Position     = tc.Position;

            Vector2 velocity = new Vector2(Math.Min(Math.Abs(Position.X - PrevPosition.X), 45), Math.Min(Math.Abs(Position.Y - PrevPosition.Y), 30));

            if (HeldCard != null && Position.Y <= HeldCard.Pos.Y && Status != CursorStatus.Grabbed)
            {
                Status         = CursorStatus.Grabbed;
                HeldCard.Scale = new Vector2(0.25f, 0.25f);
            }

            if (HeldCard != null && Status == CursorStatus.Grabbed)
            {
                HeldCard.Pos = Position;

                _game.tweener.TweenTo(HeldCard, c => c.Scale, (Vector2.One * 0.25f) - (velocity * .0025f), 0.1f, 0f);
            }
        }
Beispiel #8
0
        private bool InternalNext()
        {
            if (_status == CursorStatus.CS_CLOSED)
            {
                throw new ApplicationException("Cursor is Closed");
            }
            bool result = true;

            if (_count > _pos)
            {
                _current = _rows[_pos];
                _pos++;
            }
            else
            {
                if (_status == CursorStatus.CS_LOADING)
                {
                    BSONArrayObj page = _command.FetchRecords(_cursorId);
                    if (page == null)
                    {
                        _status = CursorStatus.CS_RECORDS_LOADED;
                        result  = false;
                    }
                    else
                    {
                        _rows.Add(page);
                        _count += page.Count;
                        result  = InternalNext();
                    }
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
Beispiel #9
0
 static void setCursor(CursorSprite cs, CursorStatus css)
 {
     setSpriteAlpha(cs.sprite, css.alpha);
     setSpriteScale(cs.sprite, css.scale);
     setSpriteRotation(cs.sprite, css.rotation);
 }
Beispiel #10
0
 static void setCursor(CursorSprite cs, CursorStatus csfrom, CursorStatus csto, float f)
 {
     setSpriteAlpha(cs.sprite, Mathf.Lerp(csfrom.alpha, csto.alpha, f));
     setSpriteScale(cs.sprite, Mathf.Lerp(csfrom.scale, csto.scale, f));
     setSpriteRotation(cs.sprite, Mathf.Lerp(csfrom.rotation, csto.rotation, f));
 }
 private void DisableCursor()
 {
     Cursor.lockState = CursorLockMode.Confined;
     Cursor.visible   = false;
     _status          = CursorStatus.diseable;
 }
Beispiel #12
0
    // Update is called once per frame
    void Update()
    {
        if (KeySetManager.GetKeyDown("Menu"))
        {
            Cursor.visible = !Cursor.visible;
        }
        newpos = Input.mousePosition;
        if (oldpos.z > -500)
        {
            diff = newpos - oldpos;
        }
        oldpos             = newpos;
        r.anchoredPosition = new Vector2(newpos.x, newpos.y);

        switch (switchStatus)
        {
        case 0: {
            float mouseSpeed = diff.magnitude;

            mouseSpeed = (mouseSpeed * currentType.moveThreshold - 3f * currentType.recoverThreshold) / 170f;
            currSpeed  = Mathf.Clamp(currSpeed + mouseSpeed, 0f, 1f);

            if (currentType.enabledMovement)
            {
                int i = 0;
                foreach (CursorSprite csp in currentType.cursorSprites)
                {
                    if (csp.cursorStatus.Length > 0)
                    {
                        setCursor(csp, csp.cursorStatus[0], currSpeed);
                    }
                    CursorStatus tmp = new CursorStatus();
                    tmp.scale            = csp.sprite.transform.localScale.x;
                    tmp.alpha            = csp.sprite.GetComponent <SpriteRenderer>().material.color.a;
                    tmp.rotation         = csp.sprite.transform.localEulerAngles.z;
                    switchStartStatus[i] = tmp;
                    i++;
                }
            }

            // 切换光标
            // if (Input.GetKeyDown(KeyCode.Z)) {
            //     switchType(cursor_test);
            // }
            // if (Input.GetKeyDown(KeyCode.C)) {
            //     switchType(cursor_aim);
            // }
        } break;

        case 1: {
            switchTimeSec++;
            float f = Mathf.Clamp((float)switchTimeSec * Time.deltaTime / switchTime, 0f, 1f);
            f = Easing.EaseIn(f, EasingType.Quartic);
            for (int i = 0; i < currentType.cursorSprites.Length; i++)
            {
                setCursor(currentType.cursorSprites[i], switchStartStatus[i], switchTo, f);
            }
            if (switchTimeSec > (float)switchTime / Time.deltaTime)
            {
                switchStatus  = 2;
                switchTimeSec = 0;
                setCursorTypeActive(currentType, false);
                switchTo.rotation = -switchTo.rotation;
                currentType       = nextType;
            }
        } break;

        case 2: {
            switchTimeSec++;
            float f = Mathf.Clamp((float)switchTimeSec * Time.deltaTime / switchTime, 0f, 1f);
            f = Easing.EaseOut(f, EasingType.Quartic);

            for (int i = 0; i < currentType.cursorSprites.Length; i++)
            {
                setCursor(currentType.cursorSprites[i], switchTo, currentType.cursorSprites[i].initStatus, f);
            }
            if (switchTimeSec > (float)switchTime / Time.deltaTime)
            {
                switchStatus      = 0;
                switchTimeSec     = 0;
                switchTo.rotation = -switchTo.rotation;
                nextType          = null;
            }
        } break;
        }
        //Input.mousePosition
    }
        private String FilterTags(String text)
        {
            StringBuilder filteredText = new StringBuilder();
            // StringBuilder hrefValue = null;
            int  len = text.Length, i;
            int  tagBegin = 0; //, attribBegin = 0;
            bool doubleQuotedAttributeValue = false;
            // bool cacheHRefValue = false;
            CursorStatus cs      = CursorStatus.OutsideTag;
            String       tagName = String.Empty;

            for (i = 0; i < len; i++)
            {
                switch (text[i])
                {
                case '<':
                {
                    switch (cs)
                    {
                    case CursorStatus.OutsideTag:
                    {
                        cs       = CursorStatus.InsideTagName;
                        tagBegin = i;
                        break;
                    }
                    }
                    break;
                }

                case '=':
                {
                    switch (cs)
                    {
                    case CursorStatus.InsideAttributeName:
                    {
                        // cacheHRefValue = text.Substring(attribBegin, i-attribBegin).Trim().ToUpper() == "HREF";
                        // hrefValue = null;
                        cs = CursorStatus.ExpectingAttributeValue;
                        break;
                    }

                    case CursorStatus.OutsideTag:
                    {
                        filteredText.Append(text[i]);
                        break;
                    }
                    }
                    break;
                }

                case '"':
                {
                    switch (cs)
                    {
                    case CursorStatus.ExpectingAttributeValue:
                    {
                        cs = CursorStatus.InsideAttributeValue;
                        doubleQuotedAttributeValue = true;
                        //if (cacheHRefValue)
                        //{
                        //    hrefValue = new StringBuilder("\"");
                        //}
                        break;
                    }

                    case CursorStatus.InsideAttributeValue:
                    {
                        //if (cacheHRefValue)
                        //{
                        //    hrefValue.Append('"');
                        //}
                        if (text[i - 1] != '\\' && doubleQuotedAttributeValue)
                        {
                            // leaving attribute value
                            cs = CursorStatus.InsideAttributeName;
                            // attribBegin = i;
                            break;
                        }
                        break;
                    }

                    case CursorStatus.OutsideTag:
                    {
                        filteredText.Append(text[i]);
                        break;
                    }
                    }
                    break;
                }

                case '\'':
                {
                    switch (cs)
                    {
                    case CursorStatus.ExpectingAttributeValue:
                    {
                        cs = CursorStatus.InsideAttributeValue;
                        //if (cacheHRefValue)
                        //{
                        //    hrefValue = new StringBuilder("'");
                        //}
                        doubleQuotedAttributeValue = false;
                        break;
                    }

                    case CursorStatus.InsideAttributeValue:
                    {
                        //if (cacheHRefValue)
                        //{
                        //    hrefValue.Append('\'');
                        //}
                        if (text[i - 1] != '\\' && !doubleQuotedAttributeValue)
                        {
                            // leaving attribute value
                            cs = CursorStatus.InsideAttributeName;
                            // attribBegin = i;
                            break;
                        }
                        break;
                    }

                    case CursorStatus.OutsideTag:
                    {
                        filteredText.Append(text[i]);
                        break;
                    }
                    }
                    break;
                }

                case '/':
                {
                    switch (cs)
                    {
                    case CursorStatus.InsideTagName:
                    {
                        tagName = text.Substring(tagBegin + 1, i - tagBegin - 1).Trim().ToUpper(CultureInfo.InvariantCulture);

                        if (tagName.Trim().Length > 0)
                        {
                            cs = CursorStatus.InsideAttributeName;
                            // attribBegin = i;
                        }
                        break;
                    }

                    case CursorStatus.OutsideTag:
                    {
                        filteredText.Append(text[i]);
                        break;
                    }
                    }
                    break;
                }

                case '>':
                {
                    switch (cs)
                    {
                    case CursorStatus.InsideTagName:
                    case CursorStatus.InsideAttributeName:
                    case CursorStatus.ExpectingAttributeValue:
                    {
                        // leaving tag
                        if (cs == CursorStatus.InsideTagName)
                        {
                            tagName = text.Substring(tagBegin + 1, i - tagBegin - 1).Trim().ToUpper(CultureInfo.InvariantCulture);
                        }
                        cs = CursorStatus.OutsideTag;
                        switch (tagName)
                        {
                        case "A":
                        {
                            //filteredText.Append(String.Format("<A HREF={0}>",
                            //    hrefValue == null ? String.Empty : hrefValue.ToString()));
                            filteredText.Append("<A HREF=\"\">");
                            break;
                        }

                        case "/A":
                        case "B":
                        case "/B":
                        case "BR":
                        case "/BR":
                        case "I":
                        case "/I":
                        case "P":
                        case "/P":
                        {
                            filteredText.Append("<" + tagName + ">");
                            break;
                        }
                        }
                        tagName = String.Empty;
                        break;
                    }

                    case CursorStatus.OutsideTag:
                    {
                        filteredText.Append(text[i]);
                        break;
                    }
                    }
                    break;
                }

                default:
                {
                    if (Char.IsWhiteSpace(text[i]))
                    {
                        switch (cs)
                        {
                        case CursorStatus.OutsideTag:
                        {
                            filteredText.Append(text[i]);
                            break;
                        }

                        case CursorStatus.InsideTagName:
                        {
                            cs = CursorStatus.InsideAttributeName;
                            // attribBegin = i;
                            tagName = text.Substring(tagBegin + 1, i - tagBegin - 1).Trim().ToUpper(CultureInfo.InvariantCulture);
                            break;
                        }
                        }
                    }
                    else
                    {
                        switch (cs)
                        {
                        case CursorStatus.OutsideTag:
                        {
                            filteredText.Append(text[i]);
                            break;
                        }
                        }
                    }
                    break;
                }
                }
            }

            return(filteredText.ToString());
        }
Beispiel #14
0
    public void ButtonClick()
    {
        GameObject       scripts          = GameObject.Find("/Scripts");
        Player           player           = GameObject.Find("/Player").GetComponent <Player> ();
        CursorController cursorController = scripts.GetComponent <CursorController> ();

        clearSignalAlowedGspace = false;


        CursorStatus cursorStatus = cursorController.GetCursorStatus();

        // The playerRole is a GridSpaceStatus to easily check if the clicked GridSpace can be moved by the player.
        if (cursorStatus == CursorStatus.EMPTY && player.playerRole == this.gridSpaceStatus && !AITurn)
        {
            // Pick up current piece
            //print("---"+ GetGridSpaceStatus());

            cursorController.SetCursorStatus(CursorStatus.OCCUPIED);
            this.SetGridSpaceStatus(GridSpaceStatus.EMPTY);
            lastpickedUp = this.gridSpaceNumber;
            print("picked up");
            if (signalDroped == true)
            {
                signalDroped = false;
                // signalpicked = true;
            }
        }
        //print sheep positions

        /*print("sheep1Position: " + sheep1Position);
        *  print("sheep2Position: " + sheep2Position);
        *  print("sheep3Position: " + sheep3Position);
        *  print("sheep4Position: " + sheep4Position);*/



        /*print(alowedGridSpaceses.Count);
         * print("0--0");*/
        for (int i = 0; i < alowedGridSpaceses.Count; i++)
        {
            // print("alowedGridSpaceses[" + i + "]: " + alowedGridSpaceses[i]);
        }

        for (int i = 0; i < alowedGridSpacesSheep.Count; i++)
        {
            // print("alowedGridSpacesSheep[" + i + "]: " + alowedGridSpacesSheep[i]);
        }

        for (int i = 0; i < mmAlowedGridSpacesSheep.Count; i++)
        {
            // print("mmAlowedGridSpacesSheep[" + i + "]: " + mmAlowedGridSpacesSheep[i]);
        }



        for (int i = 0; i < alowedGridSpaceses.Count; i++)
        {
            if (cursorStatus == CursorStatus.OCCUPIED)
            {
                if (this.gridSpaceStatus == GridSpaceStatus.EMPTY &&
                    alowedGridSpaceses[i] == foxPosition && player.playerRole == GridSpaceStatus.WOLF
                    )
                {
                    // Drop Piece if allowed
                    // print("Count = " + i);
                    // print("FoxPOsition = " + foxPosition);
                    // print(this.GetGridSpaceNumber());

                    cursorController.SetCursorStatus(CursorStatus.EMPTY);

                    this.SetGridSpaceStatus(player.playerRole);
                    if (player.playerRole == GridSpaceStatus.WOLF)
                    {
                        AITurn = true;
                    }


                    print("Case 0");
                }
            }
        }


        for (int i = 0; i < currentAlowedGridSpacesSheep.Count; i++)
        {
            //print(alowedGridSpacesSheep[i]);
            if (cursorStatus == CursorStatus.OCCUPIED)
            {
                //sheep1
                if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && sheep1 == true)
                {
                    if (sheep1OldPos != GridSpaceStatus.SHEEP)
                    {
                        if (currentAlowedGridSpacesSheep[i] == this.gridSpaceNumber)
                        {
                            cursorController.SetCursorStatus(CursorStatus.EMPTY);
                            this.SetGridSpaceStatus(player.playerRole);
                            if (player.playerRole == GridSpaceStatus.SHEEP)
                            {
                                AITurn = true;
                            }

                            clearSignalAlowedGspace = true;
                            signalDroped            = true;
                            sheep1Position          = this.gridSpaceNumber;
                            // print("SHEEEEEEP POSSS1 !" + sheep1Position);
                            // print("SHEEEEEEP POSSS2 !" + sheep2Position);
                            // print("SHEEEEEEP POSSS3 !" + sheep3Position);
                            // print("SHEEEEEEP POSSS4 !" + sheep4Position);
                        }
                    }
                }

                // sheep 2
                if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && sheep2 == true)
                {
                    if (sheep2OldPos != GridSpaceStatus.SHEEP)
                    {
                        if (currentAlowedGridSpacesSheep[i] == this.gridSpaceNumber)
                        {
                            cursorController.SetCursorStatus(CursorStatus.EMPTY);
                            this.SetGridSpaceStatus(player.playerRole);
                            if (player.playerRole == GridSpaceStatus.SHEEP)
                            {
                                AITurn = true;
                            }
                            clearSignalAlowedGspace = true;
                            signalDroped            = true;
                            sheep2Position          = this.gridSpaceNumber;
                            // print("SHEEEEEEP POSSS1 !" + sheep1Position);
                            // print("SHEEEEEEP POSSS2 !" + sheep2Position);
                            // print("SHEEEEEEP POSSS3 !" + sheep3Position);
                            // print("SHEEEEEEP POSSS4 !" + sheep4Position);
                        }
                    }
                }

                //sheep 3
                if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && sheep3 == true)
                {
                    if (sheep3OldPos != GridSpaceStatus.SHEEP)
                    {
                        if (currentAlowedGridSpacesSheep[i] == this.gridSpaceNumber)
                        {
                            cursorController.SetCursorStatus(CursorStatus.EMPTY);
                            this.SetGridSpaceStatus(player.playerRole);
                            if (player.playerRole == GridSpaceStatus.SHEEP)
                            {
                                AITurn = true;
                            }
                            clearSignalAlowedGspace = true;
                            signalDroped            = true;
                            sheep3Position          = this.gridSpaceNumber;
                            // print("SHEEEEEEP POSSS1 !" + sheep1Position);
                            // print("SHEEEEEEP POSSS2 !" + sheep2Position);
                            // print("SHEEEEEEP POSSS3 !" + sheep3Position);
                            // print("SHEEEEEEP POSSS4 !" + sheep4Position);
                        }
                    }
                }
                //sheep4
                if (this.gridSpaceStatus == GridSpaceStatus.EMPTY && sheep4 == true)
                {
                    if (sheep4OldPos != GridSpaceStatus.SHEEP)
                    {
                        if (currentAlowedGridSpacesSheep[i] == this.gridSpaceNumber)
                        {
                            cursorController.SetCursorStatus(CursorStatus.EMPTY);
                            this.SetGridSpaceStatus(player.playerRole);
                            if (player.playerRole == GridSpaceStatus.SHEEP)
                            {
                                AITurn = true;
                            }
                            clearSignalAlowedGspace = true;
                            signalDroped            = true;
                            sheep4Position          = this.gridSpaceNumber;
                            // print("SHEEEEEEP POSSS1 !" + sheep1Position);
                            // print("SHEEEEEEP POSSS2 !" + sheep2Position);
                            // print("SHEEEEEEP POSSS3 !" + sheep3Position);
                            // print("SHEEEEEEP POSSS4 !" + sheep4Position);
                        }
                    }
                }
            }
        }
    }
Beispiel #15
0
        /* プレイエリアのセルの処理とか
         * 1.ユーザーの操作
         * 2.スクロールする(しないときもある)
         *      ここでせり上がる時に一番上にセルがあればゲームオーバー
         * 3.左下から、右に、上に向かって、セルの状態変化(移動/変化)
         * 4.お邪魔セルの落下
         */
        /// <summary>
        ///   ゲームの状態を1フレーム更新する
        /// </summary>
        /// <param name="userOperation">ユーザーの操作</param>
        private void GameRule(UserOperation userOperation)
        {
            // 移動したセル配列の初期化
            _swapArray = SwapArray.CopyAndReset(null);

            //==============================スクロールする==============================
            // ScrollLine が BorderLine を超えているか?(1段上に上げるか?)
            PushedUp = ScrollLine >= BorderLine;
            // スクロール待機中なら、待機フレーム数を1減らしてスクロールしない
            if (_scrollWaitFrame > 0)
            {
                _scrollWaitFrame--;
            }
            else
            {
                // ゲームオーバーか?
                if (GameOverJudge())
                {
                    return;
                }
                // スクロールする
                ScrollLine += ScrollSpeed;
                if (PushedUp)
                {
                    ScrollLine = 0;
                    // セルを1段上に上げる
                    for (var row = PlayAreaSize.Row - 2; row >= -1; row--)
                    {
                        for (var col = 0; col < PlayAreaSize.Column; col++)
                        {
                            _cellArray[row + 1, col] = CellArray[row, col];
                        }
                    }
                    // カーソルを1段上に上げる
                    var cr = CursorStatus;
                    var mr = cr.Matrix;
                    mr.Row++;   // ホントはここがしたいだけ
                    cr.Matrix    = mr;
                    CursorStatus = cr;
                    // 一番下(Row-1)のセルをランダムに追加する
                    for (int col = 0; col < PlayAreaSize.Column; col++)
                    {
                        var cell = CellArray[-1, col];
                        cell.CellType       = CellInfo.RandomCellType(n: 0);
                        _cellArray[-1, col] = cell;
                    }
                }
            }
            //==============================ユーザーの操作==============================
            switch (userOperation)
            {
            case UserOperation.Swap:      // カーソルの位置のセルを入れ替える
                // カーソルの位置のセルを取得
                var cursorCellL = CellArray[CursorStatus.Matrix.Row, CursorStatus.Matrix.Column];
                var cursorCellR = CellArray[CursorStatus.Matrix.Row, CursorStatus.Matrix.Column + 1];

                // 両方Emptyなら入れ替える必要がないので入れ替えない
                if (cursorCellL.CellType is CellType.Empty && cursorCellR.CellType is CellType.Empty)
                {
                    break;
                }

                // カーソル位置のセルのどちらも移動可能(両方空なら上で弾かれる)
                if (!cursorCellL.CellType.IsOjama() && cursorCellL.Status is CellState.Free &&
                    !cursorCellR.CellType.IsOjama() && cursorCellR.Status is CellState.Free)
                {
                    SwapCell(CursorStatus.Matrix.Row, CursorStatus.Matrix.Column,
                             CursorStatus.Matrix.Row, CursorStatus.Matrix.Column + 1);
                }
                break;

            case UserOperation.ScrollSpeedUp:
                // TODO: スクロール速度が上昇する
                break;

            default:
                break;
            }
            // カーソルの状態を更新する
            CursorStatus = CursorStatus.Update(userOperation);


            //==============================セルの状態を更新する==============================

            /* ・更新順序
             * 1. セルの状態更新
             * 2. 今回のフレームで入れ替わる
             *    (入れ替え or 落下。入れ替わったセルは SwapArray の対応した場所にインデックスが入る)
             * 3. セルの消滅、変身
             *    * 消滅セルを検査する
             *    * 変身するお邪魔セルを検査する
             *    * 消滅、変身するセルの状態をセットする
             */
            //======================セルの状態更新
            //========全てのセルを更新
            for (int row = 0; row < CellArray.Row; row++)
            {
                for (int col = 0; col < CellArray.Column; col++)
                {
                    var cell = CellArray[row, col];
                    cell.Update();
                    _cellArray[row, col] = cell;
                }
            }
            //==========セルの落下
            for (int row = 1; row < CellArray.Row; row++)
            {
                for (int col = 0; col < CellArray.Column; col++)
                {
                    // TODO: お邪魔の落下

                    // 自分のセルが Not(種類:ノーマル or 状態:Free)
                    if (!CellArray[row, col].CellType.IsNomal() || CellArray[row, col].Status is not CellState.Free)
                    {
                        continue;
                    }

                    var bottomCell = CellArray[row - 1, col];
                    // 下のセルが 種類:空 かつ 状態:Free
                    if (bottomCell.CellType is CellType.Empty && bottomCell.Status is CellState.Free)
                    {
                        // 自分と下のセルを入れ替えて、落下を起こす
                        SwapCell(row, col, row - 1, col, isSwap: false);
                    }
                }
            }
            //==========================セルの消滅、変身
            var listD = new List <(int row, int col, CellInfo)>();   // お邪魔。変身するセルを格納する

            var searchAry = new RectangleArray <bool>(PlayAreaSize);
            // 横列走査
            var funcRow = new Func <Matrix, Matrix>(m => { m.Column++; return(m); });

            for (int row = 0; row < searchAry.Row; row++)
            {
                Serch(res: ref searchAry, func: funcRow, beforeCell: CellInfo.Empty, chain: 0, new Matrix(row, 0));
            }
            // 縦列走査
            var funcCol = new Func <Matrix, Matrix>(m => { m.Row++; return(m); });

            for (int col = 0; col < searchAry.Column; col++)
            {
                Serch(res: ref searchAry, func: funcCol, beforeCell: CellInfo.Empty, chain: 0, new Matrix(0, col));
            }


            // TODO: 変身するお邪魔セル走査


            //// 重複を取り除いて、row の降順 col の昇順に並び替え
            //listC = listC.Distinct().OrderByDescending(c => c.row).ThenBy(c => c.col).ToList();

            // 消滅するセルを、消滅するように仕向ける
            int cnt = 0;                        // 消滅セル数    (左上から順番にカウント)
            int sum = searchAry.Count(b => b);  // 消滅セル数合計

            for (int row = searchAry.Row - 1; row >= 0; row--)
            {
                for (int col = 0; col < searchAry.Column; col++)
                {
                    if (!searchAry[row, col])
                    {
                        continue;
                    }
                    var cell = CellArray[row, col];
                    // 状態遷移タイマーのセット
                    cell.StateTimer = (flashTime, cnt *momentTime + 2, (sum - cnt) * momentTime);
                    // セルの状態をフラッシュに
                    cell.Status          = CellState.Flash;
                    _cellArray[row, col] = cell;
                    cnt++;
                }
            }
        }
Beispiel #16
0
    public void ButtonClick()
    {
        GameObject     scripts        = GameObject.Find("/Scripts");
        GameController gameController = scripts.GetComponent <GameController> ();

        if (gameController.GetPlayerTurn() == false)
        {
            return;
        }

        Player           player           = GameObject.Find("/Player").GetComponent <Player> ();
        CursorController cursorController = scripts.GetComponent <CursorController> ();
        CursorStatus     cursorStatus     = cursorController.GetCursorStatus();

        // The playerRole is a GridSpaceStatus to easily check if the clicked GridSpace can be moved by the player.
        if (cursorStatus == CursorStatus.EMPTY && player.playerRole == this.gridSpaceStatus)
        {
            // Pick up current piece
            cursorController.SetCursorStatus(CursorStatus.OCCUPIED);
            cursorController.setPreviousLocation(this.gridSpaceNumber);
            this.SetGridSpaceStatus(GridSpaceStatus.EMPTY);

            // Color the tiles where a player can put the piece.
            switch (player.playerRole)
            {
            case GridSpaceStatus.WOLF:
                if (PieceOnLeftEdge(gridSpaceNumber) == true)
                {
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber - 7);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 9);
                }
                else if (PieceOnRightEdge(gridSpaceNumber) == true)
                {
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber - 9);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 7);
                }
                else
                {
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber - 7);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber - 9);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 7);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 9);
                }
                break;

            case GridSpaceStatus.SHEEP:
                if (PieceOnLeftEdge(gridSpaceNumber) == true)
                {
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 9);
                }
                else if (PieceOnRightEdge(gridSpaceNumber) == true)
                {
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 7);
                }
                else
                {
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 7);
                    gameController.SetGridSpaceAvailableColor(gridSpaceNumber + 9);
                }
                break;

            default:
                Debug.LogError("PlayerRole set to UNKNOWN. Check Player.cs and MainMenu.cs");
                break;
            }
        }

        if (cursorStatus == CursorStatus.OCCUPIED)
        {
            switch (player.playerRole)
            {
            case GridSpaceStatus.WOLF:
                if (PieceOnLeftEdge(cursorController.getPreviousLocation()))
                {
                    if (
                        this.gridSpaceNumber == cursorController.getPreviousLocation() ||
                        this.gridSpaceNumber == (cursorController.getPreviousLocation() - 7) ||
                        this.gridSpaceNumber == (cursorController.getPreviousLocation() + 9)
                        )
                    {
                        if (this.gridSpaceStatus != GridSpaceStatus.SHEEP)
                        {
                            PlacePiece(cursorController, gameController, player);
                            gameController.SetWolfPosition(this.gridSpaceNumber);
                        }
                    }
                }
                else if (PieceOnRightEdge(cursorController.getPreviousLocation()))
                {
                    if (
                        this.gridSpaceNumber == cursorController.getPreviousLocation() ||
                        this.gridSpaceNumber == (cursorController.getPreviousLocation() - 9) ||
                        this.gridSpaceNumber == (cursorController.getPreviousLocation() + 7)
                        )
                    {
                        if (this.gridSpaceStatus != GridSpaceStatus.SHEEP)
                        {
                            PlacePiece(cursorController, gameController, player);
                            gameController.SetWolfPosition(this.gridSpaceNumber);
                        }
                    }
                }
                else
                {
                    if (
                        this.gridSpaceNumber == cursorController.getPreviousLocation() ||
                        this.gridSpaceNumber == (cursorController.getPreviousLocation() - 7) ||
                        this.gridSpaceNumber == (cursorController.getPreviousLocation() - 9) ||
                        this.gridSpaceNumber == (cursorController.getPreviousLocation() + 7) ||
                        this.gridSpaceNumber == (cursorController.getPreviousLocation() + 9)
                        )
                    {
                        if (this.gridSpaceStatus != GridSpaceStatus.SHEEP)
                        {
                            PlacePiece(cursorController, gameController, player);
                            gameController.SetWolfPosition(this.gridSpaceNumber);
                        }
                    }
                }
                break;

            case GridSpaceStatus.SHEEP:
                if (this.gridSpaceStatus != GridSpaceStatus.WOLF)
                {
                    if (PieceOnLeftEdge(cursorController.getPreviousLocation()))
                    {
                        if (
                            this.gridSpaceNumber == cursorController.getPreviousLocation() ||
                            this.gridSpaceNumber == (cursorController.getPreviousLocation() + 9)
                            )
                        {
                            PlacePiece(cursorController, gameController, player);
                        }
                    }
                    else if (PieceOnRightEdge(cursorController.getPreviousLocation()))
                    {
                        if (
                            this.gridSpaceNumber == cursorController.getPreviousLocation() ||
                            this.gridSpaceNumber == (cursorController.getPreviousLocation() + 7)
                            )
                        {
                            PlacePiece(cursorController, gameController, player);
                        }
                    }
                    else
                    {
                        if (
                            this.gridSpaceNumber == cursorController.getPreviousLocation() ||
                            this.gridSpaceNumber == (cursorController.getPreviousLocation() + 7) ||
                            this.gridSpaceNumber == (cursorController.getPreviousLocation() + 9)
                            )
                        {
                            PlacePiece(cursorController, gameController, player);
                        }
                    }
                }
                break;

            default:
                Debug.LogError("PlayerRole set to UNKNOWN. Check Player.cs and MainMenu.cs");
                break;
            }
        }
    }
        /// <summary>プレイエリアを1フレーム分更新する</summary>
        /// <param name="userOperation">ユーザーの操作</param>
        public void InputKey(UserOperation userOperation)
        {
            // 更新時の最初の処理  フレーム1増加
            ElapseFrame++;

            /* ゲームアップデートの順序
             * 1. ユーザーの操作
             *    * カーソル位置移動
             *    * セルの入れ替え
             * 2. スクロール
             *    * IF ちょうど1段上がったなら、
             *      * セルを全て1段上に上げる
             *      * Row:-1 の段にセルを生成する
             *      * カーソルの位置を1段上に上げる
             * 3. セルの状態の更新
             *    1. 全てのセルの状態を更新する
             *       * StateTimer のカウントを減らす
             *    2. セルの落下
             *    3. 消滅するセルの検査
             *       1. 消滅するセルは、StateTiemr をセットする
             *       2. お邪魔とかいろいろ…
             */
            // ユーザーの操作
            _cursorStatus = CursorStatus.Update(userOperation);
            // スクロール
            ScrollLine += 2;                         // スクロールする
            if (PushedUp = ScrollLine >= BorderLine) // ちょうど1段スクロールした
            {
                ScrollLine = 0;                      // スクロールラインを戻す
                s++;
                // 全てのセルを1段上げる
                for (var row = PlayAreaSize.Row - 2; row >= -1; row--)
                {
                    for (var col = 0; col < PlayAreaSize.Column; col++)
                    {
                        _cellArray[row + 1, col] = CellArray[row, col];
                    }
                }
                // カーソルを1段上げる
                // カーソルを1段上に上げる
                var cr = CursorStatus; var mr = cr.Matrix;
                mr.Row++;   // ホントはここがしたいだけ
                cr.Matrix = mr; _cursorStatus = cr;
            }
            ScrollPer        = ScrollLine / BorderLine; // 現在のスクロール割合
            _swapArray[s, 0] = null;
            _swapArray[s, 1] = null;
            // セルの状態更新
            if (B)  // 左から右
            {
                _cellArray[s, 0] = _cellArray[s, 0].Update();
                if (_cellArray[s, 0].StateTimer.Lock == 0)
                {
                    var cell = _cellArray[s, 0];
                    cell.StateTimer  = (0, 0, 10);
                    cell.Status      = CellState.Lock;
                    _cellArray[s, 1] = cell;
                    _swapArray[s, 0] = new(s, 1);
                    B = false;
                }
            }
            else    // 右から左
            {
                _cellArray[s, 1] = _cellArray[s, 1].Update();
                if (_cellArray[s, 1].StateTimer.Lock == 0)
                {
                    var cell = _cellArray[s, 1];
                    cell.StateTimer  = (0, 0, 10);
                    cell.Status      = CellState.Lock;
                    _cellArray[s, 0] = cell;
                    _swapArray[s, 1] = new(s, 0);
                    B = true;
                }
            }

            // 最後に、更新したよ~って言う
            Updated(this, EventArgs.Empty);
        }
 private void EnubleCursor()
 {
     Cursor.lockState = CursorLockMode.None;
     Cursor.visible   = true;
     _status          = CursorStatus.enuble;
 }
Beispiel #19
0
    private void MouseBehaviour()
    {
        // Update Cursor Position
        mousePosition = Input.mousePosition;
        Vector3 position = cam.ScreenToWorldPoint(new Vector3(mousePosition.x, mousePosition.y, cam.nearClipPlane + 0.01f));

        cursorObject.Position = position;

        // Check Mouse Hover
        Ray ray = cam.ScreenPointToRay(mousePosition);

        if (!isClicked)
        {
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (currTossingObject == null)
                {
                    currTossingObject = hit.transform.GetComponent <TossingObject>();
                    if (currTossingObject != null)
                    {
                        currTossingObject.Hover();
                    }
                }
            }
            else
            {
                if (currTossingObject != null)
                {
                    currTossingObject.HoverExit();
                    currTossingObject = null;
                }
            }
            isHovered = (currTossingObject != null);
        }

        // Mouse Click & Tossing Events
        if (isHovered && Input.GetMouseButtonDown(0))
        {
            isClicked = true;
            currTossingObject.OnGrab(position + ray.direction * 0.5f);
        }
        if (isClicked)
        {
            currTossingObject.StayGrab(position + ray.direction * 0.5f);
            StoreMouseDirections();
            if (Input.GetMouseButtonUp(0))
            {
                isClicked = false;
                Vector3 throwForce    = mouseDirectionFromVec2(MouseThrowingForce(5)) * force_throwing;
                float   spinningSpeed = MouseSpinningSpeed(mouseDirectionsMaxNumber) * force_spining;
                Debug.Log("[Throw] force: " + throwForce + ", spin: " + spinningSpeed);
                currTossingObject.Throw(throwForce, spinningSpeed);
                currTossingObject = null;
                CleanupMouseDirections();
            }
        }

        // Update Status
        if (isClicked)
        {
            currCursorStatus = CursorStatus.Clicked;
        }
        else
        {
            currCursorStatus = (isHovered) ? CursorStatus.Hover : CursorStatus.Normal;
        }

        // Update Cursor
        if (currCursorStatus != currCursorStatus_cached)
        {
            currCursorStatus_cached = currCursorStatus;
            switch (currCursorStatus)
            {
            case CursorStatus.Normal:
                cursorObject.UpdateCursor(0.3f, ColorsLibrary.inst.Grey);
                break;

            case CursorStatus.Hover:
                cursorObject.UpdateCursor(0.3f, ColorsLibrary.inst.Green);
                break;

            case CursorStatus.Clicked:
                cursorObject.UpdateCursor(0.8f, ColorsLibrary.inst.White);
                break;
            }
        }
    }