前回はQuiz6.pdeの大体の構成を解析しましたが、今回は改造します。

技術者時代はカット&トライと言ったような気がしますが、取りあえず取らないといけない所をぶった切って、動作がおかしくなったところを修正していくという方法で、Quiz6.pdeを改造しました。

プレーヤーを6人から3人に減らして、画面上で空いたスペースは問題文のために使います。画面上部のプレーヤーを削除するので、問題文の回転は必要なくなります。

では、変更箇所を列挙します。

1.問題文を増やしたいので、class QuizData の定義文で、String Question を配列にします。
・String Question; → String[] Question;
・Quizdata(String Question, String[] Answers){変更なし} → Quizdata(String[] Question, String[] Answers){変更なし}

2.問題文が長くなるので表示時間を延長
・int textSpeed = 10; → int textSpeed = 2;

3.makePlayers() でプレーヤーを削減
・for(int i=1; i<=6; i++){ → for(int i=1; i<=3; i++){

4.loadQuiz() で問題文の配列を追加(※csvファイルはこれに対応した形にする必要があります)
・if(cell.length!=6){ → if(cell.length!=9){
・String question = cell[1]; → String question = { cell[1], cell[2], cell[3], cell[4]};
・String answers = { cell[2], cell[3], cell[4], cell[5]}; → String answers = { cell[5], cell[6], cell[7], cell[8]};

5.drawTitle()でタイトル画面の変更
・textSize(140); → textSize(100);
・text("Quiz6", baseWidth/2, 300); → text("Quiz03", baseWidth/2, 300);

6.drawQuiz()で逆さまの問題文を削除
・if(phase == PHASE_QUIZ_ANSWER || phase == PHASE_QUIZ_RESULT){} を{}内も含めて丸ごと削除。
・pushMatrix();からbreak; までの9行を削除。

7.drawQuizPlayerInfo() で最初の3プレーヤーを削除
・if(i < 3){} を{}内も含めて丸ごと削除。
・PlayerData player = playerList.get(i); →PlayerData player = playerList.get(i-3);
・text(i+1, 5, 35); → text(i-2, 5, 35);

8.drawQuestion()で問題文の追加
・rect(0, 30, 410, 200, 8); →rect(0, 0, 410, 250, 8);
・rect(0, 30, map(quiztime, 0, quizTimeMax, 0, 410), 4, 8); →rect(0, 0, map(quiztime, 0, quizTimeMax, 0, 410), 4, 8);
・text("問題 " + quizNo, 20, 70); → text("問題 " + quizNo, 20, 40);
・text(quiz.question.string(0, min(quizTime/textSpeed, quiz.question.length())),…を
text(quiz.question[0].string(0, min(quizTime/textSpeed, quiz.question[0].length())),…
text(quiz.question[1].string(0, min(quizTime/textSpeed, quiz.question[1].length())),…
text(quiz.question[2].string(0, min(quizTime/textSpeed, quiz.question[2].length())),…
text(quiz.question[3].string(0, min(quizTime/textSpeed, quiz.question[3].length())),…

9.mousePressed()でマウスのタッチ位置の変更
・for(int i=0; i ・PlayerData player = playerList.get(i); → PlayerData player = playerList.get(i-3);
・int pi = i; → int pi = i+3;
・if(i<=2) pi = 2 - i; は削除
・activePlayerIndex = i; → activePlayerIndex = i-3;
・if(activePlayerIndex < 3){} は{}も含めて丸ごと削除。

以上の変更で、Quiz03.pdeが完成します。


《インデックス》

◆◆◆参考文献「遊んで作るスマホゲームプログラミング for Android
◆◆◆公文生ならゲームで遊ぶな!ゲームを作れ!
◆◆◆公文式小林教室◆山形県東根市◆◆◆