【问题标题】:Making a game with 4 possible answer buttons用 4 个可能的答案按钮制作游戏
【发布时间】:2013-08-16 23:22:39
【问题描述】:

我是 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);
}

【问题讨论】:

    标签: image actionscript-3


    【解决方案1】:

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

    //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();
        }}}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多