現在配列内を調べる関数として以下があります。(メンバ関数の一部です)
現在地点から上下左右に調べる関数なのですが、似たような処理なのにまとめられなくてモヤモヤしています。
ただfor文の条件と、getTypeの引数が違うくらいでほぼ同じです。
何かいいまとめ方はないでしょうか?
よろしくお願い致します。
bool checkUp( int x, int y, int type )
{
for( int i = y - 1; i >= 0; --i ) {
if( getType(x,i) == type) ) {
return true;
}
}
return false;
}
bool checkDown( int x, int y, int type )
{
for( int i = y + 1; i < MAX_Y; ++i ) {
if( getType(x,i) == type) ) {
return true;
}
}
return false;
}
bool checkLeft( int x, int y, int type )
{
for( int i = x - 1; i >= 0; --i ) {
if( getType(i,y) == type) ) {
return true;
}
}
return false;
}
bool checkRight( int x, int y, int type )
{
for( int i = x + 1; i < MAX_X; ++i ) {
if( getType(i,y) == type) ) {
return true;
}
}
return false;
}