Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help with Text Based C++ games

Where can i go to learn how to make text based games in c++ ?.. I would like to look at some source code too for ideas and ect.. ect. plz help thx.


Comments

  • : Where can i go to learn how to make text based games in c++ ?.. I would like to look at some source code too for ideas and ect.. ect. plz help thx.


    Here's some code for making a guy (a smiley face) walk around.


    #include // these includes are stdio.h and conio.h. Only conio.h is really needed, stdio.h is put there just out of habit.

    #include


    #define UP 72 // Characters the arrow keys return from keyboard.

    #define DOWN 80

    #define LEFT 75

    #define RIGHT 77




    int main () {

    char c;

    int x,y, sizex=20, sizey=10;


    textcolor(15);

    textbackground(0);

    clrscr();

    // Change background color to 0 (black), and clear screen.


    textbackground(1);

    // Change background color to 1 (blue)


    // This for statement draws an "arena" sizex X sizey in the upper left corner of screen.

    for (y=0; y
    {

    for (x=0; x
    cprintf("
    ");

    }


    // main loop function


    x=sizex/2; // Set X and Y to be at center of arena

    y=sizey/2;

    while (c!=27)

    {

    gotoxy(x,y); // Moves cursor to specified coordinantes.

    cprintf("%c", 0x02); //Prints out a smiley face (ASCII char #2).

    gotoxy(x,y); // Moves cursor under the guy (looks nicer and used for erasing).


    c=getch(); // Reads characters from keyboard.

    if (c==0) c=getch(); // Detects arrow scancodes, they have a 0 character and then another character, we use only the second character.

    cprintf(" "); //Erases the guy (so he doesn't leave a trail).


    if ((c==UP) && (y>1)) y--; //If keyboard returns UP and if the Guy (the smiley) CAN go up (as in he must stay in the arena).

    if ((c==DOWN) && (y
    if ((c==LEFT) && (x>1)) x--;

    if ((c==RIGHT) && (x
    }

    return 0;

    }




  • The code isn't the way it was printed out. You will need to copy it out of the text box below the message and remove all the preceding ">"s.


    -Xotor-


Sign In or Register to comment.