Write a program to move a character around on the screen in response to user key-presses (you’ll have to decide which keys to use for up, down, left and right - combinations like t b f and h work well: or if you’re more ambitious you could find out the ASCII codes for the arrow keys). Use the CursorController class to paint it at the new position each time, not forgetting to erase its previous location first (by printing a space). The program should terminate when the user presses the x key.

Can anyone help me with this? I tried this with a code I made but it got wiped out and I don't know where to start as I spent so long on it.

Try filling out this code with whatever corresponding functions exist in your library:

const char up=0;//put the value for up here
const char down=0;//put the value for down here
const char right=0;//put the value for right here
const char left=0;//put the value for left here
const char exit=0;//put the value for exit here
const char disp=0;//put the value for display character here
class movingChar
{
    private:
    int x,y;
    void moveUp()
    {
        printAt(x,y,' ');//delete the old char (use the library for this)
        y++;//change position (possible use y-- depending on your coordinate system
        printAt(x,y,disp);
    }
    //etc...
    public:
    movingChar()
    {
        //you need to do this on your own
    }
    bool step()
    {
        //this is the step function, return false to quit
        char in=getInput();//your library will have this i suppose?
        switch (in)
        {
             case up:
             moveUp();
             return true;
             case down:
             moveDown();
             return true;
             //etc...
             case exit:
             return false;
             default:
             return true;
        }
    }
};
int main()
{
    movingChar mc;
    while (mc.step()){}
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.