//セットするよ
    public void SetActiveNotes(int laneNum, JudgeState judge = JudgeState.none)
    {
        bool LongEnd = false;

        if (activeNotes[laneNum] != null)
        {
            NotesScript noteInfo = activeNotes[laneNum].GetComponent <NotesScript>();

            ScoreIndex noteType = noteInfo.type;

            switch (noteType)
            {
            case ScoreIndex.SIMPLE:
                Destroy(activeNotes[laneNum]);
                break;

            case ScoreIndex.LONG:
                if (judge == JudgeState.Bad)
                {
                    Destroy(activeNotes[laneNum]);
                }
                else
                {
                    LongEnd = true;
                }
                break;

            case ScoreIndex.LONG_END:
                Destroy(activeNotes[laneNum].transform.parent.gameObject);
                break;
            }
        }

        if (LongEnd)
        {
            activeNotes[laneNum] = activeNotes[laneNum].GetComponent <NotesScript>().LNendObj;
            return;
        }

        if (noteObjects[laneNum].Count != 0)
        {
            activeNotes[laneNum] = noteObjects[laneNum].Dequeue();
        }
        else
        {
            activeNotes[laneNum] = null;
        }
    }
    /// <summary>
    /// 譜面を作るんじゃい
    /// </summary>
    /// <param name="sr">StringReader</param>
    private void MakeMusic(StringReader sr, LoadMode mode = LoadMode.Normal)
    {
        //初期化
        Init_data_MusicScore();
        //元のデータね
        string data = sr.ReadToEnd();
        //1小節ごとに分けたデータ
        List <string> score_String = new List <string>();
        //これを入れていくよ
        string score_Bar    = null;
        bool   isCommentOut = false;

        for (int i = 0; i < data.Length; i++)
        {
            string str = data.Substring(i, 1);

            if (str == "\n" || str == "\r")
            {
                isCommentOut = false;
                continue;
            }

            if (isCommentOut)
            {
                continue;
            }

            if (str == " ")
            {
                continue;
            }

            if (str == "/")
            {
                if (data.Substring(i + 1, 1) == "/")
                {
                    isCommentOut = true;
                }
                continue;
            }

            if (str == "," || str == ";")
            {
                if (score_Bar != null)
                {
                    score_String.Add(score_Bar);
                    score_Bar = null;
                }
                continue;
            }

            score_Bar += str;
        }

        //譜面入れてくよ
        for (int bar = 0; bar < score_String.Count; bar++)
        {
            //--1小節ごと
            string barStr      = score_String[bar];
            int    barOriginTh = barStr.Length / data_KEY;
            originThs.Add(barOriginTh);

            Debug.Log(bar + ":" + bar * 4 + "-" + (bar * 4 + 3) + "=" + barOriginTh + "th");

            for (int num = 0; num < barStr.Length; num++)
            {
                //--1文字ごと
                string score = barStr.Substring(num, 1);
                int    key   = num % data_KEY;
                int    th    = (num - key) / data_KEY;
                foreach (KeyValuePair <ScoreIndex, string> pair in NotesDictionary)
                {
                    if (score == pair.Value)
                    {
                        ScoreIndex index = pair.Key;

                        //----- 無視処理 -----//
                        if (index == ScoreIndex.none)
                        {
                            break;
                        }

                        if (index == ScoreIndex.MINE)
                        {
                            notesData.MineNote++;
                            break;
                        }

                        //----- サブ処理 -----//

                        if (index == ScoreIndex.SIMPLE)
                        {
                            notesData.SimpleNote++;
                        }
                        else if (index == ScoreIndex.LONG_START)
                        {
                            notesData.LongNote++;
                        }

                        //----- 分岐 -----//

                        if (mode != LoadMode.Normal)
                        {
                            break;
                        }

                        //----- メイン処理 -----//

                        if (index == ScoreIndex.LONG_END)
                        {
                            data_MusicScore[key][data_MusicScore[key].Count - 1].type              = ScoreIndex.LONG;
                            data_MusicScore[key][data_MusicScore[key].Count - 1].LNend_bar         = bar;
                            data_MusicScore[key][data_MusicScore[key].Count - 1].LNend_th          = th;
                            data_MusicScore[key][data_MusicScore[key].Count - 1].LNend_barOriginTh = barOriginTh;
                            break;
                        }

                        NotesInfo note = new NotesInfo();

                        note.bar         = bar;
                        note.th          = th;
                        note.barOriginTh = barOriginTh;
                        note.type        = index;

                        data_MusicScore[key].Add(note);

                        //Debug.Log(note.type.ToString() + ":" + (note.bar + 1) + "小節目:" + (note.th + 1) + "分目");
                        break;
                    }
                }
            }
        }
    }
    public void InputKey(int laneNum, bool keyState)
    {
        if (activeNotes[laneNum] == null)
        {
            return;
        }

        NotesScript noteInfo = activeNotes[laneNum].GetComponent <NotesScript>();

        ScoreIndex type = noteInfo.type;

        if (keyState == false && type != ScoreIndex.LONG_END)
        {
            return;
        }

        float diff = noteInfo.notesTiming - move.time;

        float fixDiff = Mathf.Abs(diff);

        JudgeState state = JudgeState.none;

        //判定部分
        if (judgeWidth.JudgeTimings[judgeWidth.JudgeTimings.Length - 1] >= fixDiff)
        {
            for (int i = 0; i < judgeWidth.JudgeTimings.Length; i++)
            {
                if (judgeWidth.JudgeTimings[i] >= fixDiff)
                {
                    switch (i)
                    {
                    case 0:
                        state = JudgeState.Great;
                        break;

                    case 1:
                        state = JudgeState.Good;
                        break;

                    case 2:
                        state = JudgeState.Bad;
                        break;
                    }
                    break;
                }
            }
        }

        switch (type)
        {
        case ScoreIndex.SIMPLE:
            if (state == JudgeState.none)
            {
                break;
            }
            ScoreManager.instance.AddJudge(state, noteInfo, diff);
            SetActiveNotes(laneNum, state);
            break;

        case ScoreIndex.LONG:
            if (state == JudgeState.none)
            {
                break;
            }
            ScoreManager.instance.AddJudge(state, noteInfo, diff);
            SetActiveNotes(laneNum, state);
            break;

        case ScoreIndex.LONG_END:
            if (state == JudgeState.none)
            {
                state = JudgeState.Bad;
            }
            ScoreManager.instance.AddJudge(state, noteInfo, diff);
            SetActiveNotes(laneNum, state);
            break;
        }
    }
