mirror of
https://github.com/ConjureETS/OuijaMTLGJ2016.git
synced 2026-03-24 18:21:07 +00:00
Bug: After a player finishes the game, application will crash. Make sure winning scenario is handled. Gameplay scene is gameplay_02.unity.
54 lines
1006 B
C#
54 lines
1006 B
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class WordGen : MonoBehaviour
|
|
{
|
|
static int prev;
|
|
static int modif;
|
|
static int tempCode;
|
|
static int[] cCodes;
|
|
static int[] codeChance;
|
|
static string finalWord;
|
|
static bool allowLetter;
|
|
|
|
public static string GetWord(int numLetters)
|
|
{
|
|
finalWord = "";
|
|
prev = -1;
|
|
modif = 0;
|
|
cCodes = new int[numLetters];
|
|
codeChance = new int[26];
|
|
|
|
for(int i = 0; i < numLetters; i++)
|
|
{
|
|
allowLetter = false;
|
|
foreach (int c in codeChance)
|
|
{
|
|
codeChance[c] = 1;
|
|
}
|
|
modif = Random.Range(0, 26) % 26;
|
|
if(i > 0)
|
|
for(int a = i - 1; a >= 0; a--)
|
|
for(int x = 0; x < 26; x++)
|
|
if(cCodes[a] - 65 == x)
|
|
codeChance[x] *= 2;
|
|
|
|
while(!allowLetter)
|
|
{
|
|
if(Random.Range(0, codeChance[modif]) == 0 && modif != prev)
|
|
allowLetter = true;
|
|
else
|
|
modif = Random.Range(0, 26);
|
|
}
|
|
|
|
prev = modif;
|
|
cCodes[i] = modif + 65;
|
|
finalWord += (char)cCodes[i];
|
|
}
|
|
|
|
|
|
return finalWord;
|
|
}
|
|
|
|
}
|