/** * Bingo Machine. 忘年会で活躍する、ビンゴマシン。 * 1から75までの数字をランダムにもれなくだぶりなく表示する。 * @author Hirata Atsushi */ //- - - - - - - - - - - - - // テストモード切り替え用フラグ //- - - - - - - - - - - - - //static final boolean TEST_MODE = true; //テストモード static final boolean TEST_MODE = false; //アプリモード //- - - - - - - - - - - - - // シンボリック定数 //- - - - - - - - - - - - - static final int DEFAULT_BACKGROUND_COLOR = 204; static final int BINGO_NUMBER_FONT_SIZE = 32; static final int FONT_COLOR = 0xFF006699; static final int BINGO_NUMBER_POS_X = 10; static final int BINGO_NUMBER_POS_Y = 60; static final int BINGO_MAX_NUMBER = 75; //- - - - - - - - - - - - - // グローバル変数 //- - - - - - - - - - - - - BingoProgression objectBingoProgression; Integer currentBingoNumber; Integer countBingoNumbers = 0; //- - - - - - - - - - - - - // メソッド //- - - - - - - - - - - - - void setup(){ if (TEST_MODE == true) { println("TEST_MODE : setup() called."); runTest(); } else { runBingoMachineApp(); } } void draw(){ if (TEST_MODE == true) { //Test code print("."); } else { println("[" + countBingoNumbers + "/" + BINGO_MAX_NUMBER + "]" + "currentBingoNumber is " + currentBingoNumber); background(DEFAULT_BACKGROUND_COLOR); textSize(BINGO_NUMBER_FONT_SIZE); fill(FONT_COLOR); text(currentBingoNumber, BINGO_NUMBER_POS_X, BINGO_NUMBER_POS_Y); } } void mousePressed() { if (TEST_MODE == true) { //Test code println("TEST_MODE : mousePressed() called."); } else { if (objectBingoProgression.hasNext() == true){ currentBingoNumber = objectBingoProgression.next(); countBingoNumbers++; } } } void runBingoMachineApp(){ println("Bingo Machine booting up..."); noLoop(); objectBingoProgression = new BingoProgression(); currentBingoNumber = objectBingoProgression.next(); countBingoNumbers = 1; loop(); } //- - - - - - - - - //Test codes below. //- - - - - - - - - void runTest(){ println("runTest called."); assert testBingoProgressionClass() == true : "ビンゴ数列発生クラスにエラーがあります"; println("runTest finished."); } boolean testBingoProgressionClass(){ println("testBingoProgressionClass called."); BingoProgression bp = new BingoProgression(); //ビンゴ数列のチェック ArrayList listForCheck = new ArrayList(); for( int i = 0; i < BINGO_MAX_NUMBER; i++ ){ listForCheck.add(false); } for( int i = 0; i < BINGO_MAX_NUMBER; i++ ){ Integer currentElement = bp.next(); println("No."+(i+1)+" is " + currentElement); if ( listForCheck.get( (int)currentElement -1 ) == true ){ return false; } else { listForCheck.set((int)currentElement-1,true); } } println("testBingoProgressionClass finished."); return true; }