/// <summary> /// Adds and returns a random theme. /// </summary> private string AddTheme() { string themeName; // Select random theme. do { themeName = m_pictureLoader.SelectRandomTheme(); }while (m_currentThemes.IndexOf(themeName) != -1); // save it to the list of current themes. m_currentThemes.Add(themeName); return(themeName); }
/// <summary> /// Sets up the manager and creates all the selectable items. /// Makes sure one of the items is the correct one to complete the row. /// </summary> public void SetUp() { DestroyOldItems(); // List to make sure that the items on the bar are from different themes. m_currentThemes = new List <string>(); // int to pick one of the four items that will match with current row. int randomItemPosition = Random.Range(0, Constants.NUMBER_OF_SELECTABLE_ITEMS); m_currentRowScript = m_rowsManager.GetCurrentRowScript(); // What is the current theme name? string currentTheme = m_currentRowScript.GetThemeName(); // Add it on used themes. List <string> itemThemes = new List <string>(); for (int i = 0; i < Constants.NUMBER_OF_SELECTABLE_ITEMS; i++) { string itemName; string selectTheme = currentTheme; GameObject item = (GameObject)Instantiate(m_itemHolder); item.AddComponent <SelectItemScript>(); // selectable item. // this is the item that matches. if (randomItemPosition == i) { itemName = m_currentRowScript.GetMissingElement(); item.GetComponent <SelectItemScript>().SetUpItem(itemName, selectTheme, i, m_currentRowScript.gameObject.transform, m_showReel); m_selectItemsNames.Add(itemName); correctItemPos = item.transform.position; } // this is a random item. else { GameObject pictureLoaderObject = GameObject.Find(Constants.PICTURE_LOADER_NAME); PictureLoader pictureLoader = pictureLoaderObject.GetComponent <PictureLoader>(); // Make sure it's not an item of the same theme! Item should be unique. if (Game.SuperMode != Game.Difficulty.Hard) { do { selectTheme = pictureLoader.SelectRandomTheme(); }while (selectTheme == currentTheme || itemThemes.IndexOf(selectTheme) != -1); itemName = pictureLoader.SelectRandomURL(selectTheme); } else { selectTheme = currentTheme; do { itemName = pictureLoader.SelectRandomURL(selectTheme); }while (m_selectItemsNames.IndexOf(itemName) != -1 || itemName == m_currentRowScript.GetMissingElement()); } item.GetComponent <SelectItemScript>().SetUpItem(itemName, selectTheme, i, gameObject.transform, m_showReel); itemThemes.Add(selectTheme); m_selectItems.Add(item); m_selectItemsNames.Add(itemName); } } }