movement

is it possible to move a character by pressing for example i,j,k,l by using for loops
yes
how can this be achieved ?
use global object cin

1
2
3
4
5
int main()
{
     char x;
     cin >> x;
}
i know about the use object cin; however i want the character to move to the left if press j on the keyboard for example
I'm not shore what you want exactly :/

can you explain a bit more?
i would like the user to input a character for example like *, and i want them to be able to move it by pressing i for up , k for down, j for left and l for right.
You need to use a library for that. Standard c++ doesn't know about keyboards.
heres my code:

#include<iostream>
#include"110ct.h"
#include<string>

using namespace std;

int main()
{
CursorController crs;
ColourController cl;


int Number;// the number of stairs
int Amount = 1; // this is the amount of x it will add to the line

string A;// this is the variable for the character
char movementi = 'i' ;// this is the variable to move the character
char movementk = 'k';
char movementj = 'j';
char movementl = 'l';

double xval ,yval;
xval= 2;// the set x postion coordinates
yval= 3;//the set x postion coordinates


cout << "Enter in how many 'stairs' you want" << endl;
cin >> Number;
cout << " now enter a special character to move up and down the starirs \n";
cin >> A;

for(int c = 0; c < Number; c++)
{
for(int d = 0; d < Amount; d++)
{
cout << "*";//the charater for the stair
}

cout << endl;
Amount +=1; //Adds 1 'X' after every new line

}
while( movementi =='i')
{
yval=yval-0.5;
crs.setPosition(xval,yval);
cout << A <<"\n";
qin>>movementi;
crs.clearAll();
cout<< " to move the special character press the following keys \n";
cout<< " press i for up \n k for down \n j for left and l for right \n";// intructions for the keys

}
while( movementk == 'k')
{
yval=yval+0.5;
crs.setPosition(xval,yval);
cout << A <<"\n";
qin>>movementk;
crs.clearAll();
cout<< " to move the special character press the following keys \n";
cout<< " press i for up \n k for down \n j for left and l for right \n";// intructions for the keys

}
while( movementj == 'j')
{
xval=xval-0.5;
crs.setPosition(xval,yval);
cout << A <<"\n";
qin>>movementj;
crs.clearAll();
cout<< " to move the special character press the following keys \n";
cout<< " press i for up \n k for down \n j for left and l for right \n";// intructions for the keys

}
while( movementl != 'l')
{
xval=xval+0.5;
crs.setPosition(xval,yval);
cout << A <<"\n";
qin>>movementl;
crs.clearAll();
cout<< " to move the special character press the following keys \n";
cout<< " press i for up \n k for down \n j for left and l for right \n";// intructions for the keys
}


qin.get();

return 0;
}
if you're talking about moving a character inside a console then so:

short description:

1.global while loop which does not end
2. iner switch statement with iner while loops
3. clearing the console for every key pressed to update the screen.
4. each inner loop inside a swithc will print the character while scree in cleard in same time
so that character in there only once but on different position.

that's how I would imagine such task.

hope this help.
Topic archived. No new replies allowed.