Ejemplo n.º 1
0
    public int SearchSquare(int nowSquareIndex, Field.DIRECTION direction, int distance)
    {
        int index = 0;

        //それぞれの斜め移動によって左右移動と上下移動のアルゴリズムクラスを使う----------------------------------------
        switch (direction)
        {
        case Field.DIRECTION.LEFT_FORWARD:
            index = leftAndRightSearch.SearchSquare(nowSquareIndex, Field.DIRECTION.LEFT, distance);
            if (index == ConstantStorehouse.ERROR)
            {
                return(index);
            }
            index = forwardAndBackSearch.SearchSquare(index, Field.DIRECTION.FORWAED, distance);
            return(index);

        case Field.DIRECTION.RIGHT_FORWARD:
            index = leftAndRightSearch.SearchSquare(nowSquareIndex, Field.DIRECTION.RIGHT, distance);
            if (index == ConstantStorehouse.ERROR)
            {
                return(index);
            }
            index = forwardAndBackSearch.SearchSquare(index, Field.DIRECTION.FORWAED, distance);
            return(index);

        case Field.DIRECTION.LEFT_BACK:
            index = leftAndRightSearch.SearchSquare(nowSquareIndex, Field.DIRECTION.LEFT, distance);
            if (index == ConstantStorehouse.ERROR)
            {
                return(index);
            }
            index = forwardAndBackSearch.SearchSquare(index, Field.DIRECTION.BACK, distance);
            return(index);

        case Field.DIRECTION.RIGHT_BACK:
            index = leftAndRightSearch.SearchSquare(nowSquareIndex, Field.DIRECTION.RIGHT, distance);
            if (index == ConstantStorehouse.ERROR)
            {
                return(index);
            }
            index = forwardAndBackSearch.SearchSquare(index, Field.DIRECTION.BACK, distance);
            return(index);

        default:
            return(ConstantStorehouse.ERROR);
        }
        //--------------------------------------------------------------------------------------------------------------
    }
