0

I have some code to draw a grid with simple characters like | | | for verticals and ----------------- for the horizontal line.

But as you play the game for some reason one of the rows gets shifted to the right. I have no clue why this happens. Even initially the zeroth row gets shifted

int blankflag = 0;
  cout << "\n   ------------------------------------------------- ";
  for (int i = 4; i >= 0; i--)
  {
    cout << "\n";
    cout << i;

    for (int j = 0; j <= 4; j++)
    {
    if (blankflag)
      {
        cout << "   |";
        blankflag = 0;
      }
      else
      {
        cout << "     |";
      }
      for (int k = 0; k < 4; k++)
      {
        if ('k'th queen is at i,j)
        {
          if (player 1's queen)
          {
            cout << "# ";
          }
          else if (player 2's queen)
          {
            cout << "O ";
          }
          blankflag = 1;
        }

      }
      if (arrow at i,j and no queen)
      {
        cout << "X";
        blankflag = 1;
      }
    }
    if (blankflag)
    {
      cout << "   |";
    }
    else
    {
      cout << "     |";
    }
    cout << "\n   ------------------------------------------------- ";
  }
  cout << " \n         a     b    c     d     e";

The arrow is another mechanic. Anyways as arrows are shot and game progresses randomly the lowest and second lowest rows get shifted when i redraw the board. Anyone has a more elegant grid solution? I just want to draw a X or a # or a O depending on my game state(which is built)

Jon Bovi
  • 53
  • 9
  • 2
    "_I have no clue why this happens_" Did you try stepping through your code with a debugger? – Algirdas Preidžius Nov 26 '18 at 16:13
  • related/dupe: https://stackoverflow.com/questions/14765155/how-can-i-easily-format-my-data-table-in-c – NathanOliver Nov 26 '18 at 16:14
  • @AlgirdasPreidžius yes I did there is no blank at the start and there are no extra vertical lines. There is no reason the game works at start and also for a few moves. But during some moves only the first or zeroth row shift to right – Jon Bovi Nov 26 '18 at 16:17
  • @JonBovi So did you, or didn't you? Since the comment seems to be self-contradicting. If you did step through your code, with a debugger, while investigating the values of the variables, at each step, you would have understanding of why it happens (or, at the very least, when it happens). – Algirdas Preidžius Nov 26 '18 at 16:23
  • Yes I think its gotta do with something related to how the numbers 0/1 takes less/more space or something – Jon Bovi Nov 26 '18 at 16:28
  • 1
    Try using a monospaced font. – paddy Nov 26 '18 at 16:38
  • You may want to consider placing the `'\n'` at the end of the lines, to help visually line up the text. – Thomas Matthews Nov 26 '18 at 18:47

0 Answers0