我目前正在开发类似于这款游戏的解读英语学习游戏: http://englishflashgames.blogspot.ca/2011/06/scrambled-words.html
我想要做的就是每次都要显示一个未加扰字的图片。我该怎么做呢?我将解读10种水果的名字。
感谢您的帮助。
package
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
public class Game extends MovieClip
{
public function Game()
{
words = new Array();
words_backup = new Array();
tileArray = new Array();
targetArray = new Array();
scramble_Array = new Array();
unscramble_Array = new Array();
animals_b = new Array("peach","apple","strawberry","melon","grapes","cherry","pineapple","tomato","banana","orange");
super();
addFrameScript(0,frame1);
}
public var inici:MovieClip;
public var bt1:SimpleButton;
public var color:MovieClip;
var words:Array;
var words_backup:Array;
var rand1:int;
var rand2:int;
var i:int;
var ii:int;
var ques_num:int;
var current_word:String;
var user_ans:String;
var tileArray:Array;
var targetArray:Array;
var scramble_Array:Array;
var unscramble_Array:Array;
var temp:String;
var flag:Boolean;
var checker:button_chk;
var f1:feedback1;
var f2:feedback2;
var f3:feedback3;
var pauser:Boolean;
var randomnum:int;
var animals_b:Array;
public function startGame(param1:*, param2:*) : *
{
inici.visible = false;
color.x = param2.x;
color.y = param2.y;
if(words.length > 0)
{
i = 0;
while(i < tileArray.length)
{
removeChild(tileArray[i]);
removeChild(targetArray[i]);
i++;
}
tileArray = [];
targetArray = [];
scramble_Array = [];
unscramble_Array = [];
}
words = param1.slice();
words_backup = param1;
getword();
checker = new button_chk();
addChild(checker);
checker.x = 290;
checker.y = 450;
checker.addEventListener(MouseEvent.CLICK,check_answer);
}
public function getword() : *
{
trace(words);
if(words.length <= 0)
{
words = words_backup.slice();
}
randomnum = Math.floor(Math.random() * words.length);
current_word = words[randomnum].toUpperCase();
words.splice(randomnum,1);
setTiles(current_word.length);
ques_num++;
}
public function setTiles(param1:*) : *
{
var _loc2_:Tile = null;
var _loc3_:Placeholder = null;
tileArray = [];
i = 0;
while(i < param1)
{
_loc2_ = new Tile();
addChild(_loc2_);
_loc2_.x = 350 - param1 * 25 + param1 % 2 * 25 + i * 50;
_loc2_.y = 350;
_loc2_.tag = i;
_loc2_.original_posx = _loc2_.x;
_loc2_.original_posy = _loc2_.y;
tileArray[i] = _loc2_;
_loc3_ = new Placeholder();
addChild(_loc3_);
_loc3_.x = 350 - param1 * 25 + param1 % 2 * 25 + i * 50;
_loc3_.y = 400;
targetArray[i] = _loc3_;
i++;
}
scramble_word(param1);
}
public function scramble_word(param1:*) : *
{
i = 0;
while(i < param1)
{
scramble_Array[i] = current_word.slice(i,i + 1);
i++;
}
i = 0;
while(i < 15)
{
rand1 = Math.ceil(Math.random() * param1) - 1;
rand2 = Math.ceil(Math.random() * param1) - 1;
temp = scramble_Array[rand1];
scramble_Array[rand1] = scramble_Array[rand2];
scramble_Array[rand2] = temp;
i++;
}
if(current_word == scramble_Array.join(""))
{
trace(scramble_Array.join(""));
scramble_Array.reverse();
}
i = 0;
while(i < param1)
{
tileArray[i].letter.text = scramble_Array[i];
i++;
}
addListeners(param1);
}
public function addListeners(param1:*) : *
{
i = 0;
while(i < param1)
{
tileArray[i].mouseChildren = false;
tileArray[i].buttonMode = true;
tileArray[i].addEventListener(MouseEvent.MOUSE_DOWN,pickup);
tileArray[i].addEventListener(MouseEvent.MOUSE_UP,drop);
i++;
}
}
public function pickup(param1:MouseEvent) : *
{
if(!pauser)
{
param1.target.startDrag(true);
this.setChildIndex(MovieClip(param1.target),this.numChildren - 1);
}
}
public function drop(param1:MouseEvent) : *
{
param1.target.stopDrag();
flag = false;
i = 0;
while(i < targetArray.length)
{
if(targetArray[i].hitTestObject(param1.target))
{
param1.target.x = targetArray[i].x;
param1.target.y = targetArray[i].y;
flag = true;
}
i++;
}
i = 0;
while(i < tileArray.length)
{
if((tileArray[i].hitTestObject(param1.target)) && !(tileArray[i] == param1.target))
{
flag = false;
}
i++;
}
if(!flag)
{
param1.target.x = param1.target.original_posx;
param1.target.y = param1.target.original_posy;
}
}
public function check_answer(param1:MouseEvent) : *
{
user_ans = "";
i = 0;
while(i < targetArray.length)
{
ii = 0;
while(ii < tileArray.length)
{
if(tileArray[ii].x == targetArray[i].x && tileArray[ii].y == targetArray[i].y)
{
user_ans = user_ans + tileArray[ii].letter.text;
}
ii++;
}
i++;
}
trace("user_ans: " + user_ans);
trace("jordi_ans: " + user_ans);
trace("current_word: " + current_word);
if(user_ans == current_word)
{
f1 = new feedback1();
addChild(f1);
f1.x = 0;
f1.y = 0;
pauser = true;
f1.buttonMode = true;
f1.addEventListener(MouseEvent.CLICK,clear_board);
}
else
{
f2 = new feedback2();
addChild(f2);
f2.x = 0;
f2.y = 0;
pauser = true;
f2.buttonMode = true;
f2.addEventListener(MouseEvent.CLICK,continue_on);
}
}
public function continue_on(param1:MouseEvent) : *
{
f2.removeEventListener(MouseEvent.CLICK,continue_on);
removeChild(f2);
pauser = false;
}
public function clear_board(param1:MouseEvent) : *
{
f1.removeEventListener(MouseEvent.CLICK,continue_on);
removeChild(f1);
pauser = false;
i = 0;
while(i < tileArray.length)
{
removeChild(tileArray[i]);
removeChild(targetArray[i]);
i++;
}
tileArray = [];
targetArray = [];
scramble_Array = [];
unscramble_Array = [];
if(ques_num == words.length + 99999)
{
removeChild(checker);
f3 = new feedback3();
addChild(f3);
f3.x = 0;
f3.y = 0;
}
else
{
getword();
}
}
function frame1() : *
{
bt1.addEventListener(MouseEvent.CLICK,function():*
{
startGame(animals_b,bt1);
});
}
}
}