0

我正在使用 HTML5/jQuery + PhoneGap 构建一个基于回合的 iPad 游戏。

在玩家每回合之后,我们希望显示一些随机的基于文本的信息。通常是一个句子。

总的来说,我们可能有大约 100 个不同的句子,分为 4 组。

就性能而言,解决此问题的正确方法是什么?

这么多内容是否适合简单地存储在 4 个 javascript 数组中?还是太多了?如果太多,创建一个单独的 JSON 文件会更有意义吗?还是使用本地存储?或者那些会矫枉过正?还是我们应该在 HTML DOM 中“存储”这 100 位文本并从那里访问它?其他想法?

4

2 回答 2

0

100 句话是微不足道的,使用数组不应该对性能产生任何影响,但你可以随时尝试......

http://jsfiddle.net/ZpCfB/(有100个)

http://jsfiddle.net/ZpCfB/1/(有4000)

var sentences = [[], [], [], []],
    groupCount = 4,
    i = 0,
    sentence = 'This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence This is a very very very long sentence sdfsdfsdf sdfsdfsdfsdf sdfsd sdfsdfsdfsdf sdfsd fsdfsdfsdf s.';

for (; i < 25; i++) {
    for (x = 0; x < 4; x++) {
        sentences[x].push(sentence);
    }
}

console.log(sentences);
于 2013-04-10T23:06:48.667 回答
0

使用 localStorage 并将 25 存储在一个由任何字符(例如“^”)分隔的 localStorage 对象中,然后使用 split() 访问字符串。

localStorage.str = "foo^bar^baz"; //etc..
var str1 = localStorage.str;
str1.split("^");
for(var i = 0; i &lt; str.length;i++){
alert(str1[i])
}
于 2013-04-10T22:59:13.333 回答