Advertisement
Guest User

Untitled

a guest
May 25th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. // NumberWizard.cs
  2. // ================
  3. using UnityEngine;
  4. using System.Collections;
  5. using UnityEngine.UI;
  6.    
  7. public class NumberWizard : MonoBehaviour
  8. {
  9.     // Use this for initialization
  10.     int max;
  11.     int min = 1;
  12.     int guess;
  13.     public int maxGuessesAllowed;
  14.     public Text text;
  15.    
  16.     //Start the game
  17.     void Start ()
  18.     {
  19.         StartGame();
  20.     }
  21.    
  22.     // Start the game
  23.     void StartGame ()
  24.     {      
  25.         NextGuess();
  26.     }
  27.    
  28.    
  29.     //Guess a higher number
  30.     public void GuessHigher()
  31.     {
  32.         min = guess;
  33.         NextGuess();
  34.     }
  35.    
  36.    
  37.     //Guess a lower number
  38.     public void GuessLower()
  39.     {
  40.         max = guess;
  41.         NextGuess();
  42.     }
  43.    
  44.     public void SetFields(){
  45.         RangeSelection RA = gameObject.AddComponent("RangeSelection") as RangeSelection;
  46.         this.max = RA.maximum;
  47.         this.maxGuessesAllowed = RA.max_GuessesAllowed;
  48.     }
  49.     //Guess a new number
  50.     void NextGuess()
  51.     {
  52.         RangeSelection RA = gameObject.AddComponent("RangeSelection") as RangeSelection;
  53.         print ("RA Max:" + RA.maximum);  
  54.         print ("Current Max:" + max);  
  55.         print ("Current # of Guesses:" + maxGuessesAllowed);  
  56.         guess = Random.Range(min,max+1);
  57.         print ("Guess: " + guess) ;
  58.         text.text = guess.ToString();  
  59.         maxGuessesAllowed--;
  60. //      if(maxGuessesAllowed <= 0)
  61. //      {
  62. //          Application.LoadLevel("Win");
  63. //      }
  64.     }
  65.    
  66.    
  67. }
  68.  
  69.  
  70.  
  71. // RangeSelection.cs
  72. // ================
  73. using UnityEngine;
  74. using System.Collections;
  75.  
  76. public class RangeSelection : MonoBehaviour {
  77.  
  78.     // Use this for initialization
  79.     public static int maximum = 500;
  80.     public static int max_GuessesAllowed = 8;
  81.    
  82.    
  83.     //Set the guessing range to 1-1000
  84.     public  void Range_1()
  85.     {
  86.         this.maximum = 1000;
  87.         this.max_GuessesAllowed = 7;
  88.         print ("Range1 called");
  89.     }
  90.    
  91.    
  92.     //Set the guessing range to 1-10000
  93.     public  void Range_2()
  94.     {
  95.         this.maximum = 10000;
  96.         this.max_GuessesAllowed = 10;
  97.         print ("Range1 called2");
  98.        
  99.     }
  100.    
  101.    
  102.     //Set the guessing range to 1-100000
  103.     public  void Range_3()
  104.     {
  105.         this.maximum = 100000;
  106.         this.max_GuessesAllowed = 15;
  107.         print ("Range1 called3");
  108.        
  109.     }  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement