1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Language C - Position my Printf in X and Y on the screen.

  1. Mar 7, 2015 #1
    1. The problem statement, all variables and given/known data
    I work on Microsoft Visual studio 2010 on Win7.

    Ok so let me explain the problem here, The functions works very good to position my printf in X and Y on my screen ONLY when my 2D Array labyrinth Map is NOT printed on the screen.

    But once I printf my Map on the screen I cannot position the printf in X and Y.

    This is the current code I use to position my printf and only works when my Map is not printed on the screen.

    gotoxy(posx,5); clreoscr();
    textcolor(15);
    posx = printf("\nSpeed of Character: %d / %d",speed, m1);
    textcolor(15);
    posx = printf("\nSpeed of enemie: %d / %d", speed_e, m2);


    This is the functions I have to use to give my printf a position on my screen.
    ----------------------------------------------------------------------------------------------------------------------------
    void gotoxy(int x,int y) //positions text cursor at (x, y) screen position
    {
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo; //variable declarations
    HANDLE hConsoleOut;

    hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);

    csbiInfo.dwCursorPosition.X = x; //cursor position X coordinate
    csbiInfo.dwCursorPosition.Y = y; //cursor position Y coordinate
    SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition); //set cursor at the given screen coordinate
    }


    /*-------------------------wherex()------------------------------------*/

    int wherex() //returns current text cursor (x) coordinate
    {
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
    return csbiInfo.dwCursorPosition.X;
    }

    /*-------------------------wherey()----------------------------------*/

    int wherey() //returns current text cursor (y) coordinate
    {
    CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo);
    return csbiInfo.dwCursorPosition.Y;
    }




    2. Relevant equations
    n/A

    3. The attempt at a solution
    N/A
     
  2. jcsd
  3. Mar 7, 2015 #2

    jedishrfu

    Staff: Mentor

    If this is a character based game then have you looked at ANSI codes?

    http://en.m.wikipedia.org/wiki/ANSI_codes

    I've,used them a lot in my character based programs and scripts to control where I print things to the display. They work in all sorts of languages once you learn how to represent escape codes in your program.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Language C - Position my Printf in X and Y on the screen.
  1. C language problem ? (Replies: 13)

  2. C language (Replies: 6)

  3. C language (Replies: 5)

Loading...