我正在尝试编写if语句,以在“ across”或“ down”小于或等于零时不绘制任何内容。不太了解如何编写它以停止draw_rect。尽管我放下= 0,但仍会遇到问题
int horiz;
int vert;
int across;
int down;
char display_char;
void draw_rect ( void ) {
// If either of the width or height is less than or equal to zero,
// the function must not draw anything.
draw_line( horiz, vert, across, vert, display_char );
draw_line( horiz, down, across, down, display_char );
draw_line( horiz, vert, horiz, down, display_char );
draw_line( across, vert, across, down, display_char );
if ( down > 0 ){
?????
}
int main( void ) {
setup_screen();
// draw a box.
horiz = rand() % screen_width() / 2;
vert = rand() % screen_height() / 2;
across = 1 + rand() % (screen_width() - horiz - 1);
down = 1 + rand() % (screen_height() - vert - 1);
display_char = '@';
draw_rect();
show_screen();
// draw a box with zero height.
horiz = rand() % screen_width() / 2;
vert = rand() % screen_height() / 2;
across = 1 + rand() % (screen_width() - horiz - 1);
down = 0;
display_char = 'a';
draw_rect();
show_screen();
timer_pause(5000);
cleanup_screen();
return 0;
}
很简单:
void draw_rect ( void )
{
//If either of the width or height is less than or equal to zero,
//the function must not draw anything.
if(across > 0 && down > 0)
{
draw_line( horiz, vert, across, vert, display_char );
draw_line( horiz, down, across, down, display_char );
draw_line( horiz, vert, horiz, down, display_char );
draw_line( across, vert, across, down, display_char );
}
}
换个角度来看。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句