so im making a game of battleships as a refresher to get back into c++. i made a post the other day about array issues, and thats now fixed thanks to your guys help. now i have... not an issue, a road block- i know what i want to do, i dont know how to do it.
in the game, players need to enter a tile selection (i.e. E,9)for either ship placement or target selection. when that coordinate is entered, im going to store it in a variable via
cin.getline()
.
now what i want to be able to do is then take the variable in which the coordinate is stored and use it to call up the variable attached to the coordinate.
ie:
1 2 3 4 5 6 7 8 9
|
//this isnt my code im using, just an example- input is user enter coords, gui is what will be printf'd, ship present is for math purposes.
if (input = a7)
{
gui_image_a7 = O;
ship_present_a7 = 1;
}
|
the problem is, i dont want to have to write an if statment for each of 100 tiles on my gameboard. is there any function i can use to select a variable in an array from another variable(s) that contain the uer entered data? ie:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
char vert; //vertical
int hori; //horizontal
cout << "please enter coords:" << endl;
cout << "vertical:";
cin >> vert;
cout << endl << "horizontal:";
cin << hori;
vert[hori] = "X"
//what i would intend for the system to see by this line is E[9] = "X". i know that dosnt work, but thats what i need to figure out.
|
is there any function for this, or any way to do it- to use a variable to refrence a variable in an array?