Roman Numerals (SOLVED)

Started by Sam., Sat 29/01/2005 18:26:01

Previous topic - Next topic

Sam.

This might seem strange to you but it was a nice thought i had. Is it possible to format the score show it displays in roman numerals? I thought and thought and thought that someone here may be able to help me out. if its impossible its cool but i just wanted to try it.
Bye bye thankyou I love you.

Ishmael

I guess you could do it with bitwise operators, in case AGS supported them... I don't remember exactly, but I have a faint memory of something like this.

If you could, I'd do it by separating the number to 1's, 10's, 100's etc for how long you need, and then turning each number to romans (if (num1 == 2) StrCopy(num1s, "II");) and then StrCat'ing them together, but there's probably an easier way...
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Kweepa

If you're happy converting C code to AGS script, then you can just search for "decimal to roman numerals c code" on google. There are plenty of examples. It's not trivial but it's not difficult either.
Perhaps someone has done it already...?
Still waiting for Purity of the Surf II

RickJ

Quote
Is it possible to format the score show it displays in roman numerals?
Yes

Quote
I thought and thought and thought that someone here may be able to help me out.
Take SteveMcCrea's advice.  Here is on I've found for you but I haven't looked at it. 
http://www.programmersheaven.com/zone3/cat414/16170.htm

I've never written a Decimal2Roman converter before but I have done for other number systems.    Basically you start by dividing the the decimal number by the highest posible power of the number system you are converting to.  The result is then converted to the character(s) representing the highest order digint in the conversion.  The remainder is then divided by the next highest power of the number system, etc...   

My explanation is brief but it should help you get through an actual c code example.  let us know if you take this on.  Cheers



Goot

Yeah, it's possible to write a code for that but probably harder than it's worth. Especially getting it to do stuff like IV instead of IIII. If your maximum score isn't too high you could just do:
if(game.score==1){
SetLabelText(x,x,"I");
}
else if(game.score==2){
SetLabelText(x,x,"II");
}
etc...

Takara

Well, you intrigued me and I had nothing planned for the evening, so I've written a couple of little functions for you :)Ã,  Just call GetRomanScore ( result ) from somewhere and result will be filled with the current score in roman numerals :)Ã,  It will only work for scores below 1000... but how often do you need more than that? :)

Code: ags

function RomanDigits ( string result, int digit, string ten_letter, string five_letter, string one_letter) {

Ã,  if ( digit == 1 )
Ã,  Ã,  StrCopy(result, one_letter);
Ã,  if ( digit == 2 )
Ã,  Ã,  StrFormat(result, "%s%s", one_letter, one_letter);
Ã,  if ( digit == 3 )
Ã,  Ã,  StrFormat(result, "%s%s%s", one_letter, one_letter, one_letter);
Ã,  if ( digit == 4 )
Ã,  Ã,  StrFormat(result, "%s%s", one_letter, five_letter);
Ã,  if ( digit == 5 )
Ã,  Ã,  StrFormat(result, "%s", five_letter);
Ã,  if ( digit == 6 )
Ã,  Ã,  StrFormat(result, "%s%s", five_letter, one_letter);
Ã,  if ( digit == 7 )
Ã,  Ã,  StrFormat(result, "%s%s%s", five_letter, one_letter, one_letter);
Ã,  if ( digit == 8 )
Ã,  Ã,  StrFormat(result, "%s%s%s%s", five_letter, one_letter, one_letter, one_letter);
Ã,  if ( digit == 9 )
Ã,  Ã,  StrFormat(result, "%s%s", one_letter, ten_letter);
Ã,  
}


function GetRomanScore ( string strROMAN ) {
Ã,  string newbit;
Ã,  int digit, length, curScore;
Ã,  
Ã,  StrCopy ( strROMAN, "");
Ã,  StrCopy ( newbit, "");
Ã,  curScore = game.score;
Ã,  digit = curScore/100;
Ã,  RomanDigits(newbit, digit, "M", "D", "C");
Ã,  StrCat(strROMAN, newbit);
Ã,  
Ã,  curScore = curScore - digit*100;
Ã,  digit = curScore/10;
Ã,  StrCopy ( newbit, "");
Ã,  RomanDigits(newbit, digit, "C", "L", "X");
Ã,  StrCat(strROMAN, newbit);
Ã,  
Ã,  curScore = curScore - digit*10;
Ã,  digit = curScore;
Ã,  StrCopy ( newbit, "");
Ã,  RomanDigits(newbit, digit, "X", "V", "I");
Ã,  StrCat(strROMAN, newbit);Ã,  
}


Of course, you may confuse people completely having scores in roman numerals... but it was fun coding :)

Hope that helps,

Takara.

SMF spam blocked by CleanTalk