2017-02-07 3 views
0

У меня есть уровень викторины 1 в кадре 2-11, а кадр 12 - результат викторины и уровень 2 викторины в кадре 13-22 с результатом в кадре 23 ..Flash AS3 - как рандомизировать каждый кадр во время игры

я хочу, чтобы рандомизировать викторины между 2-11 и рандомизировать викторины в рамке 13-22,

Пример:

  1. первой викторины рама 3
  2. второго викторины рама 6
  3. третьего викторины кадр 2
  4. (... ...)
  5. (п) й ... ... ... (последний кадр, который еще не показывает)

Я м, используя этот код в кадре 1:

stop(); 
autom.play(); 
soal = 1; 
var pic:Number=11; 
var randomFrame:Number = Math.ceil(Math.random()*pic); 
trace(randomFrame); 
gotoAndStop(randomFrame); 
nextFrame(); 

но вспышка рандомизации только первый раз

я хочу знать, если есть способ сделать это можно сделать вспышку работает хорошо, как то, что я хочу в Пример ???

EDIT:

full code of frame 1

var kunci:String, 
jawaban:String, 
dikunci:String, 
soal:int, 
betul:int, 
salah:int, 
hati:int=0, 
nilai:int, 
mcres:mcrespon = new mcrespon(); 
mcres.x = 20; 
mcres.y = 40; 
mcres.scaleX = 3; 
mcres.scaleY = 3; 

tbhome.addEventListener(MouseEvent.MOUSE_UP,clikmenu); 
tbmulai.addEventListener(MouseEvent.CLICK,cliklanjut); 
function cliklanjut(event:MouseEvent):void 
{ 
    stop(); 
    autom.play(); 
    soal = 1; 
    betul = 0; 
    salah = 0; 
    nilai = 0;6; 
    var pic:Number=22; 
    var randomFrame:Number = Math.ceil(Math.random()*pic); 
    trace(randomFrame); 
    gotoAndStop(randomFrame); 
    nextFrame(); 
    /*stop(); 
    autom.play(); 
    soal = 1; 
    var pic:Number=11; 
    var randomFrame:Number = Math.ceil(Math.random()*pic); 
    trace(randomFrame); 
    gotoAndStop(randomFrame); 
    nextFrame();*/ 
} 
function clika(event:MouseEvent):void 
{ 
    autom.play(); 
    jawaban = "a"; 
    cocokan(); 
} 
function clikb(event:MouseEvent):void 
{ 
    autom.play(); 
    jawaban = "b"; 
    cocokan(); 
} 
function clikc(event:MouseEvent):void 
{ 
    autom.play(); 
    jawaban = "c"; 
    cocokan(); 
} 
function clikd(event:MouseEvent):void 
{ 
    autom.play(); 
    jawaban = "d"; 
    cocokan(); 
} 
function cocokan() 
{ 
    addChild(mcres); 
    if (jawaban == kunci) 
    { 
     mcres.gotoAndPlay(2); 
     setTimeout(lanjutbenar,0); 
    } 
    else 
    { 
     mcres.gotoAndPlay(16); 
     setTimeout(lanjutsalah,0); 
    } 
} 
function copot() 
{ 
    removeChild(mcres); 
} 
function lanjutbenar() 
{ 
    betul += 1; 
    soal += 1; 
    copot(); 
    nextFrame(); 
} 
function lanjutsalah() 
{ 
    salah += 1; 
    hati += 1; 
    mchati.nextFrame(); 
    copot(); 
    if (hati>=3) 
    { 
     gotoAndStop("gameover"); 
    } 
    else 
    { 
     soal += 1; 
     nextFrame(); 
    } 
} 
function clikulang(event:MouseEvent):void 
{ 
    autom.play(); 
    soal = 1; 
    betul = 0; 
    salah = 0; 
    nilai = 0; 
    hati = 0; 
    gotoAndStop(1); 
} 
function kuncinya(sikunci:String) 
{ 
    soalnya.text = "Soal no " + soal.toString() + "/20"; 
    pila.addEventListener(MouseEvent.CLICK,clika); 
    pilb.addEventListener(MouseEvent.CLICK,clikb); 
    pilc.addEventListener(MouseEvent.CLICK,clikc); 
    pild.addEventListener(MouseEvent.CLICK,clikd); 
    kunci = sikunci; 
} 

