Hehe, thanks.
I don't mind the switch statement bit, but it can be fixed in other ways if it's problematic. For example:
char* flavorText;
switch(LCSrandom(4))
{
case 0:
flavorText = "You keep the gas floored!";
break;
case 1:
flavorText = "You swerve around the next corner!";
break;
case 2:
flavorText = "You screech through an empty lot to the next street!";
break;
case 3:
if(yourworst>15)
flavorText = "You boldly weave through oncoming traffic!";
else
flavorText = "You make obscene gestures at the pursuers!";
break;
}
addstr(flavorText, gamelog);
gamelog.newline();
True. Good idea. I'll keep it in mind for future switch statements.
I see a couple issues with merging the gamelog.newline() call into addstr:
1. Curses already has a bunch of boggling variants on addstr, like mvwaddnstr.
To me, addstrl looks to me like it should affect how the text is displayed, or at least give me additional options in the parameter list about how I want the text displayed. If it has no impact on the parameter list or on displaying text, that will likely be unintuitive to people who have past experience with Curses.
To me, it's obvious it does more than just display something due to the log parameter.
2. The difference between addstrl and addstr isn't self-documenting.
When I'm assessing how to best integrate logging into the current system for displaying text, I'm worried about code readability. If I'm a new developer to the project, pulling up the source code, how will I know when I should use addstr and when should I use addstrl? I won't be able to figure out what that function does from seeing its name or how it's used -- I won't even know that the difference has something to do with logging rather than displaying text. I will likely be confused, because they appear to do the same thing. There's a good chance that I'll code and use one when they should have used the other, thus creating minor bugs in the logger that other programmers will have to clean up later.
addstr(cr->name, log);
addstr(" turns the tables on ", log);
addstr(a->name, log);
addstrl("!", log); // It's not obvious what the difference is here
addstr(a->name, log);
addstr(" has been tainted with wisdom!", log);
gamelog.endmessage(); // This leads to point #3...
Good points. The log parameter does add the realm of possibility that addstrl would effect the log, which only would make the situation more confusing due to even more possibilities.
3. You will need a variant for double newlines as well.
Both of the above concerns get worse when you have a distinction between endmessage() and newline(), and are trying to represent both with single-character variations on addstr's function name.
I hadn't thought of that. That's true.
Personally, I never/rarely come across the first two issues pointed out because I *almost* always check the definition of the function before using it.
That's why I didn't think of those two issues until you pointed them out.
Oh well. Like I said, I can float the code either way.