Пример #1
0
    public void SetupFirstWord(CreatureRoot val)
    {
        _ObjectHealth = ListOfWords.GetRandomWords((int)val.Stats.WordDifficulty);
        _OriginalWord = _ObjectHealth;

        val.GetCreatureWordCheckInfo().TextElement.text = _ObjectHealth;
    }
/*	public EnemyWordChecker(Text textElement, string enemyHealth, DefaultBehaviour parent){//Adding methods to events and setting startvalues
 *
 *              TextElement = textElement;
 *              _ObjectHealth = enemyHealth;
 *              _OriginalWord = enemyHealth;
 *              _TheObject = parent;
 *
 *              _WordsToRemove = 0;
 *
 *              TextElement.text = _ObjectHealth;
 * //		_CleaveDmg = TalentBonusStats.CleaveDmg; TODO tobeused
 * //		_StopChecking = false;
 *
 *              TypingEvents.OnCompareStart += CompareStart;
 *      //	TypingEvents.OnCompareRestart += CompareRestart;
 *              TypingEvents.OnCompareEnd += CompareEnd;
 * //		players.Add (new KeyValuePair<GameObject, KeyValuePair<Color, string[]>>(theParent.gameObject, new  KeyValuePair<Color, string[]> (Color.yellow, new string[1]{ "muaaaooo" })));
 *
 *              //_SpawnedObject = Instantiate (ObjectsToSpawn [k].creature.gameObject, SpawnPoints [_SpawnSpot].transform.position, Quaternion.identity, SpawnPoints [_SpawnSpot].transform) as GameObject;
 *      //	theParent.setword(ListOfWords.GetRandomWords (Healths[0]));
 *      }*/

/*	public EnemyWordChecker(Text textElement, DefaultBehaviour parent){//Adding methods to events and setting startvalues
 *
 *              _TheObject = parent;
 *              TextElement = textElement;
 *
 * //		_ObjectHealth = ListOfWords.GetRandomWords (TheCreature.HealthWordsLength[HealthIndex]);
 *              _ObjectHealth = ListOfWords.GetRandomWords (5);
 *              _OriginalWord = _ObjectHealth;
 *
 *              TextElement.text = _ObjectHealth;
 *
 *              TypingEvents.OnCompareStart += CompareStart;
 *              TypingEvents.OnCompareEnd += CompareEnd;
 *      }*/



    public void Setup()
    {
        _Players            = new List <KeyValuePair <GameObject, KeyValuePair <Color, string[]> > >();
        PlayersTypedCorrect = new List <bool>();

        _ObjectHealth = ListOfWords.GetRandomWords(TheCreature.HealthWordsLength[HealthIndex]);
        _OriginalWord = _ObjectHealth;

        TextElement.text = _ObjectHealth;

        TypingEvents.OnCompareStart += CompareStart;
        TypingEvents.OnCompareEnd   += CompareEnd;
    }
    void CompareStart(KeyValuePair <GameObject, KeyValuePair <Color, string[]> > InputString)   //Compares _EnemyHealth with what the player typed(InputString)
    {
        if (IgnoreTyping == false)
        {
            if (!_Players.Contains(InputString))               //Adding New Players To The List
            {
                _Players.Add(InputString);
                PlayersTypedCorrect.Add(true);
            }

            for (int i = 0; i < _Players.Count; i++)              //Checking If The InputString/CurrentPlayer Is Corrent And Need Update
            {
                if (_Players [i].Key == InputString.Key)
                {
                    _WordLengths = _Players [i].Value.Value [0].Length;

                    if (_WordLengths > _ObjectHealth.Length)
                    {
                        _WordLengths = _ObjectHealth.Length;
                    }

                    for (int j = (_WordLengths - 1); j >= 0; j--)
                    {
                        if (_Players [i].Value.Value [0] [j] != _ObjectHealth [j])
                        {
                            PlayersTypedCorrect [i] = false;
                            break;
                        }
                        if (j == 0)
                        {
                            PlayersTypedCorrect [i] = true;
                            if (_WordLengths == _ObjectHealth.Length)
                            {
                                if (TheCreature.HealthWords > 0)
                                {
                                    TheCreature.HealthWords--;

                                    if (HealthIndex >= TheCreature.HealthWordsLength.Length - 1)
                                    {
                                        HealthIndex = -1;
                                    }


                                    _Players [i].Key.GetComponent <PlayerManager> ().GotTheKill(_OriginalWord.Length);               //Giving The Player That Wrote The Last Word The Score  //TODO Give Each Player Tagged Score?
                                    _Players [i].Key.GetComponent <PlayerManager> ().ResetWord();                                    //Giving The Player That Wrote The Last Word The Score  //TODO Give Each Player Tagged Score?

                                    _ObjectHealth = ListOfWords.GetRandomWords(TheCreature.HealthWordsLength [++HealthIndex]);
                                    _OriginalWord = _ObjectHealth;

                                    TextElement.text = "";                                    //Removing Text So That I Can Add It Again With New Colors
                                    PlayerColor      = (Color32)Color.black;
                                    ColorValue       = PlayerColor.r.ToString("X2") + PlayerColor.g.ToString("X2") + PlayerColor.b.ToString("X2") + PlayerColor.a.ToString("X2");

                                    for (int k = 0; k < _ObjectHealth.Length; k++)
                                    {
                                        TextElement.text += string.Format("<color=#" + ColorValue + ">{0}</color>", _ObjectHealth [k]);
                                    }

                                    return;
                                }
                                else
                                {
                                    _Players [i].Key.GetComponent <PlayerManager> ().ResetWord();                                    //Giving The Player That Wrote The Last Word The Score  //TODO Give Each Player Tagged Score?
                                    _Players [i].Key.GetComponent <PlayerManager> ().GotTheKill(_OriginalWord.Length);               //Giving The Player That Wrote The Last Word The Score  //TODO Give Each Player Tagged Score?

                                    TypingEvents.OnCompareStart -= CompareStart;
                                    TypingEvents.OnCompareEnd   -= CompareEnd;
                                    TheCreature.OnDestroyed();
                                }
                            }
                            break;
                        }
                    }
                    break;
                }
            }

            _WordLengths = 0;
            NullCheck    = 0;

            for (int i = 0; i < _Players.Count; i++)              //Iterating Through Once To Find The Two Players That Have Typed The Most. If Two Are The Same The The One That Tagged It Is The Leader
            {
                if (PlayersTypedCorrect [i] == true)
                {
                    if (_Players [i].Value.Value [0].Length > _WordLengths)
                    {
                        _2ndLongestPlayer = _LongestPlayer;
                        _LongestPlayer    = _Players [i];
                        NullCheck++;
                    }
                }
            }

            _WordsToRemove   = 0;
            TextElement.text = "";                                                                                                                       //Removing Text So That I Can Add It Again With New Colors

            if (NullCheck > 1)                                                                                                                           //Adding 2nd Place Player Color
            {
                _WordLengths = _2ndLongestPlayer.Value.Value [0].Length;                                                                                 //Length Of Player Word
                //	ColorValue = ((Color32)_2ndLongestPlayer.Value.Key).ToString ("X2"); //Does'nt Work  Only White Comes Out
                PlayerColor = (Color32)_2ndLongestPlayer.Value.Key;                                                                                      //Player Color
                ColorValue  = PlayerColor.r.ToString("X2") + PlayerColor.g.ToString("X2") + PlayerColor.b.ToString("X2") + PlayerColor.a.ToString("X2"); //Setting Color, Only Way I Got It To Work

                for (int i = 0; i < _WordLengths; i++)                                                                                                   //Iterates Through And Adds The Letter Again But With Different Color
                {
                    _WordsToRemove++;
                    TextElement.text += string.Format("<color=#" + ColorValue + ">{0}</color>", _ObjectHealth [i]);
                }
            }

            if (NullCheck > 0)              //Adding 1nd Place Player Color
            {
                _WordLengths = _LongestPlayer.Value.Value [0].Length;
                //	ColorValue = ((Color32)_LongestPlayer.Value.Key).ToString ("X2"); //Does'nt Work  Only White Comes Out
                PlayerColor = (Color32)_LongestPlayer.Value.Key;
                ColorValue  = PlayerColor.r.ToString("X2") + PlayerColor.g.ToString("X2") + PlayerColor.b.ToString("X2") + PlayerColor.a.ToString("X2");

                for (int i = _WordsToRemove; i < _WordLengths; i++)
                {
                    _WordsToRemove++;
                    TextElement.text += string.Format("<color=#" + ColorValue + ">{0}</color>", _ObjectHealth [i]);
                }
            }

            //	ColorValue = ((Color32)Color.black).ToString ("X2");//Adding The Rest That's Not Written  //Does'nt Work  Only White Comes Out
            PlayerColor = (Color32)Color.black;
            ColorValue  = PlayerColor.r.ToString("X2") + PlayerColor.g.ToString("X2") + PlayerColor.b.ToString("X2") + PlayerColor.a.ToString("X2");

            for (int i = _WordsToRemove; i < _ObjectHealth.Length; i++)
            {
                TextElement.text += string.Format("<color=#" + ColorValue + ">{0}</color>", _ObjectHealth [i]);
            }
        }
    }
Пример #4
0
    public void CompareStart(KeyValuePair <GameObject, KeyValuePair <Color, string[]> > InputString, CreatureRoot val)   //Is Called When The Player Types Something
    {
        myVariables = val.GetCreatureWordCheckInfo();

        if (!myVariables._Players.Contains(InputString))           //Adding New Players To The List
        {
            myVariables._Players.Add(InputString);
            PlayersTypedCorrect.Add(true);
        }

        for (int i = 0; i < myVariables._Players.Count; i++)          //Checking If The InputString/CurrentPlayer Is Corrent And Need Update
        {
            if (myVariables._Players [i].Key == InputString.Key)
            {
                _WordLengths = myVariables._Players [i].Value.Value [0].Length;

                if (_WordLengths > _ObjectHealth.Length)
                {
                    _WordLengths = _ObjectHealth.Length;
                }

                for (int j = (_WordLengths - 1); j >= 0; j--)
                {
                    if (myVariables._Players [i].Value.Value [0] [j] != _ObjectHealth [j])
                    {
                        PlayersTypedCorrect [i] = false;
                        break;
                    }
                    if (j == 0)
                    {
                        PlayersTypedCorrect [i] = true;
                        if (_WordLengths == _ObjectHealth.Length)
                        {
                            if (val.Stats.Health > 0)
                            {
                                val.Stats.Health--;



                                myVariables._Players [i].Key.GetComponent <PlayerManager> ().GotTheKill(_OriginalWord.Length);           //Giving The Player That Wrote The Last Word The Score  //TODO Give Each Player Tagged Score?
                                myVariables._Players [i].Key.GetComponent <PlayerManager> ().ResetWord();                                //Giving The Player That Wrote The Last Word The Score  //TODO Give Each Player Tagged Score?

                                _ObjectHealth = ListOfWords.GetRandomWords((int)val.Stats.WordDifficulty);
                                _OriginalWord = _ObjectHealth;

                                myVariables.TextElement.text = "";                                //Removing Text So That I Can Add It Again With New Colors
                                ColorValue = FreeCharacterColor.r.ToString("X2") + FreeCharacterColor.g.ToString("X2") + FreeCharacterColor.b.ToString("X2") + FreeCharacterColor.a.ToString("X2");

                                for (int k = 0; k < _ObjectHealth.Length; k++)
                                {
                                    myVariables.TextElement.text += string.Format("<color=#" + ColorValue + ">{0}</color>", _ObjectHealth [k]);
                                }

                                return;
                            }
                            else
                            {
                                myVariables._Players [i].Key.GetComponent <PlayerManager> ().ResetWord();                                //Giving The Player That Wrote The Last Word The Score  //TODO Give Each Player Tagged Score?
                                myVariables._Players [i].Key.GetComponent <PlayerManager> ().GotTheKill(_OriginalWord.Length);           //Giving The Player That Wrote The Last Word The Score  //TODO Give Each Player Tagged Score?

                                //TheCreature.OnDestroyed ();TODO Destroy/SendDestroy Request
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }

        _WordLengths = 0;
        NullCheck    = 0;

        for (int i = 0; i < myVariables._Players.Count; i++)          //Iterating Through Once To Find The Two Players That Have Typed The Most. If Two Are The Same The The One That Tagged It Is The Leader
        {
            if (PlayersTypedCorrect [i] == true)
            {
                if (myVariables._Players [i].Value.Value [0].Length > _WordLengths)
                {
                    _2ndLongestPlayer = _LongestPlayer;
                    _LongestPlayer    = myVariables._Players [i];
                    NullCheck++;
                }
            }
        }

        _WordsToRemove = 0;
        myVariables.TextElement.text = "";                                                                                                            //Removing Text So That I Can Add It Again With New Colors

        if (NullCheck > 1)                                                                                                                            //Adding 2nd Place Player Color
        {
            _WordLengths = _2ndLongestPlayer.Value.Value [0].Length;                                                                                  //Length Of Player Word
            PlayerColor  = (Color32)_2ndLongestPlayer.Value.Key;                                                                                      //Player Color
            ColorValue   = PlayerColor.r.ToString("X2") + PlayerColor.g.ToString("X2") + PlayerColor.b.ToString("X2") + PlayerColor.a.ToString("X2"); //Setting Color, Only Way I Got It To Work

            for (int i = 0; i < _WordLengths; i++)                                                                                                    //Iterates Through And Adds The Letter Again But With Different Color
            {
                _WordsToRemove++;
                myVariables.TextElement.text += string.Format("<color=#" + ColorValue + ">{0}</color>", _ObjectHealth [i]);
            }
        }

        if (NullCheck > 0)                  //Adding 1nd Place Player Color
        {
            _WordLengths = _LongestPlayer.Value.Value [0].Length;
            PlayerColor  = (Color32)_LongestPlayer.Value.Key;
            ColorValue   = PlayerColor.r.ToString("X2") + PlayerColor.g.ToString("X2") + PlayerColor.b.ToString("X2") + PlayerColor.a.ToString("X2");

            for (int i = _WordsToRemove; i < _WordLengths; i++)
            {
                _WordsToRemove++;
                myVariables.TextElement.text += string.Format("<color=#" + ColorValue + ">{0}</color>", _ObjectHealth [i]);
            }
        }

        ColorValue = FreeCharacterColor.r.ToString("X2") + FreeCharacterColor.g.ToString("X2") + FreeCharacterColor.b.ToString("X2") + FreeCharacterColor.a.ToString("X2");

        for (int i = _WordsToRemove; i < _ObjectHealth.Length; i++)
        {
            myVariables.TextElement.text += string.Format("<color=#" + ColorValue + ">{0}</color>", _ObjectHealth [i]);
        }
    }