Ejemplo n.º 2
0
    const int ONE_SQUIRREL = 1;         //左右に進むときの1マスの大きさ

    public int SearchSquare(int nowSquareIndex, Field.DIRECTION direction, int distance)
    {
        int index = 0;

        //それぞれの段の右端のマスのIndex
        int firstRowFirstIndex  = ConstantStorehouse.SQUARE_ROW_NUM * ConstantStorehouse.FIRST_ROW_INDEX;
        int secondRowFirstIndex = ConstantStorehouse.SQUARE_ROW_NUM * ConstantStorehouse.SECOND_ROW_INDEX;
        int thirdRowFirstIndex  = ConstantStorehouse.SQUARE_ROW_NUM * ConstantStorehouse.THIRD_ROW_INDEX;
        int fourthRowFirstIndex = ConstantStorehouse.SQUARE_ROW_NUM * ConstantStorehouse.FOURTH_ROW_INDEX;
        int fifthRowFirstIndex  = ConstantStorehouse.SQUARE_ROW_NUM * ConstantStorehouse.FIFTH_ROW_INDEX;

        //それぞれの段の左端のマスのIndex
        int firstRowLastIndex  = firstRowFirstIndex + (ConstantStorehouse.SQUARE_ROW_NUM - 1);
        int secondRowLastIndex = secondRowFirstIndex + (ConstantStorehouse.SQUARE_ROW_NUM - 1);
        int thirdRowLastIndex  = thirdRowFirstIndex + (ConstantStorehouse.SQUARE_ROW_NUM - 1);
        int fourthRowLastIndex = fourthRowFirstIndex + (ConstantStorehouse.SQUARE_ROW_NUM - 1);
        int fifthRowLastIndex  = fifthRowFirstIndex + (ConstantStorehouse.SQUARE_ROW_NUM - 1);

        switch (direction)
        {
        case Field.DIRECTION.LEFT:
            index = nowSquareIndex - ONE_SQUIRREL * distance;

            //今いる段の左端よりIndexが低くなったら-1を返す---------------------------------------------------------------------------------------------------------
            if ((nowSquareIndex >= firstRowFirstIndex && nowSquareIndex <= firstRowLastIndex) && index < firstRowFirstIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            if ((nowSquareIndex >= secondRowFirstIndex && nowSquareIndex <= secondRowLastIndex) && index < secondRowFirstIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            if ((nowSquareIndex >= thirdRowFirstIndex && nowSquareIndex <= thirdRowLastIndex) && index < thirdRowFirstIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            if ((nowSquareIndex >= fourthRowFirstIndex && nowSquareIndex <= fourthRowLastIndex) && index < fourthRowFirstIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            if ((nowSquareIndex >= fifthRowFirstIndex && nowSquareIndex <= fifthRowLastIndex) && index < fifthRowFirstIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            //------------------------------------------------------------------------------------------------------------------------------------------------------

            return(index);

        case Field.DIRECTION.RIGHT:
            index = nowSquareIndex + ONE_SQUIRREL * distance;

            //今いる段の右端よりIndexが大きくなったら-1を返す------------------------------------------------------------------------------------------------------
            if ((nowSquareIndex >= firstRowFirstIndex && nowSquareIndex <= firstRowLastIndex) && index > firstRowLastIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            if ((nowSquareIndex >= secondRowFirstIndex && nowSquareIndex <= secondRowLastIndex) && index > secondRowLastIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            if ((nowSquareIndex >= thirdRowFirstIndex && nowSquareIndex <= thirdRowLastIndex) && index > thirdRowLastIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            if ((nowSquareIndex >= fourthRowFirstIndex && nowSquareIndex <= fourthRowLastIndex) && index > fourthRowLastIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            if ((nowSquareIndex >= fifthRowFirstIndex && nowSquareIndex <= fifthRowLastIndex) && index > fifthRowLastIndex)
            {
                return(ConstantStorehouse.ERROR);
            }
            //-----------------------------------------------------------------------------------------------------------------------------------------------------

            return(index);

        default:
            return(ConstantStorehouse.ERROR);
        }
    }
Ejemplo n.º 3
0
    //--CSVからカードデータを読み込む関数
    void LoadFromCSV(string csvFimeName)
    {
        TextAsset       csvTextAsset       = (TextAsset)Resources.Load("CSV/" + csvFimeName);   //CSVファイルをTextAssetとして読み込む
        StringReader    stringReader       = new StringReader(csvTextAsset.text);               //csvTextAssetのテキストを読むStringReaderを生成
        List <string[]> csvStringArrayList = new List <string[]> ();                            //CSVの各値を列ごとにstring配列で格納するための変数

        //カンマごとに区切って配列へ格納-------------------
        while (stringReader.Peek() > -1)
        {
            string line = stringReader.ReadLine();
            csvStringArrayList.Add(line.Split(','));
        }
        //------------------------------------------------
        //CSVのデータを_cardDatasへ格納-------------------------------------------------------
        for (int i = 0; i < csvStringArrayList.Count; i++)
        {
            if (i > 0)                //i==0は各項目名なので除く
            {
                CardData cardData = new CardData();
                cardData._id           = int.Parse(csvStringArrayList [i] [0]);
                cardData._attack       = int.Parse(csvStringArrayList [i] [1]);
                cardData._maxToughness = int.Parse(csvStringArrayList [i] [2]);
                cardData._toughness    = cardData._maxToughness;
                //CSVデータからList<Field.DIRECTION>を作る--------------------------------------------
                int directionOfTravelData = int.Parse(csvStringArrayList [i] [3]);
                List <Field.DIRECTION> directionOfTravelList = new List <Field.DIRECTION> ();
                while (directionOfTravelData != 0)
                {
                    Field.DIRECTION fieldDirection = (Field.DIRECTION)(directionOfTravelData % 10);
                    directionOfTravelList.Add(fieldDirection);
                    directionOfTravelData /= 10;
                }
                //-----------------------------------------------------------------------------------
                cardData._directionOfTravel = directionOfTravelList;
                cardData._effect_type       = (CardData.EFFECT_TYPE) int.Parse(csvStringArrayList [i] [4]);
                cardData._effect_value      = int.Parse(csvStringArrayList [i] [5]);
                //CSVデータからList<Field.DIRECTION>を作る--------------------------------------------
                int effectDirectionData = int.Parse(csvStringArrayList [i] [6]);
                List <Field.DIRECTION> effectDirecionList = new List <Field.DIRECTION> ();
                while (effectDirectionData != 0)
                {
                    Field.DIRECTION fieldDirection = (Field.DIRECTION)(effectDirectionData % 10);
                    effectDirecionList.Add(fieldDirection);
                    effectDirectionData /= 10;
                }
                //------------------------------------------------------------------------------------
                cardData._effect_direction     = effectDirecionList;
                cardData._effect_distance      = int.Parse(csvStringArrayList [i] [7]);
                cardData._necessaryMP          = int.Parse(csvStringArrayList [i] [8]);
                cardData._necessaryAP          = int.Parse(csvStringArrayList [i] [9]);
                cardData._necessaryAPForEffect = int.Parse(csvStringArrayList [i] [10]);
                //一度改行部分で分割して再び結合させる(改行させるため)--------------------------
                string[] cardTextList = csvStringArrayList [i] [11].Split(';');
                string   cardText     = "";
                for (int j = 0; j < cardTextList.Length; j++)
                {
                    cardText += cardTextList [j];
                    if (j < cardTextList.Length - 1)
                    {
                        cardText += "\n";                        //これで改行させる
                    }
                }
                cardData._textString = cardText;
                //----------------------------------------------------------------------------
                _cardDatas.Add(cardData);
            }
        }
        //------------------------------------------------------------------------------------
    }