-2

I am working on something and i am stuck. I need to make a 5 x 5 square grid. i need to add character in it. Like

* * * * *  
* * * * *
* * * * *
* * * * *
* * * * *
5x5 grid

I need to add a character in it and move it by taking input from user(u,d,l,r) like

p * * * *  User enter d --> * * * * *
* * * * *                   p * * * *
* * * * *                   * * * * *
* * * * *                   * * * * *
* * * * *                   * * * * *

I have no clue how i will add this in a grid.I made grid by this method.

{
int s = 5;
for (int i = 1; i <= s; i = i + 1){

    for (int j = 1; j <= s; j = j + 1){

        cout << " *";

    }

    cout << endl;
}

Now if i add p with * it prints p with all *. Can anyone put me in right direction? That will be great. Thanks.

Dean
  • 3
  • 2

1 Answers1

1

Use an if clause?

If i and j match player's position push 'p' into output stream (cout) else push '*'. If you don't want to write the whole grid again for every move check this out. Linux - moving the console cursor visual

Anže
  • 181
  • 8
  • Oh Man Thank You. You are great, God bless you. – Dean May 24 '18 at 13:23
  • How will i move it? i need an if condtion for that too. – Dean May 24 '18 at 13:34
  • What you did now is drawn the board and the status of a player (his position). Now you need to take input from user and translate it into movement. Switch case would be useful for that one. There you preform the movement by changing i or j of your player (i suggest using x and y to make it easier to understand) according to movement command. Then you loop back and draw the board again. – Anže May 25 '18 at 13:08
  • I suggest you do a bit more reading on C++ syntax and std library. It sounds to me like you are very new to the programming. C++ primer is a very good book for beginners. and you can use http://en.cppreference.com/w/ for quick reference. – Anže May 25 '18 at 13:09