function diresumequis(batasbagus:int,komen1:String,komen2:String,komen3:String) 
{ 
    stop(); 
    tbulang.addEventListener(MouseEvent.CLICK,clikulang); 
    tbnextlevel.addEventListener(MouseEvent.CLICK,cliklanjut); 
    betulnya.text = "Benar = " + betul.toString(); 
    salahnya.text = "Salah = " + salah.toString(); 
    nilai = betul/10 * 100; 
    nilainya.text = "Nilai = " + nilai.toString(); 

    if (nilai == 100) 
    { 
     komentar.text = komen1; 
    } 
    else 
    { 
     if (nilai>=batasbagus) 
     { 
      komentar.text = komen2; 
     } 
     else 
     { 
      komentar.text = komen3; 
     } 
    } 
} 

in frame 2 till 11 are a same code like this :

kuncinya("a") // the correct answer of a question; 
+0

любые идеи, пожалуйста? –

ответ

2

Вам необходимо отслеживать, какие кадры вы были, так что вы не получите повторы и поэтому вы знаете, когда викторина будет выполнена.

Самый простой способ сделать это, вероятно, иметь массив ваших кадров вопроса, а затем удалить вопрос из этого массива всякий раз, когда вы заполняете вопрос.

Что-то вдоль этих линий:

Рама 1 Код:

//a var to hold the current quiz (an array/collection of frames) 
var curQuiz:Array; 

//a var to hold the ending frame of the current quiz 
var curQuizEndFrame:int; 

//the frame number or labels that are questions for this quiz 
var quiz1:Array = [2,3,4,5,6,7,8,9,10,11]; 
var quiz2:Array = [13,14,15,16]; //etc 

//create a function to start a quiz with two parameters - the quiz array to start, and the frame to goto once all the questions have been asked. 
function startQuiz(quiz:Array, endFrame:int):void { 
    curQuizEndFrame = endFrame; 
    curQuiz = quiz.concat(); //this copies the passed in quiz array (so you don't modify the original) 

    //randomize the question order 
    curQuiz.sort(randomizeArray); 

    //now call nextQuestion (created below) to go to the first question 
    nextQuestion(); 
} 

//create a function to show the next question. Call this whenever the user answers a question - the e parameter is just there in case you want to call this function from an event handler 
function nextQuestion(e:Event = null):void { 
    //check if there is a current quiz, and if there are still questions left in it 
    if(curQuiz && curQuiz.length > 0){ 
     //goto the next question in the quiz 
     gotoAndStop(curQuiz.pop()); //pop removes the last element from the array and returns its value 
    }else{ 
     if(curQuiz){ 
      //if we get here, it means the quiz exists but doesn't have any questions left, so go to the end frame 
      gotoAndStop(curQuizEndFrame); //quiz is finished 
     }else{ 
      //quiz hasn't started yet, do something like tell the user to start the quiz 
     } 
    } 
} 

//a randomize sort function for arrays 
function randomizeArray(a:*,b:*):int { 
    return(Math.random() > .5) ? 1 : -1; 
} 

Затем, когда вы закончите вопрос, звоните nextQuestion(); Это должно, вероятно, будет на следующий обработчик нажатия кнопки на каждом из вопросники.

nextBtn.addEventListener(MouseEvent.CLICK, nextQuestion, false, 0, true); 

Всякий раз, когда вы хотите, чтобы начать новую викторину, вызовите startQuiz и передать в массиве викторины и заканчивая кадр.

Например:

startQuiz(quiz1, 12); 
+0

может дать другой простой код для этого, я не могу хорошо прочитать код, я извиняюсь за это. | у вас есть идея моего полного кода в frame1? –

+0

и сэр, можно воссоздать код ура выше в 1 функции? –

+0

Я не понимаю, что делает большинство вашего кода, можете ли вы добавить комментарии к своим vars, чтобы объяснить, для чего они нужны? (так как я не знаю язык, который вы используете) – BadFeelingAboutThis

Смежные вопросы