Ejemplo n.º 1
0
    int Turn(bool isTurn)
    {
        ePieceState     AnotherColor = ((_NowPiece == ePieceState.Back) ? ePieceState.Front : ePieceState.Back);
        bool            Sandwich     = false;
        List <Position> PositionList = new List <Position>();
        int             count        = 0;

        for (int i = 0; i < 8; i++)
        {
            int deltaX = 0, deltaY = 0;
            int x = _CursorX;
            int y = _CursorY;
            deltaX  += Turn_Direction_X[i];
            deltaY  += Turn_Direction_Y[i];
            Sandwich = false;
            PositionList.Clear();
            while (true)
            {
                x += deltaX;
                y += deltaY;
                if (!(0 <= x && x < Field_Size_X && 0 <= y && y < Field_Size_Y))
                {
                    break;
                }

                if (_FieldPieceState[x, y] == AnotherColor)
                {
                    PositionList.Add(new Position(x, y));
                }
                else if (_FieldPieceState[x, y] == _NowPiece)
                {
                    Sandwich = true;
                    break;
                }
                else
                {
                    break;
                }
            }
            // ひっくり返し処理
            if (Sandwich)
            {
                count += PositionList.Count;
                if (isTurn)
                {
                    for (int j = 0; j < PositionList.Count; j++)
                    {
                        Position pos = PositionList[j];
                        _FieldPieceState[pos._x, pos._y] = _NowPiece;
                        _Piece[pos._x, pos._y].StartTurnAnimation();
                    }
                }
            }
        }
        return(count);
    }
Ejemplo n.º 2
0
    // 置ける場所の確認
    int CanTurnStone(int Ax, int Ay)
    {
        ePieceState AnotherColor = ((_NowPiece == ePieceState.Back) ? ePieceState.Front : ePieceState.Back);
        int         CanTurnPiece = 0;
        int         CanPutCount  = 0;

        if (_FieldPieceState[Ax, Ay] == ePieceState.None)
        {
            for (int i = 0; i < 8; i++)
            {
                int deltaX = 0, deltaY = 0;
                int x = Ax;
                int y = Ay;
                deltaX += Turn_Direction_X[i];
                deltaY += Turn_Direction_Y[i];
                while (true)
                {
                    x += deltaX;
                    y += deltaY;
                    if (!(0 <= x && x < Field_Size_X && 0 <= y && y < Field_Size_Y))
                    {
                        CanTurnPiece = 0;
                        break;
                    }

                    if (_FieldPieceState[x, y] == AnotherColor)
                    {
                        CanTurnPiece++;
                    }
                    else if (_FieldPieceState[x, y] == _NowPiece)
                    {
                        if (CanTurnPiece > 0)
                        {
                            CanPutCount++;
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        CanTurnPiece = 0;
                        break;
                    }
                }
            }
        }
        return(CanPutCount);
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene("TitleScene");
        }

        int dX = 0;
        int dY = 0;

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            dY += 1;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            dY -= 1;
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            dX += 1;
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            dX -= 1;
        }
        _CursorX += dX;
        _CursorY += dY;

        // オセロ盤から出ないように
        if (_CursorX < 0)
        {
            _CursorX = 0;
        }
        else if (_CursorX > 7)
        {
            _CursorX = 7;
        }

        if (_CursorY < 0)
        {
            _CursorY = 0;
        }
        else if (_CursorY > 7)
        {
            _CursorY = 7;
        }

        _CursorObject.transform.localPosition = new Vector3(_CursorX - 3.5f, 0.5f, _CursorY - 3.5f);

        if (Input.GetKeyDown(KeyCode.Return))
        {
            if (0 <= _CursorX && _CursorX < Field_Size_X && 0 <= _CursorY && _CursorY < Field_Size_Y && _FieldPieceState[_CursorX, _CursorY] == ePieceState.None && Turn(false) > 0)
            {
                _FieldPieceState[_CursorX, _CursorY] = _NowPiece;
                Turn(true);
                _NowPiece  = ((_NowPiece == ePieceState.Back) ? ePieceState.Front : ePieceState.Back);
                _Turn.text = ((_NowPiece == ePieceState.Back) ? BlackTurn : WhiteTurn);
            }
        }

        // ピースの状態反映
        UpdatePieceState();

        // 全て埋まれば終了
        UpdateFieldState();

        // 置ける場所がないとパス、2が返る
        PutCheck();
        if (PutCheck() == 2)
        {
            _NowPiece  = ((_NowPiece == ePieceState.Back) ? ePieceState.Front : ePieceState.Back);
            _Turn.text = ((_NowPiece == ePieceState.Back) ? BlackTurn : WhiteTurn);

            // 両方パスだと試合終了
            PutCheck();
            if (PutCheck() == 2)
            {
                GameOver();
            }
        }
    }