gpt4 book ai didi

JavaScript 3 维数组

转载 作者:行者123 更新时间:2023-12-02 18:20:19 25 4
gpt4 key购买 nike

我想用 Javascript 创建一个 DOS 风格的游戏,但我无法正确显示 map 。

这是 Windows 控制台中的数组:

char Map[1][10][20] = {
"####################",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"####################",
};

这就是我的 javascript 代码

var Map = {
"#":["#","#","#","#","#","#","#","#","#","#","#","#","#","#"],
"#":["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
"#":["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
"#":["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
"#":["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
"#":["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
"#":["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
"#":["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
"#":["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
"#":["#","#","#","#","#","#","#","#","#","#","#","#","#","#"]
};

本质上我希望它准确地输出第一个数组。我应该能够做其他的事情。

最佳答案

使用数组,而不是使用相同键定义每一行的对象(如果不无效,则相互覆盖1):

var Map = [
["#","#","#","#","#","#","#","#","#","#","#","#","#","#"],
["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
["#"," "," "," "," "," "," "," "," "," "," "," "," ","#"],
["#","#","#","#","#","#","#","#","#","#","#","#","#","#"]
];

1:在严格模式下,您将收到语法错误

关于JavaScript 3 维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18885687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com