You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using Multiplayer;
  6. public class GameMode : MonoBehaviour {
  7. //references to all players
  8. List<GameObject> Players = new List<GameObject>();
  9. public Recipe recipe;
  10. GameObject LocalPlayer;
  11. public CharacterMovement charMove;
  12. public GameObject timer;
  13. public GameObject winCanvas;
  14. public GameObject loseCanvas;
  15. private void Start()
  16. {
  17. LocalPlayer = Multiplayer.PlayersManager.Instance.LocalPlayer;
  18. Players.Add(LocalPlayer);
  19. foreach (GameObject curPlayer in Multiplayer.PlayersManager.Instance.RemotePlayers.Values)
  20. {
  21. Players.Add(curPlayer);
  22. }
  23. }
  24. private void OnEnable()
  25. {
  26. ClientManager.Instance.Client.RegisterHandler(PlayerMsgID.GameWin,GameWin);
  27. ClientManager.Instance.Client.RegisterHandler(PlayerMsgID.GameOver, GameLose);
  28. }
  29. private void OnDisable()
  30. {
  31. ClientManager.Instance.Client.UnregisterHandler(PlayerMsgID.GameWin);
  32. ClientManager.Instance.Client.UnregisterHandler(PlayerMsgID.GameOver);
  33. }
  34. void Update()
  35. {
  36. //CheckValues();
  37. if (charMove.CheckNearby())
  38. {
  39. recipe.CheckVictory();
  40. }
  41. }
  42. public void EndGame()
  43. {
  44. Multiplayer.ClientManager.Instance.SendMessage(Multiplayer.PlayerMsgID.Lobby);
  45. }
  46. public void PreGameWin()
  47. {
  48. ClientManager.Instance.SendMessage(PlayerMsgID.GameWin);
  49. }
  50. public void PreGameLose()
  51. {
  52. ClientManager.Instance.SendMessage(PlayerMsgID.GameOver);
  53. }
  54. public void GameWin(NetworkMessage msg)
  55. {
  56. winCanvas.SetActive(true);
  57. timer.SetActive(false);
  58. }
  59. public void GameLose(NetworkMessage msg)
  60. {
  61. loseCanvas.SetActive(true);
  62. timer.SetActive(false);
  63. }
  64. /*
  65. //Check the values for player to see if it changes the minimum or maximum values of all players
  66. void CheckValues()
  67. {
  68. float maxDistance = 0;
  69. foreach(GameObject gamePlayer in Players)
  70. {
  71. float distance = (transform.position - gamePlayer.transform.position).magnitude;
  72. Player playerScript = gamePlayer.GetComponent<Player>();
  73. foreach (GameObject dummy in playerScript.dummies)
  74. {
  75. float newDis = (transform.position - gamePlayer.transform.position).magnitude;
  76. if (newDis < distance)
  77. {
  78. distance = newDis;
  79. }
  80. }
  81. if (distance > maxDistance)
  82. {
  83. maxDistance = distance;
  84. }
  85. }
  86. if (maxDistance < DistanceToWin)
  87. {
  88. if (recipe.CheckVictory())
  89. {
  90. //Win Game here
  91. }
  92. }
  93. }
  94. */
  95. }