// Use this for initialization void Start() { int score = 0; int maxScore = 0; WorldScoreRecord scoreRecord = ChooseWorld.scoreRecord; // add up score foreach (KeyValuePair <string, WorldScore> worldItem in scoreRecord.worldScores) { WorldScore worldScore = worldItem.Value; foreach (KeyValuePair <string, SectionScore> sectionItem in worldScore.sectionScores) { SectionScore sectionScore = sectionItem.Value; foreach (KeyValuePair <string, LevelScore> levelItem in sectionScore.levelScores) { score = score + levelItem.Value.score; maxScore = maxScore + levelItem.Value.maxScore; } } } GameObject.Find("Canvas").transform .GetChild(0).gameObject.transform .GetChild(0) .GetComponent <Text>().text = "Total Score: " + score.ToString() + "/" + maxScore.ToString(); }
void AddScoreRecord() { var questionsList = JsonConvert.DeserializeObject <List <Question> >(questionJsonResponse); var num_question = questionsList.Count; // add section score to the score record string currentWorld = ChooseWorld.world.ToString(); string currentSection = ChooseWorld.section.ToString(); string currentLevel = ChooseWorld.level.ToString(); Debug.Log("adding score to record for world: " + currentWorld + ", section: " + currentSection + ", level: " + currentLevel); WorldScoreRecord scoreRecord = ChooseWorld.scoreRecord; // get WorldScore object if (!scoreRecord.worldScores.ContainsKey(currentWorld)) { scoreRecord.worldScores.Add(currentWorld, new WorldScore()); } WorldScore worldScoreRecord = scoreRecord.worldScores[currentWorld]; // get sectionScore object if (!worldScoreRecord.sectionScores.ContainsKey(currentSection)) { worldScoreRecord.sectionScores.Add(currentSection, new SectionScore()); } SectionScore sectionScoreRecord = worldScoreRecord.sectionScores[currentSection]; // add the level score sectionScoreRecord.levelScores.Add(currentLevel, new LevelScore(num_question, sectionScore)); }
public void OpenPanel(string world) { if (Panel != null) { Panel.SetActive(true); // set title Panel.transform.GetChild(0).gameObject.GetComponent <Text>().text = "World " + world; // set all values to N/A for (int i = 1; i < 10; i++) { Panel.transform.GetChild(i + 6).gameObject.GetComponent <Text>().text = "N/A"; } // set score WorldScoreRecord scoreRecord = ChooseWorld.scoreRecord; if (scoreRecord.worldScores.ContainsKey(world)) { int worldIndex = int.Parse(world); if (scoreRecord.worldScores.ContainsKey(worldIndex.ToString())) { WorldScore worldScore = scoreRecord.worldScores[worldIndex.ToString()]; for (int sectionIndex = 1; sectionIndex < 4; sectionIndex++) { if (worldScore.sectionScores.ContainsKey(sectionIndex.ToString())) { SectionScore sectionScore = worldScore.sectionScores[sectionIndex.ToString()]; for (int levelIndex = 1; levelIndex < 4; levelIndex++) { if (sectionScore.levelScores.ContainsKey(levelIndex.ToString())) { LevelScore levelScore = sectionScore.levelScores[levelIndex.ToString()]; // set the text on the panel int componentIndex = (sectionIndex - 1) * 3 + levelIndex + 6; Panel.transform.GetChild(componentIndex).gameObject.GetComponent <Text>().text = levelScore.score.ToString() + "/" + levelScore.maxScore.ToString(); } } } } } } } }
internal WorldScore GetTopTen(int?uid = 0) { WorldScore ret = new WorldScore(); ret.TopTen = new List <RankUser>(); ret.UId = uid.Value; List <User> allData = new List <User>(); using (bnbEntities ctx = new bnbEntities()) { allData = ctx.User.OrderByDescending(x => x.RankScore).ToList(); //ret.TopTen = } var maxCount = (allData.Count < 7) ? allData.Count : 7; for (int i = 0; i < maxCount; i++) { var item = ConvertUserToRank(allData[i]); item.Rank = i + 1; ret.TopTen.Add(item); } if (uid.HasValue && uid > 0) { ret.CurrentUserList = new List <RankUser>(); for (int i = 0; i < maxCount; i++) { if (allData[i].UId == uid.Value) { if (i == 0) { // for topper var item = ConvertUserToRank(allData[i]); item.Rank = i + 1; item.IsCurrentUser = true; ret.CurrentUserList.Add(item); for (int x = i + 1; x < i + 4; x++) { if (x < maxCount) { item = ConvertUserToRank(allData[x]); item.Rank = x + 1; ret.CurrentUserList.Add(item); } else { break; } } break; } else if (i == maxCount - 1) {// for last var item = ConvertUserToRank(allData[i]); for (int x = i - 4; x < i; x++) { if (x < maxCount) { item = ConvertUserToRank(allData[x]); item.Rank = x + 1; ret.CurrentUserList.Add(item); } else { break; } } item = ConvertUserToRank(allData[i]); item.Rank = i; item.IsCurrentUser = true; ret.CurrentUserList.Add(item); break; } else if (i > 0) {// for in bw var item = ConvertUserToRank(allData[i - 1]); item.Rank = i; ret.CurrentUserList.Add(item); item = ConvertUserToRank(allData[i]); item.Rank = i + 1; item.IsCurrentUser = true; ret.CurrentUserList.Add(item); for (int x = i + 1; x < i + 3; x++) { if (x < maxCount) { item = ConvertUserToRank(allData[x]); item.Rank = x + 1; ret.CurrentUserList.Add(item); } else { break; } } break; } } } } //int maxStars = ret.TopTen[0] return(ret); }