public void AssignNodeTextCharacters(int seed = -1) { string availableTextCharacters = SaveGameManager.GetString(SaveGameManager.SAVE_LEVEL_TEXTCHARACTERS, "sdfghjkl"); //ClearNodeTextCharacters(); if (seed == -1) { UnityEngine.Random.InitState(System.Environment.TickCount); //Random enough? } else { UnityEngine.Random.InitState(seed); } //Give all the nodes a random character foreach (Node currentNode in m_Nodes) { //Create an array of all still available characters List <char> availableTextCharactersList = new List <char>(availableTextCharacters.ToCharArray()); //Remove characters that our neighbours neighbours have claimed for (int dir = 0; dir <= (int)Direction.West; ++dir) { Node neighbour = currentNode.GetNeighbour((Direction)dir); if (neighbour != null) { //Character this neighbour has claimed (this is allowed, you can have an E next to a another E (the one you're standing on)) //char takenChar = neighbour.GetTextCharacter(); //if (takenChar != '\0') { availableTextCharactersList.Remove(takenChar); } //Characters his neighbours have claimed for (int dir2 = 0; dir2 <= (int)Direction.West; ++dir2) { Node neighbour2 = neighbour.GetNeighbour((Direction)dir2); if (neighbour2 != null) { char takenChar = neighbour2.GetTextCharacter(); if (takenChar != '\0') { availableTextCharactersList.Remove(takenChar); } } } } } if (availableTextCharactersList.Count > 0) { //Pick a random character from the remaining list and assign it int randInt = UnityEngine.Random.Range(0, availableTextCharactersList.Count); currentNode.SetTextCharacter(availableTextCharactersList[randInt]); currentNode.name = currentNode.name + " - " + currentNode.GetTextCharacter(); } } }
private void OnDeleteSaveGame() { //Reset data m_WidthInputField.text = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_WIDTH, 5).ToString(); m_HeightInputField.text = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_HEIGHT, 5).ToString(); m_TextCharactersInputField.text = SaveGameManager.GetString(SaveGameManager.SAVE_LEVEL_TEXTCHARACTERS, "sdfghjkl"); m_SeedInputField.text = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_SEED, -1).ToString(); }
public void Show() { if (m_CanvasGroup != null) { m_CanvasGroup.Show(); } if (LevelDirector.Instance != null) { LevelDirector.Instance.AddInputBlocker(); } if (m_GenerateButton != null) { StartCoroutine(SelectButtonRoutine()); } //Load all the save game data m_WidthInputField.text = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_WIDTH, 5).ToString(); m_HeightInputField.text = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_HEIGHT, 5).ToString(); m_TextCharactersInputField.text = SaveGameManager.GetString(SaveGameManager.SAVE_LEVEL_TEXTCHARACTERS, "sdfghjkl"); m_SeedInputField.text = SaveGameManager.GetInt(SaveGameManager.SAVE_LEVEL_SEED, -1).ToString(); }