--- Matt Foltz <[EMAIL PROTECTED]> wrote:
> I was bored, and came up with an interesting idea. I
> used the {n "colour code" to randomly put out a color.
> (This is written for Lope's color). Here's what I
> did:
>
> In the int colour function add:
>
> int random = 0;
>
> to the declarations.
>
> Then I added:
>
> case 'n':
> random = number_range( 1, 13);
> if ( random == 1 )
> strcpy( code, C_BLUE );
> else if ( random == 2 )
> strcpy( code, C_B_BLUE );
> else if ( random == 3 )
> strcpy( code, C_CYAN );
> else if ( random == 4 )
> strcpy( code, C_B_CYAN );
> else if ( random == 5 )
> strcpy( code, C_GREEN );
> else if ( random == 6 )
> strcpy( code, C_B_GREEN );
> else if ( random == 7 )
> strcpy( code, C_D_GREY );
> else if ( random == 8 )
> strcpy( code, C_MAGENTA );
> else if ( random == 9 )
> strcpy( code, C_B_MAGENTA );
> else if ( random == 10 )
> strcpy( code, C_RED );
> else if ( random == 11 )
> strcpy( code, C_B_RED );
> else if ( random == 12 )
> strcpy( code, C_YELLOW );
> else
> strcpy( code, C_B_YELLOW );
> break;
Yucky if-elses.. If I might suggest a more elegent solution?
case 'n':
{
const char * color_list[13] =
{
C_BLUE, C_B_BLUE, C_CYAN, C_B_CYAN,
C_GREEN, C_B_GREEN, C_D_GREY, C_MAGENTA,
C_B_MAGENTA, C_RED, C_B_RED, C_YELLOW,
C_B_YELLOW
};
strcpy(code, color_list[number_range(0,12)]);
}
break;
I might also recommend using some kind of named constant instead of the "magic"
numbers 13 and 12 here, but if it's not likely to change much it may not be
worth it.
~Kender
=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++:+ a-- C+++$>++++ UBLS++++$
P+++(--)$ L++>+++ E--- W+>++$ N !o K? w(--) !O
M- !V PS+ PE(++) Y+ PGP->+ t- 5 X+() R(+) tv+@
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com