public static bool CheckWordInLevel(string str, WordLevel level) { Dictionary <char, int> counts = new Dictionary <char, int>(); for (int i = 0; i < str.Length; i++) { char c = str[i]; if (level.charDict.ContainsKey(c)) { if (!counts.ContainsKey(c)) { counts.Add(c, 1); } else { counts[c]++; } if (counts[c] > level.charDict[c]) { return(false); } } else { return(false); } } return(true); }
// Статичный метод даёт знать можно ли взять слово с текущим level.charDict public static bool CheckWordInLevel(string str, WordLevel level) { Dictionary <char, int> counts = new Dictionary <char, int>(); foreach (char c in str) { // Если charDict содержит такую букву if (level.charDict.ContainsKey(c)) { // Если наш счётчик ещё не содержит такой буквы как ключа if (!counts.ContainsKey(c)) { // Добавляем новый ключ counts.Add(c, 1); } else // counts содержит такой ключ { counts[c]++; } // Если в переданном слове больше каких то букв чем // в charDict, значит слово недоступно if (counts[c] > level.charDict[c]) { return(false); } } else { // charDict не содержит такой буквы return(false); } } return(true); }
public string GetRandomWord(WordLevel level = WordLevel.easy) { var words = Words.Where(word => word.WordLevel == level).ToList(); int index = UnityEngine.Random.Range(0, words.Count); return(words[index].Value); }
// With the default value of -1, this method will generate a level from // a random word. public WordLevel MakeWordLevel(int levelNum = -1) { WordLevel level = new WordLevel(); if (levelNum == -1) { // Pick a random level level.longWordIndex = Random.Range(0, WordList.S.longWordCount); } else { // This can be added later } level.levelNum = levelNum; level.word = WordList.S.GetLongWord(level.longWordIndex); level.charDict = WordLevel.MakeCharDict(level.word); // Call a coroutine to check all the words in the WordList and see // whether each word can be spelled by the chars in level.charDict StartCoroutine(FindSubWordsCoroutine(level)); // This returns the level before the coroutine finishes, so // SubWordSearchComplete() is called when the coroutine is done return(level); }
public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string> (); string str; List <string> words = WordList.S.GetWords(); for (int i = 0; i < WordList.S.wordCount; i++) { str = words [i]; if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } if (i % WordList.S.numToParseBeforeYield == 0) { yield return(null); } } level.subWords.Sort(); level.subWords = SortWordsByLength(level.subWords).ToList(); SubWordSearchComplete(); }
private void SetUpBotTimer(WordLevel level, int filter) { var key = new UserFilterKey(level, filter); IDisposable timerDisp = null; if (bots.TryRemove(key, out timerDisp)) { timerDisp?.Dispose(); } var disposable = Observable.Interval(TimeSpan.FromSeconds(8), botTimerScheduler) .Take(1) .SelectMany(async _ => { await AddUserToQueue(new UserInfo(Guid.NewGuid().ToString(), GetRandomBotName(), level, true, false), filter); return(Unit.Default); }) .Subscribe(); if (!bots.TryAdd(key, disposable)) { disposable.Dispose(); } }
// A coroutine that finds words that can be spelled in this level public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string>(); string str; List <string> words = WordList.S.GetWords(); // ^ This is very fast because List<string> is passed by reference // Iterate through all the words in the WordList for (int i = 0; i < WordList.S.wordCount; i++) { str = words[i]; // Check whether each one can be spelled using level.charDict if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } // Yield if we've parsed a lot of words this frame if (i % WordList.S.numToParseBeforeYield == 0) { // yield until the next frame yield return(null); } } // List<string>.Sort() sorts alphabetically by default level.subWords.Sort(); // Now sort by length to have words grouped by number of letters level.subWords = SortWordsByLength(level.subWords).ToList(); // The coroutine is complete, so call SubWordSearchComplete() SubWordSearchComplete(); }
//this static method checks to see whether the word can be spelled with the //chars in level.charDict public static bool CheckWordInLevel(string str, WordLevel level) { Dictionary<char, int> counts = new Dictionary<char, int>(); for(int i=0; i<str.Length; i++) { char c = str[i]; //if the charDict contains char c if(level.charDict.ContainsKey(c)) { //if counts doesn't already have char c as a key if(!counts.ContainsKey(c)) { //then add a new key with a value of 1 counts.Add (c,1); } else { counts[c]++; } //if this means that there are more instances of char c in str //than are available in level.charDict if(counts[c] > level.charDict[c]) { //then return false return(false); } } else { //the char c isn't in level.word, so return false return(false); } } return(true); }
public void TypeLetter(char letter) { ActiveWord.TypeLetter(letter); if (ActiveWord.IsWordTyped()) { Debug.Log("Player attack"); playerInBattle.GetComponent <PlayerInBattle>().attack(enemy); enemyHealth.text = enemy.GetComponent <EnemyInBattle>().health + "/" + maxEnemyHealth; if (enemy.GetComponent <EnemyInBattle>().health <= 0) { //Invoke the Restart function to start the next level with a delay of restartLevelDelay (default 1 second). Debug.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!! VICTORY"); Text foodText = GameObject.FindGameObjectWithTag("FoodText").GetComponent <Text>(); headline.text = "Victory!"; Invoke("Exit", exitDelay); } else { WordLevel wordLevel = EmotionMenager.GetInstance().WordLevelDifficulty(); ActiveWord = new WordToType(WordsRepository.GetRandomWord(wordLevel), WordSpawner.SpawnWord()); } // GameManager.instance.loadMainScene(); } }
// This static method checks to see whether a word can be spelled with the // chars in level.charDict public static bool CheckWordInLevel(string str, WordLevel level) { Dictionary <char, int> counts = new Dictionary <char, int>(); for (int i = 0; i < str.Length; i++) { char c = str[i]; // If charDict contains char c if (level.charDict.ContainsKey(c)) { if (!counts.ContainsKey(c)) { // ...then adda new key with a value of 1 counts.Add(c, 1); } else { // Otherwise, add 1 to the current value counts[c]++; } if (counts[c] > level.charDict[c]) { return(false); } } else { return(false); } } return(true); }
public WordLevel MakeWordLevel(int levelNum = -1) { WordLevel level = new WordLevel(); if (levelNum == -1) { // Pick a random level level.longWordIndex = Random.Range(0, WordList.LONG_WORD_COUNT); } else if (levelNum == 0) { level.longWordIndex = Random.Range(8, WordList.LONG_WORD_COUNT); } else { level.longWordIndex = Random.Range(14, WordList.LONG_WORD_COUNT); } level.levelNum = levelNum; level.word = WordList.GET_LONG_WORD(level.longWordIndex); level.charDict = WordLevel.MakeCharDict(level.word); StartCoroutine(FindSubWordsCoroutine(level)); // b return(level); // c }
public async Task <Game> StartGame(UserInfo user1, UserInfo user2, string groupId, WordLevel wordLevel, bool isGameWithBot, int wordsCount) { AssociatedGroupId = groupId; IsGameWithBot = isGameWithBot; if (IsGameWithBot) { bot = new Bot(); } gameFinishesSubject.Subscribe(_ => { lock (locker) { currentTimer?.Dispose(); } }); currentGame = new Game(user1, user2, groupId); var words = await storageAdapter.GetRandomWords(wordsCount * 2, wordLevel); currentGame.StartGame(words); InitNewTimer(0); return(currentGame); }
// A coroutine that finds words that can be spelled in this level public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string>(); string str; List <string> words = WordList.GET_WORDS(); // Iterate through all of the words in the wordList for (int i = 0; i < WordList.WORD_COUNT; i++) { str = words[i]; // Check whether each one can be spelled using level.charDict if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } // Yield if we have parsed a lot of words this frame if (i % WordList.NUM_TO_PARSE_BEFORE_YIELD == 0) { // yield until the next frame yield return(null); } } level.subWords.Sort(); level.subWords = SortWordsByLength(level.subWords).ToList(); // The coroutine is complete, so call SubWordSearchComplete() SubWordSearchComplete(); }
public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string>(); string str; List <string> words = WordList.S.GetWords(); // ^ работает быстро т.к. возвращает ссылку // Повторяем среди всех слов в списке for (int i = 0; i < WordList.S.wordCount; i++) { str = words[i]; // Проверяем может ли слово сделанно из букв if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } // Уступаем если мы передали много слов в этот кадр if (i % WordList.S.numToParseBeforeYield == 0) { // Уступаем до следующего кадра yield return(null); } } // List<string>.Sort() сортирует по алфавиту level.subWords.Sort(); // Теперь сортируем по длинне level.subWords = SortWordsByLength(level.subWords).ToList(); // Сопроцесс окончен, вызываем SubWordSearchComplete() SubWordSearchComplete(); }
public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List<string> (); string str; List<string> words = WordList.S.GetWords (); for (int i=0; i<WordList.S.wordCount; i++) { str = words [i]; if (WordLevel.CheckWordInLevel (str, level)) { level.subWords.Add (str); } if (i % WordList.S.numToParseBeforeYield == 0) { yield return null; } } level.subWords.Sort (); level.subWords = SortWordsByLength (level.subWords).ToList (); SubWordSearchComplete (); }
public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List <string>(); string str; List <string> words = WordList.GET_WORDS(); for (int i = 0; i < WordList.WORD_COUNT; i++) { str = words[i]; if (WordLevel.CheckWordInLevel(str, level)) { level.subWords.Add(str); } if (i % WordList.NUM_TO_PARSE_BEFORE_YIELD == 0) { yield return(null); } } level.subWords.Sort(); level.subWords = SortWordsByLength(level.subWords).ToList(); SubWordSearchComplete(); }
public static bool CheckWordInLevel(string str, WordLevel level) { Dictionary<char,int> counts = new Dictionary<char,int> (); for (int i=0; i<str.Length; i++) { char c = str [i]; if (level.charDict.ContainsKey (c)) { if (!counts.ContainsKey (c)) { counts.Add (c, 1); } else { counts [c]++; } if (counts [c] > level.charDict [c]) { return(false); } } else { return(false); } } return(true); }
public async Task ConnectAsAuthUser(string displayName, WordLevel level, bool isGameWithFriend, int wordsCountFilter, string friendsGroupId) { await ConnectUser(displayName, level, isGameWithFriend, friendsGroupId, wordsCountFilter, true); }
private void DelayBotTimer(WordLevel level, int filter) { IDisposable timerDisp = null; if (bots.TryRemove(new UserFilterKey(level, filter), out timerDisp)) { timerDisp?.Dispose(); } }
public void LevelUp() { if (Level == WordLevel.Normal) { Level = WordLevel.Hard; } else if (Level == WordLevel.Easy) { Level = WordLevel.Normal; } }
public void LevelDown() { if (Level == WordLevel.Normal) { Level = WordLevel.Easy; } else if (Level == WordLevel.Hard) { Level = WordLevel.Normal; } }
// This static method checks to see whether the word can be spelled with the // chars in level.charDict public static bool CheckWordInLevel(string str, WordLevel level) { Dictionary <char, int> counts = new Dictionary <char, int>(); for(int i = 0; i < str.Length; i++) { char c = str[i]; // If the charDict contains char c if(level.charDict.ContainsKey(c)) { // If counts doesn't already have char c as a key if(!counts.ContainsKey(c)) { // ...then add a new key with a value of 1 counts.Add(c, 1); } else { // Otherwise, add 1 to the current value counts[c]++; } // If this means that there are more instances of char c in str // than are available in level.charDict if(counts[c] > level.charDict[c]) { // ... then return false return(false); } } else { // The char c isn't in level.word, so return false return(false); } } return(true); }
public async Task ConnectAnon(string displayName, WordLevel level, bool isGameWithFriend, int wordsCountFilter, string friendsGroupId) { if (Context.User.Identity.IsAuthenticated) { throw new HttpRequestException("User is authorized. Should use ConnectAsAuthUser method"); } await ConnectUser(displayName, level, isGameWithFriend, friendsGroupId, wordsCountFilter, false); }
public async Task <List <WordBL> > GetRandomWords(int count, WordLevel wordLevel) { if (wordLevel == WordLevel.Unknown) { throw new ArgumentException(nameof(wordLevel)); } var dtoList = await dataContext.GetWordsCollection(wordLevel) .Aggregate() .AppendStage <WordDTO>(string.Format("{{ $sample: {{ size: {0} }} }}", count)) .ToListAsync(); return(dtoList.Select(Mapper.Map <WordBL>).ToList()); }
public WordLevel MakeWordLevel(int levelNum = -1) { WordLevel level = new WordLevel (); if (levelNum == -1) { level.longWordIndex = Random.Range (0, WordList.S.longWordCount); } else { } level.levelNum = levelNum; level.word = WordList.S.GetLongWord (level.longWordIndex); level.charDict = WordLevel.MakeCharDict (level.word); StartCoroutine (FindSubWordsCoroutine (level)); return(level); }
}//end of WordListParseComplete() public WordLevel MakeWordLevel(int levelNum = -1){ WordLevel level = new WordLevel (); if (levelNum == -1) level.longWordIndex = Random.Range (0, WordList.S.longWordCount); else { }//end of else level.levelNum = levelNum; level.word = WordList.S.GetLongWord (level.longWordIndex); level.charDict = WordLevel.MakeCharDict (level.word); //can the word be spelled by the letters in level.charDict StartCoroutine(FindSubWordsCoroutine(level)); //because level is returned before the coroutine is finished SubWordSearchComplete() //will be called when the coroutine is finished return level; }//end of MakeWordLevel(int levelNum = -1)
public WordLevel MakeWordLevel(int levelNum = -1) { WordLevel level = new WordLevel(); if (levelNum == -1) { level.longWordIndex = Random.Range(0, WordList.S.longWordCount); } else { } level.levelNum = levelNum; level.word = WordList.S.GetLongWord(level.longWordIndex); level.charDict = WordLevel.MakeCharDict(level.word); StartCoroutine(FindSubWordsCoroutine(level)); return(level); }
public IMongoCollection <WordDTO> GetWordsCollection(WordLevel collectionType) { switch (collectionType) { case WordLevel.Beginer: return(GetWordsBeginnerCollection()); case WordLevel.Intermediate: return(GetWordsIntermediateCollection()); case WordLevel.Advanced: return(GetWordsAdvancedCollection()); default: throw new ArgumentException(nameof(collectionType)); } }
}//wordlist parse complete public WordLevel MakeWordLevel(int levelNum = -1) { WordLevel level = new WordLevel(); if (levelNum == -1) { level.longWordIndex = Random.Range(0, WordList.LONG_WORD_COUNT); }//if else { //empty for now }//else level.levelNum = levelNum; level.word = WordList.GET_LONG_WORD(level.longWordIndex); level.charDict = WordLevel.MakeCharDict(level.word); StartCoroutine(FindSubWordsCoroutine(level)); return(level); }//public wordlevel
public WordLevel MakeWordLevel(int levelNum = -1) { WordLevel level = new WordLevel(); if (levelNum == -1) { level.longWordIndex = Random.Range(0, WordList.LONG_WORD_COUNT); } else { // This will be added later in the chapter } level.levelNum = levelNum; level.word = WordList.GET_LONG_WORD(level.longWordIndex); level.charDict = WordLevel.MakeCharDict(level.word); StartCoroutine(FindSubWordsCoroutine(level)); return(level); }
public UserInfo(string userId, string displayName, WordLevel gameLevel, bool isBot, bool isLoggedIn, LoginUserInfo loginUserInfo = null) { UserId = userId; DisplayName = displayName; GameLevel = gameLevel; IsBot = isBot; if (isLoggedIn && loginUserInfo == null) { throw new ArgumentException(nameof(loginUserInfo)); } IsLoggedIn = isLoggedIn; LoginInfo = loginUserInfo; }
}//end of MakeCharDict(string w) //this function checks to see if a word can be spelled with available letters public static bool CheckWordInLevel(string str, WordLevel level){ Dictionary <char,int> counts = new Dictionary <char,int> (); for (int i = 0; i < str.Length; i++) { char c = str [i]; //if the level contains char c if (level.charDict.ContainsKey (c)) { //if the key already isn't in counts if (!counts.ContainsKey (c)) counts.Add (c, 1); //otherwise add 1 to the current value else counts [c]++; //if there aren't enough of the character if (counts [c] > level.charDict [c]) return false; }//end of if //or if it doesn't contain char c else return false; }//end of for loop return true; }//end of CheckWordInLevel(string str, WordLevel level)
private async Task ConnectUser(string displayName, WordLevel level, bool isGameWithFriend, string friendsGroupId, int wordsCountFilter, bool isLoggedIn) { if (string.IsNullOrWhiteSpace(displayName)) { throw new ArgumentNullException(nameof(displayName)); } if (level == WordLevel.Unknown) { throw new ArgumentException(nameof(level)); } await collector.AddUserToQueue( new UserInfo(Context.ConnectionId, displayName, level, false, isLoggedIn, GetLoginInfoFromClaims()), wordsCountFilter, isGameWithFriend, friendsGroupId); }
// Use this for initialization when manager is enabled with "setActive" void OnEnable() { Debug.Log("OnEnabled BattleManager"); // Prevent to init on very first start of the game if (GameManager.instance != null && GameManager.instance.isBattle) { WordsRepository = XmlManager.Deserialize <WordsRepository>(); WordLevel wordLevel = EmotionMenager.GetInstance().WordLevelDifficulty(); ActiveWord = new WordToType(WordsRepository.GetRandomWord(wordLevel), WordSpawner.SpawnWord()); // get random enemy from prefabs Debug.Log("Init enemy:"); EnemyType enemyType = getEnemyType(); Debug.Log(enemyType); if (enemyType.Equals(EnemyType.Wolf)) { Debug.Log("Loading Wolf."); enemy = Instantiate(Resources.Load("Prefabs/WolfBattle", typeof(GameObject)), enemyPosition.position, Quaternion.identity) as GameObject; } else if (enemyType.Equals(EnemyType.Zombie)) { Debug.Log("Loading Zombie."); enemy = Instantiate(Resources.Load("Prefabs/Zombie1Battle", typeof(GameObject)), enemyPosition.position, Quaternion.identity) as GameObject; } Debug.Log(enemy); // enemy.transform.parent = enemyPosition; //set up player&enemy health text Debug.Log("Player health: "); Debug.Log(playerInBattle.GetComponent <PlayerInBattle>().health); Debug.Log("Enemy health: "); Debug.Log(enemy.GetComponent <EnemyInBattle>().health); maxEnemyHealth = enemy.GetComponent <EnemyInBattle>().health; playerHealth.text = playerInBattle.GetComponent <PlayerInBattle>().health + "/" + Player.maxHealth; enemyHealth.text = enemy.GetComponent <EnemyInBattle>().health + "/" + enemy.GetComponent <EnemyInBattle>().health; headline.text = "Fight!"; } }
public void WordListParseComplete(){ mode = GameMode.makeLevel; currLevel = MakeWordLevel (); }
//a coroutine that finds words that can be spelled in this level public IEnumerator FindSubWordsCoroutine(WordLevel level) { level.subWords = new List<string> (); string str; List<string> words = WordList.S.GetWords (); //iterate through all the words in the WordList for (int i = 0; i<WordList.S.wordCount; i++) { str = words [i]; //check whetehr each one can be spelled using level.charDict if (WordLevel.CheckWordInLevel (str, level)) { level.subWords.Add (str); } //yield if we've parsed a lot of words this frame if (i % WordList.S.numToParseBeforeYield == 0) { //yield until the next frame yield return null; } } //List<String>.Sort() sorts alphabetically by default level.subWords.Sort (); //now sort by length to have words grouped by number of letters level.subWords = SortWordsByLength (level.subWords).ToList (); //the coroutine is complete, so call SubWordSearchComplete() SubWordSearchComplete (); }
//with the default value of -1, this method will generate a level from //a random word public WordLevel MakeWordLevel(int levelNum= -1) { WordLevel level = new WordLevel (); if (levelNum == -1) { //pick a random level level.longWordIndex = Random.Range (0, WordList.S.longWordCount); } else { //added later } level.levelNum = levelNum; level.word = WordList.S.GetLongWord (level.longWordIndex); level.charDict = WordLevel.MakeCharDict (level.word); //call a coroutine to check all the words in the WordList and see //whether each word can be spelled by the chars in level.charDict StartCoroutine (FindSubWordsCoroutine (level)); //this returns the level before the coroutine finished, so //SubWordSearchComplete() is called when the coroutine is done return (level); }
//called by the SendMessage() command from WordList public void WordListParseComplete() { mode = GameMode.makeLevel; //make a level and assign it to currLevel, the current WordLevel currLevel = MakeWordLevel (); }