こんにちは、川合です。現在ちょぴり休養中なので、アドバイスを。
まあアドバイスといっても、僕が好きでやっているだけなので、くー
みんさんが気に入らなければ無視して構わないのですが。以下の中で気
に入ったものだけを利用してください。
(1)USE_COLORあたりの簡略化
#ifdef USE_COLOR
int getcolor(const int blocktype);
#endif
という部分がありますが、これを以下のようにすれば、プログラムがす
っきりします。
#ifdef USE_COLOR
int getcolor(const int blocktype);
#else
#define getcolor(x) 8
#endif
こうすることで、getcolor(〜)は8に自動的に読み替えられるので、
#ifdef USE_COLOR
putmarkwin(6,1,0, getcolor(next1), getscr(next1));
putmarkwin(6,0,0, getcolor(next2), getscr(next2));
#else
putmarkwin(6,1,0, 8, getscr(next1));
putmarkwin(6,0,0, 8, getscr(next2));
#endif
という部分を、
putmarkwin(6,1,0, getcolor(next1), getscr(next1));
putmarkwin(6,0,0, getcolor(next2), getscr(next2));
だけにできるわけです。関数to_down()などはそのままですが。
(2)10進数変換はもっとスマートに!
putmark()という関数がありますが、僕は以下の内容をおすすめいた
します。
void putmark(int mark)
{
char markstr[9], *s = "strong!";
int i;
if (mark < 10000000) {
s = markstr;
markstr[8] = 0;
for (i = 7; i >= 0; i--) {
markstr[i] = '0' + mark % 10;
mark /= 10;
}
}
putmarkwin(9,1,8, 0, s);
return;
}
これでちょっとは小さくできるでしょう。またmy_itoa()という関数
は不要になりますのでコンパクト化が期待できます。
(3)関数getscr()の改良
以下のような記述にできます。というか、配列が使える場面では配列
を積極的に使うのが一番いいです。ifやswitchにするのはもっともサイ
ズと速度を食います。
char *getscr(const int type)
{
static char *table[4] = { "##", "$$", "<>", "[]" };
if (-5 <= type && type <= -2) {
return table[5 + type];
}
return " ";
}
もし、このtypeの値が、-5〜0の値しかとらないと分かっているのな
ら、getscrはもっと簡単にできます(もちろん速い)。
static char *getscr_table[6] = { "##", "$$", "<>", "[]", " ", " " };
#define getscr(type) (getscr_table[5 + (type)])
この#defineタイプを使う場合は、getscr()のプロトタイプ宣言部分と
差し替える必要があります。
(4)関数getcolor()の改良
getscr()のときと同様に簡単に簡略化できます。
char *getscr(const int type)
{
static int table[4] = { 12, 11, 10, 9 };
if (-5 <= type && type <= -2) {
return table[5 + type];
}
return 0;
}
typeが-5〜0の値しかとらないと分かっているのなら、
static int getcol_table[6] = { 12, 11, 10, 9, 0, 0 };
#define getscr(type) (getcol_table[5 + (type)])
でいいわけです。
続きはまた気が向いたときに。
それでは。
--
川合 秀実(KAWAI Hidemi)
OSASK計画代表 / システム設計開発担当
E-mail:kawai !Atmark! imasy.org
Homepage http://www.imasy.org/~kawai/