Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class HelloWorld : MonoBehaviour {
- int minValue = 1;
- int maxValue = 1000;
- int min;
- int max;
- int guess;
- bool finish;
- int lastnumber;
- void Start () {
- NewGame();
- //Debug.Log("Hello World");
- }
- // Update is called once per frame
- void Update () {
- GameControl();
- }
- void GameControl()
- {
- //Guessing
- if (!finish)
- {
- if (Input.GetKeyDown(KeyCode.UpArrow))
- {
- if(guess == maxValue)
- {
- Debug.Log("You have reach maximum number");
- return;
- }
- lastnumber = guess;
- min = guess;
- guess = (min + max) / 2;
- //Debug.Log("You have press Up Arrow");
- Debug.Log("Your number is : " + guess + " ?");
- Debug.Log("If higher press Up Arrow if lower press Down Arrow");
- Debug.Log("================================");
- FixNotReachMax();
- }
- else if (Input.GetKeyDown(KeyCode.DownArrow))
- {
- if(guess == minValue)
- {
- Debug.Log("You have reach minimum number");
- }
- lastnumber = guess;
- max = guess;
- guess = (min + max) / 2;
- //Debug.Log("You have press Down Arrow");
- Debug.Log("Your number is : " + guess + " ?");
- Debug.Log("If higher press Up Arrow if lower press Down Arrow");
- Debug.Log("================================");
- }
- //Ending Guess
- else if (Input.GetKeyDown(KeyCode.Return))
- {
- finish = true;
- //Debug.Log("You have press Enter");
- Debug.Log("You number is " + guess);
- Debug.Log("Press Enter again if you want to play again!");
- Debug.Log("Press ESC to leave a game");
- Debug.Log("================================");
- }
- }
- else
- {
- //Restart
- if (Input.GetKeyDown(KeyCode.Return))
- {
- NewGame();
- }
- //Quit
- else if (Input.GetKeyDown(KeyCode.Escape))
- {
- Application.Quit();
- }
- }
- }
- void NewGame()
- {
- min = minValue;
- max = maxValue;
- finish = false;
- guess = (min + max) / 2;
- Debug.Log("Welcome to My GUESS NUMBER ");
- Debug.Log("Pick number between");
- Debug.Log("Max number is = " + maxValue);
- Debug.Log("Min number is = " + minValue);
- Debug.Log("================================");
- Debug.Log("Press Up Arrow if your Guess is higher");
- Debug.Log("Press Down Arrow if your Guess is lower");
- Debug.Log("Your Number is higher or lower than = " + guess + " ?");
- Debug.Log("================================");
- }
- void FixNotReachMax()
- {
- if (guess == lastnumber)
- {
- guess++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement