예제 #1
0
 public static void AddSpell(string spell_name, string[] spell_input, int id)
 {
     SpellCombo newCombo = new SpellCombo();
     newCombo.spell_input = spell_input;
     newCombo.spell_id = id;
     newCombo.spell_name = spell_name;
     allCombos.Add(newCombo);
 }
예제 #2
0
    public int CheckMatchingCombo(SpellCombo checkSpell)
    {
        // Print Commands
        PrintPressedKeys();

        string[] CheckCombo = checkSpell.spell_input;

        // Convert combo dictionary keys into ValidKey keys
        string[] newCombo = new string[CheckCombo.Length];
        for (int comboLetter = 0; comboLetter < CheckCombo.Length; comboLetter++)
        {
            
            for (int comboLetterLetter = 0; comboLetterLetter < CheckCombo[comboLetter].Length; comboLetterLetter++)
            {
                if (CheckCombo[comboLetter][comboLetterLetter] == "F"[0])
                {
                    newCombo[comboLetter] += KEY_FIRE;
                }
                if (CheckCombo[comboLetter][comboLetterLetter] == "W"[0])
                {
                    newCombo[comboLetter] += KEY_WATER;
                }
                if (CheckCombo[comboLetter][comboLetterLetter] == "E"[0])
                {
                    newCombo[comboLetter] += KEY_EARTH;
                }
                if (CheckCombo[comboLetter][comboLetterLetter] == "A"[0])
                {
                    newCombo[comboLetter] += KEY_AIR;
                }
            }
        }
      
        
        // Turn pressedkeys into a string array
        object[] pressedKeysArray = PressedKeys.ToArray();
        bool stillMatches = true;
        bool firstMatch = false;
        int whatPositionInPressedKeysMatch = 0;

        if(newCombo.Length > pressedKeysArray.Length)
        {
            // Doesn't match combo
            return -1;
        }

        // Need to match first character of combo with something in pressed keys array.
        for (int i = 0; i < pressedKeysArray.Length; i++)
        {
            KeyCommand keyP = (KeyCommand)pressedKeysArray[i];
            // cycle through, checking against the current combo until we make our first match
            if (keyP.keyPressed == newCombo[0])
            {
                firstMatch = true;
                whatPositionInPressedKeysMatch = i;
                break;
            }
        }

        // If there is no first match or if the length of the combo is longer than the input buffer's remaining space, return.
        if (firstMatch == false || whatPositionInPressedKeysMatch + newCombo.Length > pressedKeysArray.Length)
        {
            return -1;
        }

        for(int i = whatPositionInPressedKeysMatch; i < pressedKeysArray.Length; i++)
        {
            KeyCommand keyP = (KeyCommand)pressedKeysArray[i];
            int newComboLoc = i - whatPositionInPressedKeysMatch;
            if(newComboLoc < 0 || newComboLoc > newCombo.Length-1)
            {
                return -1;
            }
            if (keyP.keyPressed == newCombo[newComboLoc])
            {
                stillMatches = true;
            }
            else
            {
                stillMatches = false;
                break;
            }
        }
        
        if(!stillMatches)
        {
            // Matching failed in mid-combo check.
            return -1;
        }

        ////// All checks succeeded! COMBO IS HIT!!!
        print("PERFORMED COMBO! ");
        return checkSpell.spell_id;

        





    }