我正在尝试制作 Bingo 票 (Housie) 生成器,但我遇到了一些问题。
通常,每行包含五个数字和四个沿行随机分布的空格。数字按列分配(1-9、10-19、20-29、30-39、40-49、50-59、60-69、70-79 和 80-90)。我的生成器如下所示:
如您所见,我无法设法每行有 5 个数字。我的代码如下(我使用的是RandomPlus类):
package com.demstra.Ticket {
import flash.display.MovieClip;
public class Ticket extends MovieClip {
private var startNumColumn_1:Number = 1;
private var endNumColumn_1:Number = 9;
private var startNumColumn_2:Number = 10;
private var endNumColumn_2:Number = 19;
private var startNumColumn_3:Number = 20;
private var endNumColumn_3:Number = 29;
private var startNumColumn_4:Number = 30;
private var endNumColumn_4:Number = 39;
private var startNumColumn_5:Number = 40;
private var endNumColumn_5:Number = 49;
private var startNumColumn_6:Number = 50;
private var endNumColumn_6:Number = 59;
private var startNumColumn_7:Number = 60;
private var endNumColumn_7:Number = 69;
private var startNumColumn_8:Number = 70;
private var endNumColumn_8:Number = 79;
private var startNumColumn_9:Number = 80;
private var endNumColumn_9:Number = 90;
private var rp1:RandomPlus = new RandomPlus(startNumColumn_1, endNumColumn_1);
private var rp2:RandomPlus = new RandomPlus(startNumColumn_2, endNumColumn_2);
private var rp3:RandomPlus = new RandomPlus(startNumColumn_3, endNumColumn_3);
private var rp4:RandomPlus = new RandomPlus(startNumColumn_4, endNumColumn_4);
private var rp5:RandomPlus = new RandomPlus(startNumColumn_5, endNumColumn_5);
private var rp6:RandomPlus = new RandomPlus(startNumColumn_6, endNumColumn_6);
private var rp7:RandomPlus = new RandomPlus(startNumColumn_7, endNumColumn_7);
private var rp8:RandomPlus = new RandomPlus(startNumColumn_8, endNumColumn_8);
private var rp9:RandomPlus = new RandomPlus(startNumColumn_9, endNumColumn_9);
private var column_1:Array = new Array
(rp1.getNum(), rp1.getNum(), rp1.getNum(), rp1.getNum(), rp1.getNum(), rp1.getNum(), rp1.getNum(), rp1.getNum(), rp1.getNum(),
"", "", "", "", "", "", "", "", "");
private var column_2:Array = new Array
(rp2.getNum(), rp2.getNum(), rp2.getNum(), rp2.getNum(), rp2.getNum(), rp2.getNum(), rp2.getNum(), rp2.getNum(), rp2.getNum(), rp2.getNum(),
"", "", "", "", "", "", "", "");
private var column_3:Array = new Array
(rp3.getNum(), rp3.getNum(), rp3.getNum(), rp3.getNum(), rp3.getNum(), rp3.getNum(), rp3.getNum(), rp3.getNum(), rp3.getNum(), rp3.getNum(),
"", "", "", "", "", "", "", "");
private var column_4:Array = new Array
(rp4.getNum(), rp4.getNum(), rp4.getNum(), rp4.getNum(), rp4.getNum(), rp4.getNum(), rp4.getNum(), rp4.getNum(), rp4.getNum(), rp4.getNum(),
"", "", "", "", "", "", "", "");
private var column_5:Array = new Array
(rp5.getNum(), rp5.getNum(), rp5.getNum(), rp5.getNum(), rp5.getNum(), rp5.getNum(), rp5.getNum(), rp5.getNum(), rp5.getNum(), rp5.getNum(),
"", "", "", "", "", "", "", "");
private var column_6:Array = new Array
(rp6.getNum(), rp6.getNum(), rp6.getNum(), rp6.getNum(), rp6.getNum(), rp6.getNum(), rp6.getNum(), rp6.getNum(), rp6.getNum(), rp6.getNum(),
"", "", "", "", "", "", "", "");
private var column_7:Array = new Array
(rp7.getNum(), rp7.getNum(), rp7.getNum(), rp7.getNum(), rp7.getNum(), rp7.getNum(), rp7.getNum(), rp7.getNum(), rp7.getNum(), rp7.getNum(),
"", "", "", "", "", "", "", "");
private var column_8:Array = new Array
(rp8.getNum(), rp8.getNum(), rp8.getNum(), rp8.getNum(), rp8.getNum(), rp8.getNum(), rp8.getNum(), rp8.getNum(), rp8.getNum(), rp8.getNum(),
"", "", "", "", "", "", "", "");
private var column_9:Array = new Array
(rp9.getNum(), rp9.getNum(), rp9.getNum(), rp9.getNum(), rp9.getNum(), rp9.getNum(), rp9.getNum(), rp9.getNum(), rp9.getNum(), rp9.getNum(), rp9.getNum(),
"", "", "", "", "", "", "");
private var c1:Array = column_1.sort(shuffle);
private var c2:Array = column_2.sort(shuffle);
private var c3:Array = column_3.sort(shuffle);
private var c4:Array = column_4.sort(shuffle);
private var c5:Array = column_5.sort(shuffle);
private var c6:Array = column_6.sort(shuffle);
private var c7:Array = column_7.sort(shuffle);
private var c8:Array = column_8.sort(shuffle);
private var c9:Array = column_9.sort(shuffle);
private function shuffle(a, b):Number {
var num:Number = Math.round(Math.random() * 2) - 2;
return num;
}
private function populateBoxes():void {
variant1_1_1.txt.text = c1[0];
variant1_2_1.txt.text = c1[1];
variant1_3_1.txt.text = c1[2];
variant2_1_1.txt.text = c1[3];
variant2_2_1.txt.text = c1[4];
variant2_3_1.txt.text = c1[5];
variant3_1_1.txt.text = c1[6];
variant3_2_1.txt.text = c1[7];
variant3_3_1.txt.text = c1[8];
variant4_1_1.txt.text = c1[9];
variant4_2_1.txt.text = c1[10];
variant4_3_1.txt.text = c1[11];
variant5_1_1.txt.text = c1[12];
variant5_2_1.txt.text = c1[13];
variant5_3_1.txt.text = c1[14];
variant6_1_1.txt.text = c1[15];
variant6_2_1.txt.text = c1[16];
variant6_3_1.txt.text = c1[17];
//-----------------------------
variant1_1_2.txt.text = c2[0];
variant1_2_2.txt.text = c2[1];
variant1_3_2.txt.text = c2[2];
variant2_1_2.txt.text = c2[3];
variant2_2_2.txt.text = c2[4];
variant2_3_2.txt.text = c2[5];
variant3_1_2.txt.text = c2[6];
variant3_2_2.txt.text = c2[7];
variant3_3_2.txt.text = c2[8];
variant4_1_2.txt.text = c2[9];
variant4_2_2.txt.text = c2[10];
variant4_3_2.txt.text = c2[11];
variant5_1_2.txt.text = c2[12];
variant5_2_2.txt.text = c2[13];
variant5_3_2.txt.text = c2[14];
variant6_1_2.txt.text = c2[15];
variant6_2_2.txt.text = c2[16];
variant6_3_2.txt.text = c2[17];
//-------------------------------
variant1_1_3.txt.text = c3[0];
variant1_2_3.txt.text = c3[1];
variant1_3_3.txt.text = c3[2];
variant2_1_3.txt.text = c3[3];
variant2_2_3.txt.text = c3[4];
variant2_3_3.txt.text = c3[5];
variant3_1_3.txt.text = c3[6];
variant3_2_3.txt.text = c3[7];
variant3_3_3.txt.text = c3[8];
variant4_1_3.txt.text = c3[9];
variant4_2_3.txt.text = c3[10];
variant4_3_3.txt.text = c3[11];
variant5_1_3.txt.text = c3[12];
variant5_2_3.txt.text = c3[13];
variant5_3_3.txt.text = c3[14];
variant6_1_3.txt.text = c3[15];
variant6_2_3.txt.text = c3[16];
variant6_3_3.txt.text = c3[17];
//------------------------------
variant1_1_4.txt.text = c4[0];
variant1_2_4.txt.text = c4[1];
variant1_3_4.txt.text = c4[2];
variant2_1_4.txt.text = c4[3];
variant2_2_4.txt.text = c4[4];
variant2_3_4.txt.text = c4[5];
variant3_1_4.txt.text = c4[6];
variant3_2_4.txt.text = c4[7];
variant3_3_4.txt.text = c4[8];
variant4_1_4.txt.text = c4[9];
variant4_2_4.txt.text = c4[10];
variant4_3_4.txt.text = c4[11];
variant5_1_4.txt.text = c4[12];
variant5_2_4.txt.text = c4[13];
variant5_3_4.txt.text = c4[14];
variant6_1_4.txt.text = c4[15];
variant6_2_4.txt.text = c4[16];
variant6_3_4.txt.text = c4[17];
//------------------------------
variant1_1_5.txt.text = c5[0];
variant1_2_5.txt.text = c5[1];
variant1_3_5.txt.text = c5[2];
variant2_1_5.txt.text = c5[3];
variant2_2_5.txt.text = c5[4];
variant2_3_5.txt.text = c5[5];
variant3_1_5.txt.text = c5[6];
variant3_2_5.txt.text = c5[7];
variant3_3_5.txt.text = c5[8];
variant4_1_5.txt.text = c5[9];
variant4_2_5.txt.text = c5[10];
variant4_3_5.txt.text = c5[11];
variant5_1_5.txt.text = c5[12];
variant5_2_5.txt.text = c5[13];
variant5_3_5.txt.text = c5[14];
variant6_1_5.txt.text = c5[15];
variant6_2_5.txt.text = c5[16];
variant6_3_5.txt.text = c5[17];
//------------------------------
variant1_1_6.txt.text = c6[0];
variant1_2_6.txt.text = c6[1];
variant1_3_6.txt.text = c6[2];
variant2_1_6.txt.text = c6[3];
variant2_2_6.txt.text = c6[4];
variant2_3_6.txt.text = c6[5];
variant3_1_6.txt.text = c6[6];
variant3_2_6.txt.text = c6[7];
variant3_3_6.txt.text = c6[8];
variant4_1_6.txt.text = c6[9];
variant4_2_6.txt.text = c6[10];
variant4_3_6.txt.text = c6[11];
variant5_1_6.txt.text = c6[12];
variant5_2_6.txt.text = c6[13];
variant5_3_6.txt.text = c6[14];
variant6_1_6.txt.text = c6[15];
variant6_2_6.txt.text = c6[16];
variant6_3_6.txt.text = c6[17];
//------------------------------
variant1_1_7.txt.text = c7[0];
variant1_2_7.txt.text = c7[1];
variant1_3_7.txt.text = c7[2];
variant2_1_7.txt.text = c7[3];
variant2_2_7.txt.text = c7[4];
variant2_3_7.txt.text = c7[5];
variant3_1_7.txt.text = c7[6];
variant3_2_7.txt.text = c7[7];
variant3_3_7.txt.text = c7[8];
variant4_1_7.txt.text = c7[9];
variant4_2_7.txt.text = c7[10];
variant4_3_7.txt.text = c7[11];
variant5_1_7.txt.text = c7[12];
variant5_2_7.txt.text = c7[13];
variant5_3_7.txt.text = c7[14];
variant6_1_7.txt.text = c7[15];
variant6_2_7.txt.text = c7[16];
variant6_3_7.txt.text = c7[17];
//------------------------------
variant1_1_8.txt.text = c8[0];
variant1_2_8.txt.text = c8[1];
variant1_3_8.txt.text = c8[2];
variant2_1_8.txt.text = c8[3];
variant2_2_8.txt.text = c8[4];
variant2_3_8.txt.text = c8[5];
variant3_1_8.txt.text = c8[6];
variant3_2_8.txt.text = c8[7];
variant3_3_8.txt.text = c8[8];
variant4_1_8.txt.text = c8[9];
variant4_2_8.txt.text = c8[10];
variant4_3_8.txt.text = c8[11];
variant5_1_8.txt.text = c8[12];
variant5_2_8.txt.text = c8[13];
variant5_3_8.txt.text = c8[14];
variant6_1_8.txt.text = c8[15];
variant6_2_8.txt.text = c8[16];
variant6_3_8.txt.text = c8[17];
//------------------------------
variant1_1_9.txt.text = c9[0];
variant1_2_9.txt.text = c9[1];
variant1_3_9.txt.text = c9[2];
variant2_1_9.txt.text = c9[3];
variant2_2_9.txt.text = c9[4];
variant2_3_9.txt.text = c9[5];
variant3_1_9.txt.text = c9[6];
variant3_2_9.txt.text = c9[7];
variant3_3_9.txt.text = c9[8];
variant4_1_9.txt.text = c9[9];
variant4_2_9.txt.text = c9[10];
variant4_3_9.txt.text = c9[11];
variant5_1_9.txt.text = c9[12];
variant5_2_9.txt.text = c9[13];
variant5_3_9.txt.text = c9[14];
variant6_1_9.txt.text = c9[15];
variant6_2_9.txt.text = c9[16];
variant6_3_9.txt.text = c9[17];
}
public function Ticket():void {
populateBoxes();
externalizeNumbers();
}
public function externalizeNumbers(): void {
var variant_1:Array = new Array(variant1_1_1.txt.text, variant1_1_2.txt.text, variant1_1_3.txt.text, variant1_1_4.txt.text, variant1_1_5.txt.text, variant1_1_6.txt.text, variant1_1_7.txt.text, variant1_1_8.txt.text, variant1_1_9.txt.text,
variant1_2_1.txt.text, variant1_2_2.txt.text, variant1_2_3.txt.text, variant1_2_4.txt.text, variant1_2_5.txt.text, variant1_2_6.txt.text, variant1_2_7.txt.text, variant1_2_8.txt.text, variant1_2_9.txt.text,
variant1_3_1.txt.text, variant1_3_2.txt.text, variant1_3_3.txt.text, variant1_3_4.txt.text, variant1_3_5.txt.text, variant1_3_6.txt.text, variant1_3_7.txt.text, variant1_3_8.txt.text, variant1_3_9.txt.text);
var variant_2:Array = new Array(variant2_1_1.txt.text, variant2_1_2.txt.text, variant2_1_3.txt.text, variant2_1_4.txt.text, variant2_1_5.txt.text, variant2_1_6.txt.text, variant2_1_7.txt.text, variant2_1_8.txt.text, variant2_1_9.txt.text,
variant2_2_1.txt.text, variant2_2_2.txt.text, variant2_2_3.txt.text, variant2_2_4.txt.text, variant2_2_5.txt.text, variant2_2_6.txt.text, variant2_2_7.txt.text, variant2_2_8.txt.text, variant2_2_9.txt.text,
variant2_3_1.txt.text, variant2_3_2.txt.text, variant2_3_3.txt.text, variant2_3_4.txt.text, variant2_3_5.txt.text, variant2_3_6.txt.text, variant2_3_7.txt.text, variant2_3_8.txt.text, variant2_3_9.txt.text);
var variant_3:Array = new Array(variant3_1_1.txt.text, variant3_1_2.txt.text, variant3_1_3.txt.text, variant3_1_4.txt.text, variant3_1_5.txt.text, variant3_1_6.txt.text, variant3_1_7.txt.text, variant3_1_8.txt.text, variant3_1_9.txt.text,
variant3_2_1.txt.text, variant3_2_2.txt.text, variant3_2_3.txt.text, variant3_2_4.txt.text, variant3_2_5.txt.text, variant3_2_6.txt.text, variant3_2_7.txt.text, variant3_2_8.txt.text, variant3_2_9.txt.text,
variant3_3_1.txt.text, variant3_3_2.txt.text, variant3_3_3.txt.text, variant3_3_4.txt.text, variant3_3_5.txt.text, variant3_3_6.txt.text, variant3_3_7.txt.text, variant3_3_8.txt.text, variant3_3_9.txt.text);
var variant_4:Array = new Array(variant4_1_1.txt.text, variant4_1_2.txt.text, variant4_1_3.txt.text, variant4_1_4.txt.text, variant4_1_5.txt.text, variant4_1_6.txt.text, variant4_1_7.txt.text, variant4_1_8.txt.text, variant4_1_9.txt.text,
variant4_2_1.txt.text, variant4_2_2.txt.text, variant4_2_3.txt.text, variant4_2_4.txt.text, variant4_2_5.txt.text, variant4_2_6.txt.text, variant4_2_7.txt.text, variant4_2_8.txt.text, variant4_2_9.txt.text,
variant4_3_1.txt.text, variant4_3_2.txt.text, variant4_3_3.txt.text, variant4_3_4.txt.text, variant4_3_5.txt.text, variant4_3_6.txt.text, variant4_3_7.txt.text, variant4_3_8.txt.text, variant4_3_9.txt.text);
var variant_5:Array = new Array(variant5_1_1.txt.text, variant5_1_2.txt.text, variant5_1_3.txt.text, variant5_1_4.txt.text, variant5_1_5.txt.text, variant5_1_6.txt.text, variant5_1_7.txt.text, variant5_1_8.txt.text, variant5_1_9.txt.text,
variant5_2_1.txt.text, variant5_2_2.txt.text, variant5_2_3.txt.text, variant5_2_4.txt.text, variant5_2_5.txt.text, variant5_2_6.txt.text, variant5_2_7.txt.text, variant5_2_8.txt.text, variant5_2_9.txt.text,
variant5_3_1.txt.text, variant5_3_2.txt.text, variant5_3_3.txt.text, variant5_3_4.txt.text, variant5_3_5.txt.text, variant5_3_6.txt.text, variant5_3_7.txt.text, variant5_3_8.txt.text, variant5_3_9.txt.text);
var variant_6:Array = new Array(variant6_1_1.txt.text, variant6_1_2.txt.text, variant6_1_3.txt.text, variant6_1_4.txt.text, variant6_1_5.txt.text, variant6_1_6.txt.text, variant6_1_7.txt.text, variant6_1_8.txt.text, variant6_1_9.txt.text,
variant6_2_1.txt.text, variant6_2_2.txt.text, variant6_2_3.txt.text, variant6_2_4.txt.text, variant6_2_5.txt.text, variant6_2_6.txt.text, variant6_2_7.txt.text, variant6_2_8.txt.text, variant6_2_9.txt.text,
variant6_3_1.txt.text, variant6_3_2.txt.text, variant6_3_3.txt.text, variant6_3_4.txt.text, variant6_3_5.txt.text, variant6_3_6.txt.text, variant6_3_7.txt.text, variant6_3_8.txt.text, variant6_3_9.txt.text);
trace(variant_1);
trace(variant_2);
trace(variant_3);
trace(variant_4);
trace(variant_5);
trace(variant_6);
}
}
}