create and deleting display in c++

could we create something like:

"hello, there..."

on the screen and it scroll from right to left? and is ittrue that we can create snake game in c++ console progs?
firstly, http://www.cplusplus.com/forum/articles/28558/
then if you are stubborn, google ncurses (portable) or see http://msdn.microsoft.com/en-us/library/ms682073(v=vs.85).aspx (microsoft)
closed account (3pj6b7Xj)
You mean maybe something like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#define LEFT 0
#define RIGHT 1

int xpos = 10;
int direction = RIGHT;

string mystr(" hello, there... ");

HDC hdc = GetDC(hWnd);

while(program is runnning)
{
     while (PeekMessage(&Msg, NULL,0,0,PM_REMOVE)
     {
           TranslateMessage(&Msg);
           DispatchMessage(&Msg);
     }

     if (direction == LEFT) { xpos--; if (xpos < 10) direction = RIGHT; }
     if (direction == RIGHT) { xpos++; if (xpos > 600) direction = LEFT; }

     TextOut(hdc,xpos,30,mystr.c_str(),mystr.size());
}
ReleaseDC(hWnd, hdc);


Note that i left an empty space on both sides of the message, so that it doesn't leave a trail of text.

Now as for the snake game under the console, that is almost impossible with out using conio.h because you need gotoxy and textcolor() and textbackground() to set colors and paint the snakes....the problem is conio.h is not really portable...I think your better off trying it with windows GDI which, I have already done :) game is almost finished.

But hey, anything is possible...
Last edited on
Don't use conio.h or Windows API, use ncurses. It's a cross-platform Curses implementation.

ncurses: http://gnuwin32.sourceforge.net/packages/ncurses.htm
Tutorial: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
closed account (3pj6b7Xj)
No way, you kidding me? I gotta try this out myself.
Curses has been around for a long time, at least as long as the X Window System.
@faosfx: i don't know this code yet, can you show me the full code? is it windows apps? i want it in console...
It's pseudo-code.
system("cls") clears the screen. then try to print your words as you want
system() is strongly deprecated, Timur, and for a good reason. See here: http://www.cplusplus.com/forum/articles/11153/
:/

There's a whole article about clearing the console, which you can find in the stickied thread at the top of the "Articles" section of this forum. The best standard way is to print a large number of newlines, however I would definitely recommend using a curses library, such as ncurses or PDCurses, as chrisname suggested. :)

Have fun!

-Albatross
Last edited on
Topic archived. No new replies allowed.