Jul 19, 2013 at 2:47am UTC
Might i may a suggestion, instead of having the borders apart of the 2d array, just print them apart from it.
1 2 3 4 5 6 7 8 9 10 11
std::cout << "xxxx..... width ......xxxx"
for (int i........ )
{
std::cout << '|' ';
for ( int j..... )
{
print board code
}
std::cout << ' |';
}
std::cout << "xxxx..... width ......xxxx"
EDIT: added the bottom border
sorry for no indentation
this is how i make borders in the console, it makes it alot easier
Last edited on Jul 19, 2013 at 2:49am UTC
Jul 19, 2013 at 3:29am UTC
@ line 34 you use two equals signs instead of one
Move the seeding of the random numbers ( line 86 ) to the beginning of main(). srand() should be called once per program.
As a suggestion, make the board a 2d array of char
, there's no need for strings here.
I'm also getting food that is ending up on the top and bottom border, I would imagine working that out is all part of the fun though :)
Paoletti301 brings up a good point though, you might want to look into a specific way to differentiate between the board and its borders.
Last edited on Jul 19, 2013 at 3:31am UTC
Jul 19, 2013 at 3:40am UTC
Aha! It was the double equals signs! Thank you very much for the help LowestOne. Also, I'll change the program and print the board separately. Thanks for the idea Paoletti301.
Jul 19, 2013 at 3:52am UTC
I personally would keep the borders in the same array, mainly because console is so stupid to try to make look pretty ...
I don't even know how at the top of my head, maybe something like:
1 2 3 4 5 6 7 8 9 10
const int PLAY_AREA_X; = 20;
const int PLAY_AREA_Y = 60;
const int BOARD_X = PLAY_AREA_X + 2; // one character extra for each side
const int BOARD_Y = PLAY_AREA_Y + 2;
char board[BOARD_Y][BOARD_X];
int random_playable( const int remainder ) { return rand() % remainder + 1; }
int random_row( void ) { return random_playable( PLAY_AREA_X ); }
Maybe try to define the border widths somehow.
Last edited on Jul 19, 2013 at 3:53am UTC
Jul 19, 2013 at 4:25am UTC
why keep the border in the same array?
you can just hardcode the border outputs in the print function, which works great for square grids
also question to the op, how do you plan to handle animation with the game?