LocalGameScript.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. public class LocalGameScript : MonoBehaviour
  7. {
  8. public Transform content;
  9. public GameObject playerInfoPrefab;
  10. public Button startButton;
  11. public Button deleteButton;
  12. private int gameId;
  13. private string gameMode;
  14. private int questionsNeededToWin;
  15. private int answerTimer;
  16. private int numberOfPlayers;
  17. private string currentPlayer;
  18. private string currentPlayerName;
  19. private int round;
  20. private string startDate;
  21. private string lastPlayedDate;
  22. private string finishedDate;
  23. private List<KeyValuePair<string, int>> players;
  24. public string CurrentPlayerName { get => currentPlayerName; set => currentPlayerName = value; }
  25. public string CurrentPlayer { get => currentPlayer; set => currentPlayer = value; }
  26. public int NumberOfPlayers { get => numberOfPlayers; set => numberOfPlayers = value; }
  27. public int AnswerTimer { get => answerTimer; set => answerTimer = value; }
  28. public int QuestionsNeededToWin { get => questionsNeededToWin; set => questionsNeededToWin = value; }
  29. public string GameMode { get => gameMode; set => gameMode = value; }
  30. public int GameId { get => gameId; set => gameId = value; }
  31. public int Round { get => round; set => round = value; }
  32. public string StartDate { get => startDate; set => startDate = value; }
  33. public string LastPlayedDate { get => lastPlayedDate; set => lastPlayedDate = value; }
  34. public string FinishedDate { get => finishedDate; set => finishedDate = value; }
  35. public List<KeyValuePair<string, int>> Players { get => players; set => players = value; }
  36. private void Start() {
  37. startButton.onClick.AddListener(StartThisGame);
  38. deleteButton.onClick.AddListener(DeleteThisGame);
  39. }
  40. public void AddPlayer(string name, int points) {
  41. if (players == null) {
  42. players = new List<KeyValuePair<string, int>>();
  43. }
  44. KeyValuePair<string, int> p = new KeyValuePair<string, int>(name, points);
  45. Players.Add(p);
  46. GameObject go = Instantiate(playerInfoPrefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
  47. PlayerInfo playerInfo = go.GetComponent<PlayerInfo>();
  48. playerInfo.SetName(name);
  49. playerInfo.SetPoints(points);
  50. playerInfo.transform.SetParent(content);
  51. playerInfo.transform.SetSiblingIndex(0);
  52. }
  53. public void StartThisGame() {
  54. Debug.Log("CLicked button to start game");
  55. PlayerPrefs.SetInt("GameId", GameId);
  56. SceneManager.LoadSceneAsync("narKampen");
  57. }
  58. public void DeleteThisGame() {
  59. Debug.Log("CLicked button to delete game");
  60. }
  61. }