Changeset 63 for trunk/UGame.pas


Ignore:
Timestamp:
Nov 9, 2019, 1:38:36 PM (5 years ago)
Author:
chronos
Message:
  • Added: Roman numerals as tile skin.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGame.pas

    r56 r63  
    9595  end;
    9696
    97   TTileSkin = (tsLinear, tsPowerOfTwo, tsAlpha);
     97  TTileSkin = (tsLinear, tsPowerOfTwo, tsAlpha, tsRoman);
    9898
    9999  { TGame }
     
    181181  SSkinPowerOfTwo = 'Power of two';
    182182  SSkinAlpha = 'Alpha';
     183  SSkinRoman = 'Roman numerals';
    183184  STileShouldBeEmpty = 'Tile should be empty';
    184185
     
    197198  SkinText[tsPowerOfTwo] := SSkinPowerOfTwo;
    198199  SkinText[tsAlpha] := SSkinAlpha;
     200  SkinText[tsRoman] := SSkinRoman;
    199201end;
    200202
     
    10211023end;
    10221024
     1025function IntToStrRoman(Num: Integer): string;
     1026const
     1027  Nvals = 13;
     1028  Vals: array [1..Nvals] of Word =
     1029    (1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000);
     1030  Roms: array [1..Nvals] of string[2] =
     1031    ('I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M');
     1032var
     1033  B: 1..Nvals;
     1034begin
     1035  Result := '';
     1036  B := Nvals;
     1037  while Num > 0 do
     1038  begin
     1039    while Vals[b] > Num do
     1040      Dec(B);
     1041    Dec(Num, Vals[B]);
     1042    Result := Result + Roms[B];
     1043  end;
     1044end;
     1045
    10231046function TGame.GetTileSkinValue(Value: Integer): string;
    10241047begin
     
    10271050    tsPowerOfTwo: Result := IntToStr(1 shl Value);
    10281051    tsAlpha: Result := Chr(Ord('A') + Value - 1);
     1052    tsRoman: Result := IntToStrRoman(Value);
    10291053    else Result := IntToStr(Value);
    10301054  end;
Note: See TracChangeset for help on using the changeset viewer.