看板 Flash 關於我們 聯絡資訊
※ 引述《woodymonkey (小罐的吃太快)》之銘言: : 如果不出現一樣的問題: : 將所有的問題放在主場景的不同影格, : 然後產生一個陣列Array(20),用迴圈將隨機數字放入此陣列, : 陣列每一個元素內的數字注意不可重複。 : 定義一個全域變數y,初始值為0。 : 答對時用gotoAndPlay(Array(y)),並且將y加1。 想到另外一招 如果你有20格,就先讓個Array裝1~20 var array:Array = new Array(); for (var i:int = 0; i < 20; i++) { array[i] = i + 1; } //得到 [1, 2, 3, ..., 20] 然後用random決定這個Array裡面的一個數字 用過之後就把這個數字從Array裡面拔掉 之後再random決定的時候就絕對不會選到這個數字 if (array.length == ) { //沒題目了,跳到結尾 } var targetFrame:int = array[Math.floor((Math.random() * array.length))]; array = array.splice(targetFrame, 1); //拔掉用過的數字 gotoAndPlay(targetFrame); -- CJ Cat = Croa'J Cat = Cockroach Cat = 西街凱特 = 蜚蠊貓 = 蟑螂貓 Blog http://cjcat.blogspot.com Gallery http://cjcat2266.deviantart.com ptt2 Board CJWorkshop - 阿多比閃光(Adobe Flash)研討區 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.166.136.167
Jerrynet:Math.floor(Math.random()*(array.length-1)) ?? 04/03 00:21
cjcat2266:hmm... random() * 20會是0~19.999999,應該沒錯吧(?) 04/03 00:34
Jerrynet:我指的是20,每次都20?? 04/03 00:43
Jerrynet:splice之後再用20不會超過index嘛? 04/03 00:49
cjcat2266:對喔,忘記這點了XD 04/03 00:55
※ 編輯: cjcat2266 來自: 218.166.136.167 (04/03 00:56)