1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-25 22:18:30 +02:00

Abstract UtilityClass::number() to be more generic

Previously, it was a hardcoded list going up to fifty.

This time, it's less hardcoded. Most of the time, it will take a number,
find out its tens-place word, find out its ones-place word, and combine
the two together. There are special cases for the teens, and the numbers
zero through nine, and one hundred.

Also, now if it is given a negative value, it will just return "???"
instead.

If there are more than one hundred it will still say "Lots".
This commit is contained in:
Info Teddy 2020-01-23 06:45:50 -08:00 committed by Ethan Lee
parent cd7cc317b5
commit 37507c147f

View File

@ -151,24 +151,42 @@ std::string UtilityClass::timestring( int t )
std::string UtilityClass::number( int _t )
{
const int BIGGEST_SMALL_NUMBER = 50;
const char* smallnumbers[] = {"Zero", "One", "Two", "Three",
"Four", "Five", "Six", "Seven", "Eight", "Nine",
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen",
"Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty", "Twenty One",
"Twenty Two", "Twenty Three", "Twenty Four", "Twenty Five",
"Twenty Six", "Twenty Seven", "Twenty Eight", "Twenty Nine",
"Thirty", "Thirty One", "Thirty Two", "Thirty Three", "Thirty Four",
"Thirty Five", "Thirty Six", "Thirty Seven", "Thirty Eight",
"Thirty Nine", "Forty Zero", "Forty One", "Forty Two", "Forty Three",
"Forty Four", "Forty Five", "Forty Six", "Forty Seven", "Forty Eight",
"Forty Nine", "Fifty"};
const std::string ones_place[] = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
const std::string tens_place[] = {"Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
const std::string teens[] = {"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
if(_t <= BIGGEST_SMALL_NUMBER) {
return smallnumbers[_t];
if (_t < 0)
{
return "???";
}
else if (_t > 100)
{
return "Lots";
}
else if (_t == 0)
{
return "Zero";
}
else if (_t == 100)
{
return "One Hundred";
}
else if (_t >= 1 && _t <= 9)
{
return ones_place[_t-1];
}
else if (_t >= 11 && _t <= 19)
{
return teens[_t-11];
}
else if (_t % 10 == 0)
{
return tens_place[(_t/10)-1];
}
else
{
return tens_place[(_t/10)-1] + " " + ones_place[(_t%10)-1];
}
return "Lots";
}
bool UtilityClass::intersects( SDL_Rect A, SDL_Rect B )