第18講 テトリス開発(完成まで)
第9話 次のブロックの予告するの洗練化その2
078予告を実現するコード例(変更部分だけ記載)
void yokoku(){
  int i;
  int irosentaku[7]={kiiro,mizuiro,aka,ao,siro,midori,murasaki};
  for (i = 0; i < 4; i++) {
    DrawBox(300 + 20 * p[s[1]][k[1]][i], 60 + 20 * q[s[1]][k[1]][i], 299 + 20 * (p[s[1]][k[1]][i] + 1), 59 + 20 * (q[s[1]][k[1]][i] + 1), irosentaku[iro[1]], true);
  }
}
コピペ用添付ファイル

今回
int irosentaku[7]={kiiro,mizuiro,aka,ao,siro,midori,murasaki};
をローカル配列としましたが、
これをグローバル配列に変更して、
for文の次元数を1つ増やせば、
block()の
  for(i=0;i<7;i++){
    for (j = 0; j < 12; j++) {
      for (l = 0; l < 27; l++) {
        if (chizu[j][l] == 2 + i) {
          if(i==0)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, kiiro, true);
          if(i==1)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, mizuiro, true);
          if(i==2)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, aka, true);
          if(i==3)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, ao, true);
          if(i==4)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, siro, true);
          if(i==5)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, midori, true);
          if(i==6)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, murasaki, true);
        }
      }
    }
  }
  for(i=0;i<7;i++){
    for (j = 0; j < 12; j++) {
      for (l = 0; l < 27; l++) {
        if (chizu[j][l] == 9 + i) {
          if(i==0)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, kiiro, true);
          if(i==1)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, mizuiro, true);
          if(i==2)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, aka, true);
          if(i==3)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, ao, true);
          if(i==4)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, siro, true);
          if(i==5)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, midori, true);
          if(i==6)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, murasaki, true);
        }
      }
    }
  }
  for(i=0;i<7;i++){
    for (j = 0; j < 12; j++) {
      for (l = 0; l < 27; l++) {
        if (chizu[j][l] == 16 + i) {
          if(i==0)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, kiiro, true);
          if(i==1)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, mizuiro, true);
          if(i==2)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, aka, true);
          if(i==3)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, ao, true);
          if(i==4)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, siro, true);
          if(i==5)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, midori, true);
          if(i==6)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, murasaki, true);
        }
      }
    }
  }
  for(i=0;i<7;i++){
    for (j = 0; j < 12; j++) {
      for (l = 0; l < 27; l++) {
        if (chizu[j][l] == 23 + i) {
          if(i==0)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, kiiro, true);
          if(i==1)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, mizuiro, true);
          if(i==2)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, aka, true);
          if(i==3)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, ao, true);
          if(i==4)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, siro, true);
          if(i==5)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, midori, true);
          if(i==6)DrawBox(20 * j, 20 * l, 20 * (j + 1) - 1, 20 * (l + 1) - 1, murasaki, true);
        }
      }
    }
  }
の60行が、たったの12行に圧縮できます。
それに挑戦しましょう。




第8話へ  第10話へ
a

初心者のための excel 2016 マクロ VBA 入門講義 基礎から応用まで
vc++ c言語 c++ 入門 初心者 基礎から応用まで
eclipse c++ 入門
魔方陣 数独で学ぶ VBA 入門

数独のシンプルな解き方・簡単な解法の研究
VB講義へ
VB講義基礎へ
初心者のための世界で一番わかりやすいVisual C++入門基礎講座
初心者のための世界で一番わかりやすいVisual Basic入門基礎講座

初心者のための世界で一番わかりやすいVBA入門講義(基礎から応用まで)
初心者のための VC++による C言語 C++ 入門 基礎から応用まで第1部
eclipse java 入門
java 入門 サイト 基礎から応用まで
本サイトトップへ