Unity - 如何将单词翻译成L337表格?

时间:2017-10-19 00:23:22

标签: c# unity3d

我正在尝试创建一个可以在输入字段中输入单词的游戏,当L337切换设置为开启时,该单词的L337版本会出现输出文本,这几乎可以用数字替换一些字母和其他信件。它基本上有效,但我无法将结果加密成L337格式。无论切换是打开还是关闭,它都是相同的。有人可以帮帮我吗?

public class Encryption : MonoBehaviour
{
InputField input;
public Text output;
string inputText;

public Toggle L337Toggle;

 void Start()
{
    L337Toggle.isOn = false;


}
private void Update()
{
   inputText = input.text;
    output.text = inputText;

    var textEncryption = new TextEncryption(inputText);
    var L337Encryption = new L337Encryption(textEncryption);

    if (Input.GetKeyDown("enter"))
    {
        if (L337Toggle.isOn == true)
        {
            string result = L337Encryption.Encrypt();
        }
    }
}


public interface IEncryption
{
    string Encrypt();
}

public class TextEncryption : IEncryption
{
    private string originalString;

    public TextEncryption(string original)
    {
        originalString = original;
    }
    public string Encrypt()
    {
        Debug.Log("Encrypting Text");
        return originalString;
    }
}

public class L337Encryption : IEncryption
{
    private IEncryption _encryption;

    public L337Encryption(IEncryption encryption)
    {
        _encryption = encryption;
    }
    public string Encrypt()
    {
        Debug.Log("Encrypting L337 Text");
        string result = _encryption.Encrypt();
        result = result.Replace('a', '4').Replace('b', '8').Replace('e', '3').Replace('g', '6').Replace('h', '4').Replace('l', '1')
            .Replace('0', '0').Replace('q', '9').Replace('s', '5').Replace('t', '7');

        return result;
    }
}
}

1 个答案:

答案 0 :(得分:2)

您声明加密结果,但从不使用它。加上这个:

string result = L337Encryption.Encrypt();
output.text = result;