Advertisement
gntalakas

NumberGuess semifinal

Oct 26th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. public class NumberGuess : MonoBehaviour {
  4.     public int max;
  5.     public int min;
  6.     public int guess;
  7.     public int correctNumber;
  8.  
  9.     void Start () {
  10.         StartGame ();
  11.     }
  12.  
  13.     // Update is called once per frame
  14.     void Update () {
  15.         if(Input.GetKeyDown(KeyCode.UpArrow) ) {
  16.             min = guess;
  17.             NextGuess ();
  18.         } else if(Input.GetKeyDown(KeyCode.DownArrow) ) {
  19.             max = guess;
  20.             NextGuess ();
  21.         } else
  22.             if(guess==correctNumber) {
  23.             //if(Input.GetKeyDown(KeyCode.Return) ) {
  24.             print ("Κέρδισες");
  25.             StartGame ();
  26.         }
  27.  
  28.     }
  29.  
  30.     void StartGame (){
  31.         correctNumber = Random.Range (min, max);
  32.     //  print (Random.Range(min, max));
  33.         print ("My nymber Game");
  34.         print ("Διάλεξε έναν αριθμό αλλά μην πεις ποιος είναι");
  35.         print ("Μέγιστος αριθμός: " + max + ", ελάχιστος αριθμός: " + min);
  36.         NextGuess ();  
  37.     }
  38.  
  39.     void NextGuess(){
  40.         //max = max + 1;
  41.         guess = (max + min) / 2;
  42.         print ("Ο αριθμός είναι μεγαλύτερος του " + guess +";");
  43.         print ("Αν είναι μεγαλύτερος πάτα το πάνω βέλος, εάν είναι μικρότερος πάτα το κάτω βέλος, εάν τον βρήκα πάτα το Enter");
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement