Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class HelloWorld : MonoBehaviour {
  5.  
  6. int minValue = 1;
  7. int maxValue = 1000;
  8.  
  9. int min;
  10. int max;
  11. int guess;
  12. bool finish;
  13.  
  14. int lastnumber;
  15.  
  16. void Start () {
  17. NewGame();
  18. //Debug.Log("Hello World");
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update () {
  23. GameControl();
  24. }
  25.  
  26. void GameControl()
  27. {
  28. //Guessing
  29. if (!finish)
  30. {
  31. if (Input.GetKeyDown(KeyCode.UpArrow))
  32. {
  33. if(guess == maxValue)
  34. {
  35. Debug.Log("You have reach maximum number");
  36. return;
  37. }
  38. lastnumber = guess;
  39. min = guess;
  40. guess = (min + max) / 2;
  41. //Debug.Log("You have press Up Arrow");
  42. Debug.Log("Your number is : " + guess + " ?");
  43. Debug.Log("If higher press Up Arrow if lower press Down Arrow");
  44. Debug.Log("================================");
  45. FixNotReachMax();
  46. }
  47. else if (Input.GetKeyDown(KeyCode.DownArrow))
  48. {
  49. if(guess == minValue)
  50. {
  51. Debug.Log("You have reach minimum number");
  52. }
  53. lastnumber = guess;
  54. max = guess;
  55. guess = (min + max) / 2;
  56. //Debug.Log("You have press Down Arrow");
  57. Debug.Log("Your number is : " + guess + " ?");
  58. Debug.Log("If higher press Up Arrow if lower press Down Arrow");
  59. Debug.Log("================================");
  60. }
  61. //Ending Guess
  62. else if (Input.GetKeyDown(KeyCode.Return))
  63. {
  64. finish = true;
  65. //Debug.Log("You have press Enter");
  66. Debug.Log("You number is " + guess);
  67. Debug.Log("Press Enter again if you want to play again!");
  68. Debug.Log("Press ESC to leave a game");
  69. Debug.Log("================================");
  70. }
  71. }
  72. else
  73. {
  74. //Restart
  75. if (Input.GetKeyDown(KeyCode.Return))
  76. {
  77. NewGame();
  78. }
  79. //Quit
  80. else if (Input.GetKeyDown(KeyCode.Escape))
  81. {
  82. Application.Quit();
  83. }
  84. }
  85. }
  86.  
  87. void NewGame()
  88. {
  89. min = minValue;
  90. max = maxValue;
  91. finish = false;
  92. guess = (min + max) / 2;
  93. Debug.Log("Welcome to My GUESS NUMBER ");
  94. Debug.Log("Pick number between");
  95. Debug.Log("Max number is = " + maxValue);
  96. Debug.Log("Min number is = " + minValue);
  97. Debug.Log("================================");
  98. Debug.Log("Press Up Arrow if your Guess is higher");
  99. Debug.Log("Press Down Arrow if your Guess is lower");
  100. Debug.Log("Your Number is higher or lower than = " + guess + " ?");
  101. Debug.Log("================================");
  102.  
  103. }
  104.  
  105. void FixNotReachMax()
  106. {
  107. if (guess == lastnumber)
  108. {
  109. guess++;
  110. }
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement