用户:
Mini_edit查看:7 回复:5 评论:7 创建时间:2023-04-14T21:41:00
希望的效果:
玩家和一个NPC互动就会触发一个选择框(【解密密码,加密字符串】)
选择解密密码就能解密密码,选择加密字符串就能加密字符串:
具体想要的效果:
有两个列表:
hanzi和mima
里面有装着密码和汉字——
如:
hanzi=[甲,乙,丙,丁,]
mima=[5·2·12,1·1·2,5·1·22,2·1·3]
然后如果要加密“甲乙丙丁”这一句话
系统就会跳出“5·2·12!1·1·2!5·1·22!2·1·3”
选择解密则反之
啊谢谢提供代码的人~~~~
SCS_user_LoeheodVOQ> encodeURI('114汉字514')
< '114%E6%B1%89%E5%AD%97514'
> decodeURI('114%E6%B1%89%E5%AD%97514')
< '114汉字514'
可以使用encodeURI和decodeURI函数
点赞0
评论
翎with珝用最笨的一个一个数据的判断
console.clear()
const w_p = {
'甲': '5·2·12',
'乙': '1·1·2',
'丙': '5·1·22',
'丁': '2·1·3'
};
const p_w = {
'5·2·12': '甲',
'1·1·2': '乙',
'5·1·22': '丙',
'2·1·3': '丁'
};
var npc = world.querySelector('#吉');
npc.enableInteract = true;
npc.interactRadius = 16;
npc.interactHint = `加/解密`;
npc.onInteract(async ({ entity }) => {
let result = await entity.player.dialog({
type: Box3DialogType.SELECT,
content: `你要干什么`,
options: ['加密', '解密'],
});
if (!result) return;
if (result) {
if (result.value == '加密') {
let text = await entity.player.dialog({
type: Box3DialogType.INPUT,
content: `加密文字`,
confirmText: '确定',
});
if (!text) return;
if (text) {
let password = '';
for (let i = 0; i <= text.length - 1; i++) {
password = password + w_p[text[i]] + '!'
};
password = password.substring(0, password.lastIndexOf('!'));
entity.player.dialog({
type: Box3DialogType.TEXT,
content: `${text}的加密结果为:\n${password}`,
});
};
} else if (result.value == '解密') {
let text = await entity.player.dialog({
type: Box3DialogType.INPUT,
content: `解密文字`,
confirmText: '确定',
});
if (!text) return;
if (text) {
let passwords = [];
let writing = '';
passwords = text.split('!');
for (let i = 0; i <= passwords.length - 1; i++) {
writing = writing + p_w[passwords[i]] + ','
};
writing = writing.substring(0, writing.lastIndexOf(','));
entity.player.dialog({
type: Box3DialogType.TEXT,
content: `${text}的加密结果为:\n${writing}`,
});
};
};
};
});点赞0
评论