0

We have a discussion on using std::pair or some own struct for Snake game column and row. Do we need to create something like that:

struct { int row; int col;} ... cell.row, cell.col;

Or use:

std::pair<int, int> ... cell.first, cell.second;

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
vityo
  • 1
  • Are you trying to create a two-dimensional grid? – jkdev Mar 01 '16 at 11:51
  • @jkdev yes. what will be look appropriately? – vityo Mar 02 '16 at 14:56
  • How about a [two-dimensional array](http://www.cprogramming.com/tutorial/lesson8.html)? Then you could retrieve each element using, for example, `snake_grid[x][y]`. – jkdev Mar 02 '16 at 20:42
  • @jkdev it was test work [technical task link](https://drive.google.com/file/d/0B0JzYnpdRNuGZVhhQ24tSTVHMG8/view?usp=sharing) and this [github link](https://github.com/vityo/SnakePopCap) . 2d array maybe not suit, because we need to find free cell from collection of free places in game (game have cells with walls), so i take set of cells: set. But question is what cell_type must be: my own struct, or we need to use standard pair – vityo Mar 04 '16 at 12:15
  • I think either option would work (struct or standard pair). It's not a question of "need"; you could choose one or the other. Take a look at this answer: http://stackoverflow.com/a/5260147/3345375 It describes playing cards rather than grids, but the same principles might apply. – jkdev Mar 06 '16 at 06:08

0 Answers0