예제 #1
0
	// randomized selection of the word for unscramble game
	private void SelectWord() {
		int r = Random.Range (0, words.Count);
		string w = words [r]; // Gets a random word from the dictionary

		// checks if the word is valid for unscramble
		while (w.Length > hintSpots.Length) {
			r = Random.Range (0, words.Count);
			w = words [r];
		}

		// make w == currentWord
		currentWord = w;

		List<char> cl = new List<char> (); // the list or chars in the list
		foreach (char c in w) {
			cl.Add (c);
		}

		// sorts letters based on how many words contains each char
		cl.Sort (delegate(char c1, char c2) {
			return letterToWords[c1].Count.CompareTo(letterToWords[c2].Count);
		});

		int count = 0; // counts the chars in cl
		foreach (char c in cl) {
			string s = GetRandomWord (c, w);
			//generated random numbers for the unscramble
			HashSet<int> rand = generateNRandom(s.Length, s.Length);
			while (IsSorted (rand)) {
				rand = generateNRandom(s.Length, s.Length);
			}

			// the unscrambled word
			StringBuilder unscramble = new StringBuilder ();
			foreach (int i in rand) {
				unscramble.Append (s[i]);
			}

			// create Hint objects
			if (hints.Count < count + 1) {
				r = Random.Range (0, hintsTypes.Length);
				Hint h = Instantiate (hintsTypes [r]).GetComponent<Hint> ();
				hints.Add (h);
			}
			Hint hint = hints[count];
			hint.CreateHint (s, c, unscramble.ToString(), rand);

			count++;
		}
	}