Example #1
0
        public void SaveIfRankIn(int scoreNum)
        {
            var scoreEntities = ScoreRepository.GetScoreEntities(Ranking.Size);
            var currentScore  = new Score(scoreNum);
            var ranking       = ScoreTranslator.TranslateAsRanking(scoreEntities);
            var rank          = ranking.GetRank(currentScore);
            var rankedIn      = rank != -1;

            if (!rankedIn)
            {
                return;
            }

            // TODO: 連結リストのほうが挿入が楽かな?
            var currentScoreEntity   = ScoreTranslator.TranslateAsScoreEntity(currentScore);
            var updatedScoreEntities = scoreEntities.ToList();

            updatedScoreEntities.Insert(rank, currentScoreEntity);
            ScoreRepository.SaveScore(updatedScoreEntities.Take(5).ToArray());

            Debug.Log("-----result-----");
            // TODO: remove debug log
            var result = ScoreRepository.GetScoreEntities(Ranking.Size);

            foreach (var r in result)
            {
                Debug.Log(r.ScoreNum);
            }
        }