1

I have a simple game which you can play over telnet, but it refreshes the screen by printing a few line breaks and then sending the entire screen again. Sometimes this can cause flicker, and if the user scrolls up their terminal they see all the old frames.

What improvements could I make?

Is there a way to just modify certain characters rather than re-sending everything? This would probably prevent the flicker, and stop the users terminal from filling up with loads of old frames.

I tried sending the backspace character (8), but this doesn't go any further than the start of the current line. Something like this which goes to other lines would be perfect!

Also, I noticed that telnet towel.blinkenlights.nl doesn't use my horrible frame-sending method.. so I know there is a better solution.

Matt
  • 11,157
  • 26
  • 81
  • 110
  • 2
    What you need is a curses library for Java. Check out here: http://stackoverflow.com/questions/439799/whats-a-good-java-curses-like-library-for-terminal-applications – Jeremy Friesner Dec 29 '10 at 20:41
  • But I've got so far without it! (I'm also too stupid to successfully install any sort of library on Eclipse). Surely all a library can do is send some combination of low level characters to manipulate the screen? I don't need much OS independence, because I will only be showing my game on Unix systems. – Matt Dec 29 '10 at 20:47
  • Well, apparently you didn't get far enough if you are asking this question? – MK. Dec 29 '10 at 20:56
  • @MK I mean with all the other stuff everyone insisted I need curses for.. I just don't see why I NEED it if all it's doing is sending special character sequences? – Matt Dec 29 '10 at 21:02
  • 1
    I suggest learning to get libraries working in Eclipse as soon as possible. You may be able to write the entire library yourself, but there's no reason to. – Brendan Long Dec 29 '10 at 21:11

2 Answers2

3

Curses will do that. If you want to write it yourself, the algorithm is pretty simple. It remembers the state of the screen in one buffer, the program draws the new screen to another buffer, it calls a refresh, and the library compares the two buffers and only sends the required changes. It then copies the new buffer to the current buffer and then goes to the next frame. The tricky part is dealing with all the different terminal types and their control sequences to move the cursor around. The Curses stuff has a terminal library included.

JOTN
  • 6,120
  • 2
  • 26
  • 31
  • That would probably be quite good, because I've already implemented the buffer stuff, and the screens are stored in a 2D array. So are there just too many terminal types to do it manually? – Matt Dec 29 '10 at 21:03
  • Just checking the terminal database on this system, and there's 1,675 terminal types. I'm not sure how many are actually being used these days. – JOTN Dec 29 '10 at 21:32
1

Apparently I can use ANSI escape sequences.. seems to work okay on my terminal.

It's probably a horrible unsupported thing to do, but it answers the question so I'll leave the link here for anyone who may need it in the future.

http://www.termsys.demon.co.uk/vtansi.htm

Matt
  • 11,157
  • 26
  • 81
  • 110