GameManagerScript.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class GameManagerScript : MonoBehaviour {
  6. private int playerCount;
  7. private int questionTimer;
  8. private string gameMode;
  9. public Database db;
  10. public OnlineDatabase odb;
  11. StatsScript statsScript;
  12. public string GameMode { get => gameMode; set => gameMode = value; }
  13. public int GameId { get; internal set; }
  14. public int QuestionTimer { get => questionTimer; set => questionTimer = value; }
  15. List<KeyValuePair<string, int>> players;
  16. // Start is called before the first frame update
  17. void Start() {
  18. GameId = PlayerPrefs.GetInt("GameId");
  19. GameMode = PlayerPrefs.GetString("GameMode");
  20. QuestionTimer = PlayerPrefs.GetInt("QuestionTimer");
  21. if (GameMode.Equals("Local")) {
  22. db = Database.Instance;
  23. db.SetLocalOrOnline(GameMode);
  24. db.SetLastPlayedDate(GameId);
  25. } else if (GameMode.Equals("Online")) {
  26. odb = OnlineDatabase.Instance;
  27. odb.SetLastPlayedDate(GameId);
  28. }
  29. statsScript = GameObject.Find("StatsPanel").GetComponent<StatsScript>();
  30. }
  31. private List<KeyValuePair<string,int>> GetPlayersForGame() {
  32. players = db.GetPlayersForGame(GameId, GameMode);
  33. return players;
  34. }
  35. public void UpdateQuestiosLost(int questionsLost, string playerName) {
  36. db.SetQuestionsLost(GameId, playerName, questionsLost);
  37. }
  38. public void UpdateQuestionsInAnswerLine(string playerName, int count) {
  39. }
  40. public List<KeyValuePair<string, int>> GetPlayers() {
  41. if (players == null) {
  42. players = GetPlayersForGame();
  43. }
  44. return players;
  45. }
  46. }