I'm trying to write a GUI for a battleship game for class and am running into problems with the Win API and such for C++ on Visual Studio 2010.
My issues:
1) I pass in 2 vectors and an int. ie. - DrawBoard(int xsize, vector<char> ShotBrd, vector<char> ShipBrd)
"Shotbrd" contains the cells where I've fired, and whether they were "hit" or "miss"
"Shipbrd" contains the cells where my ships are.
"xsize" is the integer size of each row.
In the console version, I used a for() loop and cout<< to display a grid.
1 2 3 4 5 6 7 8 9 10 11
|
int i=0
for (int y=0;y<ysize;y++)
{
for(int x=0;x<xsize;x++)
{
i=(y*xsize)+x
cout<<Shotbrd[i];
}
cout<<endl;
}
|
and this would display something similar to:
~~~~~~*~~
*~*~~~*~~
*x*~~~~~~
~~~~~~~~~
~~~~~~~~~ |
with the ~ being waves/unshot areas, * being shot but misses, and x being hits.
I need to translate this to Blue buttons for waves, Red buttons for hits, and Grey buttons for misses.
A similar setup is setup for the "ShipBrd".
2) I need the Shotboard buttons to return their position when clicked. I was able to do this with a single button, but with an array of dynamically created buttons was a little harder...