package qube;

/**
 * User interface (or test subject interface)
 */
public class UI
{
    public static final int WRAP_AFTER = 74;

    public static void printGameLogo()
    {
        System.out.println(
            "                 _    _____  \n" +
            "      __ _ _   _| |__|___ /  \n" +
            "     / _` | | | | '_ \\ |_ \\  \n" +
            "    | (_| | |_| | |_) |__) | \n" +
            "     \\__, |\\__,_|_.__/____/  \n" +
            "        |_|                  \n");
    }

    private static void sleep(int milis)
    {
        if (System.getenv().containsKey("NOSLEEP")) {
            return;
        }

        try {
            Thread.sleep(milis);
        } catch (InterruptedException e) {
        }
    }

    private static void printSleep(char c) {
        int milis;

        switch (c) {
            case '\n':
            case '.':
            case ':':
            case '?':
            case '!':
                milis = 200; break;
            case ',':
            case ';':
            case '-':
                milis = 120; break;
            default:
                milis = 35;
        }

        milis += (int)(milis * (0.5 - Math.random()));

        sleep(milis);
        System.out.print(c);
    }

    public static void print(String text, String indent)
    {
        int runLength = 0;
        for (char c : text.toCharArray()) {
            c = (runLength >= WRAP_AFTER && c == ' ') ? '\n' : c;
            runLength = (c != '\n') ? (runLength + 1) : 0;
            printSleep(c);
            if (c == '\n') {
                System.out.print(indent);
            }
        }
    }

    public static void lineFeed()
    {
        printSleep('\n');
    }

    public static void print(String text)
    {
        print(text, "");
    }

    public static void println(String text, String indent)
    {
        print(text, indent);
        lineFeed();
    }

    public static void println(String text)
    {
        println(text, "");
    }

    public static void printPrompt(String prompt)
    {
        println("-> " + prompt, "   ");
        lineFeed();
    }

    public static void printContinue(String prompt)
    {
        println("   " + prompt, "   ");
        lineFeed();
    }

    private static String numeral(int n)
    {
        switch (n) {
            case  1: return "first";
            case  2: return "second";
            case  3: return "third";
            case  4: return "fourth";
            case  5: return "fifth";
            case  6: return "sixth";
            case  7: return "seventh";
            case  8: return "eighth";
            case  9: return "ninth";
            case 10: return "tenth";
            case 11: return "eleventh";
            case 12: return "twelfth";
            default:
                String numeral = String.valueOf(n);
                switch (n & 3) {
                    case 1: return numeral + "st";
                    case 2: return numeral + "nd";
                    case 3: return numeral + "rd";
                    default: return numeral + "th";
                }
        }
    }

    public static void printRespawn(int nRespawns)
    {
        printPrompt("You die.");
        sleep(5000);
        printContinue("God has other plans for you, however.");
        if (nRespawns > 1) {
            printContinue(". . . For the " + numeral(nRespawns) + " time.");
        }
    }
}
@@ -2266,21 +2266,21 @@
  String 
-numer
+ordin
 al(int n
@@ -2279,32 +2279,178 @@
 al(int n)%0A    %7B%0A
+        String%5B%5D sufixes = new String%5B%5D %7B %22th%22, %22st%22, %22nd%22, %22rd%22, %22th%22,%0A                                          %22th%22, %22th%22, %22th%22, %22th%22, %22th%22 %7D;%0A
         switch (
@@ -2920,83 +2920,18 @@
     
-    default:%0A                String numeral = String.valueOf(n);%0A  
+%7D%0A
         
     
@@ -2926,22 +2926,16 @@
         
-      
 switch (
@@ -2940,11 +2940,13 @@
  (n 
-& 3
+%25 100
 ) %7B%0A
@@ -2961,55 +2961,17 @@
     
- 
-       case 1: return numeral + %22st%22;%0A        
+case 11:%0A
     
@@ -2987,37 +2987,12 @@
 ase 
+1
 2:
- return numeral + %22nd%22;%0A   
+%0A
     
@@ -2999,26 +2999,22 @@
         
-     
 case 
+1
 3: retur
@@ -3020,31 +3020,17 @@
 rn n
-umeral
  + %22
-rd
+th
 %22;%0A
-        
     
@@ -3058,40 +3058,27 @@
 rn n
-umeral + %22th%22;%0A                %7D
+ + sufixes%5Bn %25 10%5D;
 %0A   
@@ -3344,13 +3344,13 @@
 %22 + 
-numer
+ordin
 al(n
@@ -3389,8 +3389,9 @@
 %0A    %7D%0A%7D
+%0A

Fix number → ordinal translation