用4个可能的答案按钮制作游戏

时间:2013-08-16 23:22:39

标签: image actionscript-3

我是ActionScript-3的新手,我正在尝试制作游戏以了解更多信息。

对于每个显示的图片,我希望有4个选项(按钮),其中只有一个是正确的。但是我怎样才能使按钮中的文本随机。

正如你所看到的,我已经做到了,所以第4个按钮始终是正确的答案。我不想为所显示的每张图片做出所有这些事情......对于无意义的代码。

任何人都可以帮助我吗?如果您需要额外的信息,我很乐意提供。

var k:int;
for(k=1;k<=3;k++)
{
GAME.variante.buttonMode=true;
GAME.variante.addEventListener(MouseEvent.MOUSE_OVER,mouse_over_variante);
GAME.variante.addEventListener(MouseEvent.MOUSE_OUT,mouse_out_variante);
GAME.variante.varianta_corecta.addEventListener(MouseEvent.CLICK,variante);
GAME.variante.varianta_gresita1.addEventListener(MouseEvent.CLICK,variante_gresiteunu);
GAME.variante.varianta_gresita2.addEventListener(MouseEvent.CLICK,variante_gresitedoi);
GAME.variante.varianta_gresita3.addEventListener(MouseEvent.CLICK,variante_gresitetrei);


GAME.varianta1.text = "Cameleon";
GAME.varianta2.text = "Snake";
GAME.varianta3.text = "Frog";
GAME.varianta4.text = "Snail";

function variante_gresiteunu(e:MouseEvent){
if (varianta_gresita_apasata1 == 1){
totalScore -= score_variante_gresite;
GAME.text1.text = totalScore;
    varianta_gresita_apasata1 = 2;
    }
}
function variante_gresitedoi(e:MouseEvent){
if  (varianta_gresita_apasata2 == 1){
totalScore -= score_variante_gresite;
GAME.text1.text = totalScore;
    varianta_gresita_apasata2 = 2;
}
}
function variante_gresitetrei(e:MouseEvent){
if  (varianta_gresita_apasata3 == 1){
totalScore -= score_variante_gresite;
GAME.text1.text = totalScore;
    varianta_gresita_apasata3 = 2;
}
}
}
GAME.extra_points.visible = false;
function variante (e:MouseEvent) {
if (GAME.stichere.sticker1.currentFrame == (1)){
GAME.extra_points.visible = true;
GAME.extra_points.plus_ten1.gotoAndPlay(1);
}
//go to great job screen
GAME.greatJob.stars.gotoAndPlay(1);
GAME.greatJob.visible = true;
}
function mouse_over_variante (e:MouseEvent) {
trace(e.target.name);
e.target.gotoAndPlay(1);
}
function mouse_out_variante (e:MouseEvent) {
e.target.gotoAndStop(1);
}

1 个答案:

答案 0 :(得分:0)

  

你想要有4张图片,它们会被测试吗?   图像下方的文字将是随机的。我看到了你的代码和我   承认我很困惑。我做了一个不同的。   我不认为这段代码与你的要求有点不同,但我认为它会&gt;给你一些新的想法,并帮助你的应用程序......

//start button added on the sceen named f3toc. I give a function name for him f3roll.
f3toc.addEventListener(MouseEvent.CLICK,f3roll);

function f3roll(e:MouseEvent):void{

//creating variables for the picture.
var bola:Number
var quadrado:Number
var pentagono:Number
//Here is just a randomization code, you can change it to the what you want to use after the =

    bola = Math.ceil(Math.random() * 10);
    pentagono = Math.ceil(Math.random() * 10);
    f3res1_txt.text = String (bola + 8 + 8);
    f3res2_txt.text = String(bola - 1 + bola);
    f3res3_txt.text = String (pentagono + 10 - bola);

//converting number to string so we can put tem into the text fields. 
var pentagonotring:String = pentagono.toString();
var bolastring:String = bola.toString();

//function to check wen the name is correct. each wrong do nothing and every correct add 1 to a variable, in the end wen this variable reach 3 it does something.

    f3check_bnt.addEventListener (MouseEvent.CLICK, f3check);
function f3check (e:MouseEvent):void{
    if (f3inp2_txt.text == pentagonotring){
        f3ver_ext2.text = "Correct"
        } else {f3ver_ext2.text = "Wrong";}
    if (f3inp1_txt.text == bolastring){
        f3ver_ext1.text = "Correct"
        }else {f3ver_ext1.text = "Wrong";}

// function to check wen the variable pass reach 3  
pass = 0;
    if  (f3ver_ext1.text == "Correct"){
        pass++
    }
    if  (f3ver_ext2.text == "Correct"){
        pass++

    if  (pass == 3){
        nextFrame();
    }}}}