| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class StatsScript : MonoBehaviour {
- public GameObject statsNames;
- public GameObject statsValues;
- public GameObject statsLinePrefab;
- private Text[] statsTextNames;
- private Text[] statsTextValues;
- private List<StatsLine> statLines = new List<StatsLine>();
- GameManagerScript gms;
- private void Start() {
- gms = GameObject.Find("GameManager").GetComponent<GameManagerScript>();
- CreateStandardStats();
- AddPlayersToStats(gms.GetPlayers());
- }
- private void CreateStandardStats() {
- StatsLine round = CreateStatLine();
- round.SetStatName("Round");
- int roundValue = gms.GetDatabase().GetRoundValue(gms.GameId);
- round.SetStatValue(roundValue.ToString());
- round.name = "roundStat";
- StatsLine lostQuestions = CreateStatLine();
- lostQuestions.SetStatName("Questions lost");
- lostQuestions.SetStatValue("0");
- lostQuestions.name = "questionsLost";
- StatsLine playerTitle = CreateStatLine();
- playerTitle.SetStatName("Players");
- playerTitle.SetStatValue("");
- playerTitle.MakeBold();
- statLines.Add(round);
- statLines.Add(lostQuestions);
- statLines.Add(playerTitle);
- }
- private StatsLine CreateStatLine() {
- GameObject slp = Instantiate(statsLinePrefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
- StatsLine statLine = slp.GetComponent<StatsLine>();
- statLine.transform.SetParent(this.transform);
- return statLine;
- }
- public void AddPlayersToStats(List<KeyValuePair<string, int>> players) {
- foreach (KeyValuePair<string, int> player in players) {
- StatsLine p = CreateStatLine();
- p.SetStatName(player.Key);
- p.SetStatValue(player.Value.ToString());
- statLines.Add(p);
- }
- }
- public void IncreaseRoundValue() {
- foreach (StatsLine sl in statLines) {
- if (sl.GetName().Equals("Round")) {
- Int32.TryParse(sl.GetValue(), out int round);
- round++;
- sl.SetStatValue(round.ToString());
- break;
- }
- }
- }
- public void MakeBold(string playerName) {
- foreach (StatsLine sl in statLines) {
- if (sl.GetName().Equals(playerName)) {
- sl.MakeBold();
- } else {
- sl.UnBold();
- }
- }
- }
- public void SetQuestionsInAnswerLine(string playerName, int count) {
- foreach (StatsLine sl in statLines) {
- if (sl.GetName().Equals(playerName)) {
- sl.SetStatValue(count.ToString()) ;
- break;
- }
- }
- return;
- }
- }
|