Closed rifaterdemsahin closed 6 years ago
using System.Collections; using System.Linq; using System; using System.Collections.Generic; using UnityEngine;
public class SetTheQuestion : MonoBehaviour {
public GameObject question;
public GameObject newLetterOrder;
// Use this for initialization
void Start () {
var myQuestion = Words.GetAWordRandom();
question.GetComponent<TextMesh>().text = myQuestion;
newLetterOrder.GetComponent<TextMesh>().text = Shuffle.StringMixer(myQuestion);
}
// Update is called once per frame
void Update () {
}
}
public class Words {
public string Word { get; set; }
public static List
public static string GetAWordRandom()
{
init();
var result = "";
result = (from f in Dictionary
select f
).OrderBy(x => Guid.NewGuid()).FirstOrDefault();
return result;
}
} public class Shuffle { static System.Random rnd = new System.Random();
static void Fisher_Yates(int[] array)
{
int arraysize = array.Length;
int random;
int temp;
for (int i = 0; i < arraysize; i++)
{
random = i + (int)(rnd.NextDouble() * (arraysize - i));
temp = array[random];
array[random] = array[i];
array[i] = temp;
}
}
public static string StringMixer(string s)
{
string output = "";
int arraysize = s.Length;
int[] randomArray = new int[arraysize];
for (int i = 0; i < arraysize; i++)
{
randomArray[i] = i;
}
Fisher_Yates(randomArray);
for (int i = 0; i < arraysize; i++)
{
output += s[randomArray[i]];
}
return output;
}
}
use the world list get a letters list Scramble it.create that order Load a different word every time