Hmm, yes, there does seem to be a problem which I didn't initially play it for long enough to find, namely that the ball can sometimes get stuck on the LHS of the screen and bounce back and forth within the first five columns. Perhaps replace the test x%72<5 with (d>0?1:-1)*(x-40)>35 (unless that can be improved using a standard sign or abs function), so that the ball only ever bounces if it's heading out of the arena rather than on the way back into it?
And the bat isn't displayed until it first moves; you could get round that by, for example, initialising k to -1 and conditionalising the input statement on that (k=k==-1?k:System.in.available()>0?System.in.read()-44:1). Then k will be overwritten when the time is read, and so in all subsequent iterations the input check will occur (unless System.nanoTime() happens to return exactly -1, but it'll stop doing that a nanosecond later and I think that's an acceptable response lag).
Also, I had to try three or four Java compilers before I found one which didn't either fail to cope with the preamble (insisting on main() being declared explicitly) or fail to find System.nanoTime(); and once I'd compiled the program I then had to manually configure my terminal device before it was playable (stty raw isig -echo; java G; stty sane, and better still echo -ne "\033[?25l" to disable the cursor before running it, and echo -ne "\033[?25h" to re-enable it afterwards). But I assume the former was just because I had out-of-date software, and the latter an expected consequence of Java not containing a real curses library.
System.nanoTime is 1.5+. 1.5 has been out for around three years now. There shouldn't be a problem compiling without a main (most classes don't have a main). However, running is open to dispute. Java WebStart, for instance, does not initialise the main class as a separate step before finding and executing the main method (and it will complain if the method is defined in the wrong class loader). Terminal handling in Java is a bit limited (and available is not guaranteed to return anything other than zero), although there is Console.readPassword in 1.6.
IIRC, the getting caught in the left hand side was to do with starting position. But I forget now. I don't have many characters to spare.
x%72<5with(d>0?1:-1)*(x-40)>35(unless that can be improved using a standard sign or abs function), so that the ball only ever bounces if it's heading out of the arena rather than on the way back into it?And the bat isn't displayed until it first moves; you could get round that by, for example, initialising
kto-1and conditionalising the input statement on that (k=k==-1?k:System.in.available()>0?System.in.read()-44:1). Thenkwill be overwritten when the time is read, and so in all subsequent iterations the input check will occur (unlessSystem.nanoTime()happens to return exactly-1, but it'll stop doing that a nanosecond later and I think that's an acceptable response lag).Also, I had to try three or four Java compilers before I found one which didn't either fail to cope with the preamble (insisting on
main()being declared explicitly) or fail to findSystem.nanoTime(); and once I'd compiled the program I then had to manually configure my terminal device before it was playable (stty raw isig -echo; java G; stty sane, and better stillecho -ne "\033[?25l"to disable the cursor before running it, andecho -ne "\033[?25h"to re-enable it afterwards). But I assume the former was just because I had out-of-date software, and the latter an expected consequence of Java not containing a realcurseslibrary.IIRC, the getting caught in the left hand side was to do with starting position. But I forget now. I don't have many characters to spare.