LocalGameScript.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public Text numberOfPlayersText;
  13. public Text neededToWinText;
  14. public Text roundText;
  15. public Text dateStartedText;
  16. public Text lastPlayedText;
  17. public Text finishedDateText;
  18. private int answerTimer;
  19. private string gameMode;
  20. private string currentPlayer;
  21. private string currentPlayerName;
  22. private int gameId;
  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 string NumberOfPlayers { get => numberOfPlayersText.text; set => numberOfPlayersText.text = value; }
  27. public int AnswerTimer { get => answerTimer; set => answerTimer = value; }
  28. public string QuestionsNeededToWin { get => neededToWinText.text; set => neededToWinText.text = value; }
  29. public string GameMode { get => gameMode; set => gameMode = value; }
  30. public int GameId { get => gameId; set => gameId = value; }
  31. public string Round { get => roundText.text; set => roundText.text = value; }
  32. public string StartDate { get => dateStartedText.text; set => dateStartedText.text = value; }
  33. public string LastPlayedDate { get => lastPlayedText.text; set => lastPlayedText.text = value; }
  34. public string FinishedDate { get => finishedDateText.text; set => finishedDateText.text = 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. }