Sign in to follow this  
orcfan32

Refreshing a...console?

Recommended Posts

Well, time to reveal what I've been planning: CONSOLE TETRIS!! Problem is, I don't want to keep printing more text! I wan't to remove old text and replace with new text. Possible? Not possible?

Share this post


Link to post
Share on other sites
Assuming Windows, you can write directly to coordinates in the console using the WriteConsoleOutput() family of functions. In *nix, you can use a curses library like ncurses.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
In *nix, you can use a curses library like ncurses.

And there's also pdcurses which is cross platform.

Share this post


Link to post
Share on other sites
Quote:
Original post by orcfan32
Quote:
Original post by Gink
Use system("CLS");


Exactly what I needed, thanks.


But I don't think this way is very effective. It calls an external program where it executes a command to clear the screen. It might make your game slow at updating itself. You could try the second approach listed here, http://support.microsoft.com/default.aspx?scid=kb;en-us;99261, which should make you program more effective.

Edit: How to I create clickable URL's?

Share this post


Link to post
Share on other sites
Quote:
Original post by orcfan32
Well, nevermind clearing the entire screen. How would I clear a certain line??


In Tetris, when you need to do this (or something like it), you'll have to move stuff down into the space anyway. What you want to do is maintain a buffer inside your program that describes the current "appearance" of the game, and periodically redraw that to screen. As blocks fall/lines form/etc., update the buffer by copying/clearing/resetting data within it.

Share this post


Link to post
Share on other sites
I would handle it by keeping an array of ints that represents the screen. Inside the int would be the handle that represents the tile in that space. Then when you remove a line, do a loop starting at the row you are deleting and set its value equal to the id number of the tile above it, then 0 out the array elements representing the top row.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this