作者cjcjovup (啊嚓!)
看板Flash
標題[問題] 選擇題隨機出幾題
時間Thu Aug 20 11:31:19 2009
我之前有做過一個隨機出題
有15題.然後它會把15題都隨機出完
那假設15題只要出其中的5題就會跳到結束頁的話要怎麼修@@
附上程式碼:
第一格:(裡面的Q1~QEnd是第二格到最後一格的影格名稱)
stop();
stopAllSounds();
var totalQ:
Number = 15;
var choiceQ:
Number = 15;
var nextQ:
Number = 0;
var selQ:
Array =[
"Q1",
"Q2",
"Q3",
"Q4",
"Q5",
"Q6",
"Q7",
"Q8",
"Q9",
"Q10",
"Q11",
"Q12",
"Q13",
"Q14",
"Q15",
"QEnd"];
for(i = 0; i < totalQ; i++)
{
j =
Math.floor(
Math.random()
* totalQ);
temp = selQ[i];
selQ[i] = selQ[j];
selQ[j] = temp;
}
selQ[choiceQ] = selQ[totalQ];
start_btn.
onPress =
function() {
gotoAndPlay(selQ[nextQ++]);
}
第二格:(之後的三~十六格都差不多)
stop();
stopAllSounds();
var rightSound:
Sound =
new Sound();
rightSound.
attachSound(
"1");
var wrongSound:
Sound =
new Sound();
wrongSound.
attachSound(
"bibi");
var clickedTimes = 0;
a1.
enabled =
true;
a2.
enabled =
true;
a3.
enabled =
true;
next_btn.
_visible =
false;
selIcon_mc.
_visible =
false;
var sortA:
Array = [
"a1",
"a2",
"a3"];
for(j = 0; j < 3; j++)
{
k = Math.floor(
Math.random()
* 3);
temp = sortA[j];
sortA[j] = sortA[k];
sortA[k] = temp;
}
this[sortA[0]]
._x = 50;
this[sortA[0]]
._y = 200;
this[sortA[1]]
._x = 50;
this[sortA[1]]
._y = 275;
this[sortA[2]]
._x = 50;
this[sortA[2]]
._y = 350;
a1.
onPress =
function() {
selIcon_mc.
_visible =
true;
selIcon_mc
._x =
25;
selIcon_mc
._y =
this._y;
feedback_lbl
.text =
"O";
stopAllSounds();
rightSound.
start();
next_btn.
_visible =
true;
a1.
enabled =
false;
a2.
enabled =
false;
a3.
enabled =
false;
}
a2.
onPress =
function() {
selIcon_mc.
_visible =
true;
selIcon_mc.
_x = 25;
selIcon_mc.
_y =
this._y;
feedback_lbl
.text =
"X";
stopAllSounds();
wrongSound.
start();
}
a3.
onPress =
function() {
selIcon_mc.
_visible =
true;
selIcon_mc.
_x = 25;
selIcon_mc.
_y =
this._y;
feedback_lbl
.text =
"X";
stopAllSounds();
wrongSound.
start();
}
Qnum_lbl
.text = nextQ
.toString() +
".";
next_btn
.onPress =
function() {
gotoAndPlay(selQ[nextQ++]);
}
網址:
http://140.130.43.178/~tschung97eid/G4/s0963373~2/select.swf
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.127.140.238
→ cjcjovup:這個程式是助教教我們的.不過他現在畢業了沒辦法問他@@ 08/20 11:32
※ 編輯: cjcjovup 來自: 59.127.140.238 (08/20 11:37)
推 cjcat2266:code highlight很認真,推一個 08/20 11:38
※ 編輯: cjcjovup 來自: 59.127.140.238 (08/20 11:42)
推 stopcrying:試著在第一格加上變數用來紀錄已經答對幾格,並在換問 08/20 12:08
→ stopcrying:題時檢查答對題數以決定要不要跳到結束畫面這樣? 08/20 12:09