I've managed to get around that but I have tested using the reference.
I can draw the tile now based on coords and I'm busy trying to making the drawing function recursive.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
class board
{
public:
board();
~board();
string arboard[50][50];
void initboard();
void refreshboard();
void addtile(int x,int y,int z);
};
//constructor init board with x
board::board(){};
board::~board(){};
void board::initboard()
{
for(int i=0;i<20;i++)
{
for (int j=0;j<20;j++)
{
arboard[i][j] = "X";
cout<< arboard[i][j] ;
}
cout << endl;
}
};
void board::refreshboard()
{
//this function will draw the board with tiles one it.
for(int i=0;i<20;i++)
{
for (int j=0;j<20;j++)
{
cout<< arboard[i][j];
}
cout << endl;
}
};
void board::addtile(int x,int y,int z)
{
int newx = 0;
int newy = 0;
int tiles = 0;
int levels = 1;
//number of new hegaxons to be drawn
int iterations = ((2*(2*levels)-1) + (2*(1+ levels)));
// count hexagons
for(int i=0;i<20;i++)
{
for (int j=0;j<20;j++)
{
if (arboard[i][j] == "|")
{
tiles++;
}
}
}
// this version draw the tile but it only ever draw one on the board .
arboard[y-1][x-2] = " ";
arboard[y-1][x-1] = "/";
arboard[y-1][x] = " ";
arboard[y-1][x+1] = "\\";
arboard[y-1][x+2] = " ";
//Draw middle
arboard[y][x-2] = "|";
arboard[y][x-1] = " ";
arboard[y][x] = 1;
arboard[y][x+1] = " ";
arboard[y][x+2] = "|";
//draw bottom
arboard[y+1][x-2] = " "; // this is the new coord for next tile.
arboard[y+1][x-1] = "\\";
arboard[y+1][x] = " ";
arboard[y+1][x+1] = "/";
arboard[y+1][x+2] = " ";
};
/*void SetTile(board &myboard,int x,int y,int z)
{
//function to set the tile to interface with the class method
myboard.addtile(x,y,z);
myboard.refreshboard();
}*/
int main()
{
int x = 0;
int y=0;
int i = 0;
board myboard;
myboard.initboard();
while (i<5)
{
cout << "Insert X and Y \n";
cin >> x ;
cin >> y;
myboard.addtile(x,y,1);
myboard.refreshboard();
i++;
}
return 0;
}
Thanks for the help.
I spend most of the day drawing hexagons and finding a pattern or formula to the number of new tiles to be drawn which is
((2*(2*levels)-1) + (2*(1+ levels)));