Exemple #4
0
        public async Task ScoreAsync(Score currentScore, Game currentGame, ScoreIndex scoreAs)
        {
            switch (scoreAs)
            {
            case ScoreIndex.Ones:
                if (currentScore.Ones != 0)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.Twos:
                if (currentScore.Twos != 0)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.Threes:
                if (currentScore.Threes != 0)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.Fours:
                if (currentScore.Fours != 0)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.Fives:
                if (currentScore.Fives != 0)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.Sixes:
                if (currentScore.Sixes != 0)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.ThreeOfAKind:
                if (currentScore.ThreeOfAKind != 0)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.FourOfAKind:
                if (currentScore.FourOfAKind != 0)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.FullHouse:
                if (!currentScore.FullHouse)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.SmallStreet:
                if (!currentScore.SmallStreet)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.LargeStreet:
                if (!currentScore.LargeStreet)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.Yahtzee:
                if (!currentScore.Yahtzee)
                {
                    throw new Exception();
                }
                break;

            case ScoreIndex.Chance:
                if (currentScore.Chance != 0)
                {
                    throw new Exception();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(scoreAs), scoreAs, null);
            }

            byte scoreAsIndex = (byte)(scoreAs - 1);

            switch (scoreAs)
            {
            case ScoreIndex.Ones:
                currentScore.Ones = currentGame.Dices.Sum(d => d.Value == 1 ? 1 : 0);
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.Twos:
                currentScore.Twos = currentGame.Dices.Sum(d => d.Value == 2 ? 2 : 0);
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.Threes:
                currentScore.Threes = currentGame.Dices.Sum(d => d.Value == 3 ? 3 : 0);
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.Fours:
                currentScore.Fours = currentGame.Dices.Sum(d => d.Value == 4 ? 4 : 0);
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.Fives:
                currentScore.Fives = currentGame.Dices.Sum(d => d.Value == 5 ? 5 : 0);
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.Sixes:
                currentScore.Sixes = currentGame.Dices.Sum(d => d.Value == 6 ? 6 : 0);
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.ThreeOfAKind:
            {
                (int diceA, int diceB, int diceC)dices = (0, 0, 0);
                currentScore.ThreeOfAKind = currentGame.Dices.Any(d =>
                                                                  currentGame.Dices.Any(e => d.Number != e.Number &&
                                                                                        currentGame.Dices.Any(f =>
                    {
                        var solution = d.Number != f.Number &&
                                       d.Value == e.Value &&
                                       d.Value == f.Value;
                        if (solution)
                        {
                            dices = (d.Number, e.Number, f.Number);
                        }
                        return(solution);
                    })
                                                                                        )
                                                                  )
                            ? currentGame.Dices.Sum(d => d.Value)
                            : 0;
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         ContainsDiceNo(dices, 1),
                                                                         ContainsDiceNo(dices, 2),
                                                                         ContainsDiceNo(dices, 3),
                                                                         ContainsDiceNo(dices, 4),
                                                                         ContainsDiceNo(dices, 5));

                break;
            }

            case ScoreIndex.FourOfAKind:
            {
                (int diceA, int diceB, int diceC, int diceD)dices = (0, 0, 0, 0);
                currentScore.FourOfAKind = currentGame.Dices.Any(d =>
                                                                 currentGame.Dices.Any(e => d.Number != e.Number &&
                                                                                       currentGame.Dices.Any(f => d.Number != f.Number &&
                                                                                                             currentGame.Dices.Any(g =>
                    {
                        var solution =
                            d.Number != g.Number &&
                            d.Value == e.Value &&
                            d.Value == f.Value &&
                            d.Value == g.Value;
                        if (solution)
                        {
                            dices = (d.Number, e.Number,
                                     f.Number, g.Number);
                        }
                        return(solution);
                    })
                                                                                                             )
                                                                                       )
                                                                 )
                            ? currentGame.Dices.Sum(d => d.Value)
                            : 0;
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         ContainsDiceNo(dices, 1),
                                                                         ContainsDiceNo(dices, 2),
                                                                         ContainsDiceNo(dices, 3),
                                                                         ContainsDiceNo(dices, 4),
                                                                         ContainsDiceNo(dices, 5));

                break;
            }

            case ScoreIndex.FullHouse:
            {
                (int diceA, int diceB, int diceC)dices = (0, 0, 0);
                currentScore.FullHouse = currentGame.Dices.Any(d =>
                                                               currentGame.Dices.Any(e => d.Number != e.Number &&
                                                                                     currentGame.Dices.Any(f => d.Number != f.Number &&
                                                                                                           currentGame.Dices.Any(g =>
                                                                                                                                 d.Number != g.Number &&
                                                                                                                                 currentGame.Dices.Any(h =>
                    {
                        var solution =
                            d.Number != h.Number &&
                            d.Value == e.Value &&
                            d.Value == f.Value &&
                            d.Value != g.Value &&
                            g.Value == h.Value;
                        if (solution)
                        {
                            dices = (d.Number, e.Number,
                                     f.Number);
                        }
                        return(solution);
                    })
                                                                                                                                 )
                                                                                                           )
                                                                                     )
                                                               );
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         ContainsDiceNo(dices, 1),
                                                                         ContainsDiceNo(dices, 2),
                                                                         ContainsDiceNo(dices, 3),
                                                                         ContainsDiceNo(dices, 4),
                                                                         ContainsDiceNo(dices, 5));

                break;
            }

            case ScoreIndex.SmallStreet:
                currentScore.SmallStreet = currentGame.Dices.Any(d =>
                                                                 currentGame.Dices.Any(e => d.Number != e.Number &&
                                                                                       currentGame.Dices.Any(f => d.Number != f.Number &&
                                                                                                             currentGame.Dices.Any(g => d.Number != g.Number &&
                                                                                                                                   d.Value == e.Value + 1 && d.Value == f.Value + 2 && d.Value == g.Value + 3))));
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.LargeStreet:
                currentScore.LargeStreet = currentGame.Dices.Any(d =>
                                                                 currentGame.Dices.Any(e => d.Number != e.Number &&
                                                                                       currentGame.Dices.Any(f => d.Number != f.Number &&
                                                                                                             currentGame.Dices.Any(g => d.Number != g.Number &&
                                                                                                                                   currentGame.Dices.Any(h => d.Number != h.Number &&
                                                                                                                                                         d.Value == e.Value + 1 && d.Value == f.Value + 2 && d.Value == g.Value + 3 && d.Value == h.Value + 4)))));
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.Yahtzee:
                currentScore.Yahtzee = currentGame.Dices.Any(d =>
                                                             currentGame.Dices.Any(e => d.Number != e.Number &&
                                                                                   currentGame.Dices.Any(f => d.Number != f.Number &&
                                                                                                         currentGame.Dices.Any(g => d.Number != g.Number &&
                                                                                                                               currentGame.Dices.Any(h => d.Number != h.Number &&
                                                                                                                                                     d.Value == e.Value && d.Value == f.Value && d.Value == g.Value && d.Value == h.Value)))));
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            case ScoreIndex.Chance:
                currentScore.Chance = currentGame.Dices.Sum(d => d.Value);
                await _service.AssignResultRequestAndWaitForReceiptAsync(scoreAsIndex,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false,
                                                                         false);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(scoreAs), scoreAs, null);
            }
        }