有效的方式,在AS3多个阵列工作多个、阵列、有效、方式

2023-09-08 14:26:05 作者:╰︶梦落、晚安′

我要创建一个益智游戏,在Flash / AS3。它使用约30〜40组字。我想要做的是中放入一个随机组词在比赛的开始和使用后,我要加载另一个随机组等。什么是解决这个问题的最好方法是什么?我应该有多个阵列,我将使用基于随机数switch语句中选择,或者我应该把他们都为一个多维数组?每个组词可以包含多达2000字。

I'm creating a puzzle game in Flash/AS3. It uses about 30 to 40 groups of words. What I want to do is to load one random group of words in the beginning of the game and after using them, I want to load another random group and so on. What is the best way to solve this? Should I have multiple arrays which I will select from using switch statement based on random number or should I put them all into one multidimensional array? Every group of words could contain up to 2000 words.

推荐答案

这是更好地使用XML创建wordgroups,并轻松地将它们拉。所以,我的意思是,你用多维数组的效率。

It's better you use xml for creating wordgroups and to pull them easily. So, i mean, it's efficient you use multidimensional arrays.

var wordgroups:Array = new Array();
wordgroups.push(new Array("word1", "word3", "word5"), new Array("word2", "word4", "word6")); //you can easily create whole this multidimensional array with xml

wordgroups.shuffle(); //shuffles array (flashpunk library have this function, you may check it out and clone it's function if you can)

var selectedwordgroup:Array;
selectedwordgroup = wordgroups.pop(); //you can easily take a word group from that array and it removes selected wordgroup from the "wordgroups" array automatically with pop() function.

那么XML的东西

What about XML stuff

这就是一个样本* .xml文件:

Thats a sample *.xml file:

<?xml version="1.0" encoding="utf-8"?>
<wordstuff>
   <wordgroups>
      <group>word1,word2,word3,word4,word5,word6</group>
      <group>word7,word8,word9,word10,word11,word12</group>
      <group>word13,word14,word15,word16,word17,word18</group>
   </wordgroups>
</wordstuff>

这是一个简单的拉从XML数据(你要嵌入您的XML的东西到你的游戏,所以,你不需要任何URL加载的对象,你可以将它嵌入像你嵌入图像文件进入游戏,有少许差别) 那么您可以创建此嵌入式XML阵列

and this is a sample to pull data from xml (you're going to embed your xml stuff to your game, so, you don't need any url loader object, you can embed it like you're embedding image files into your game, with a little difference) then you can create arrays with this embedded xml

var pulledgroups:Array = new Array();

var my_xml:XML = WORDSTUFF //that's embedded file
var wordgroups:XMLList = my_xml.wordgroups.group;
var group:XML;
for each (group in wordgroups)
{
   var pulledwordgroup:Array = group.split(",");
   pulledgroups.push(pulledwordgroup);
}

这一切,这个单一code段,翻出所有的数据在同一时间

THAT'S ALL, this single code paragraph, pulls all data at the same time