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.

101 lines
2.5 KiB

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