in reply to Re: seek() command on STDOUT
in thread seek() command on STDOUT

Thanks,

The program I'm writing is a simple terminal game called snake that was a popular arcade game in the '70s. It has 50x50 grids where the snake-like creature moves around and the player steers it not to hit the blockage or itself. It is intended to run on xterm.

I finished the program, but currently, it refreshes the display every second(and getting faster over the time) with print `clear` and redraws the entire 50x50 grids with the new pattern. However, since all the grids are refreshed every time, the flickering is annoying especially when the snake's move gets faster. Then I realized that only 2 out of 50x50 grids are required to be updated every time(The head and tailend of the snake need to be updated to move forward) and I need to move the cursor to those 2 locations to update it every time. I thought seek() could do that on STDOUT where I got it wrong.

So, basically, like you said, I need to move the cursor to the random points of 50x50 grid on xterm, update them with keeping all the other grids unchanged.

Is ncurses able to do it ?

Thanks for your help..

Replies are listed 'Best First'.
Re^3: seek() command on STDOUT
by BrowserUk (Patriarch) on Apr 30, 2010 at 21:46 UTC

    On *nix, you can probably use ansi escape sequences to move the cursor around (untested):

    sub moveTo{ my( $x, $y ) = @_; return chr(27) . "[$y;$xH"; } print moveTo( 25, 25), 'some text'; print moveTo( 10, 10 ), ' ';

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      As being suggested, I played with ANSI escape sequence a little bit, and made my program work as intended.

      Thanks for your help.