I need to identify what type of ship is the "row".
For example, I have this data in the file:
1 2 3
A1;A2;A3=Y
B1;C1;D1=Z
C5;C6=X
Assuming:
Y symbolize "Battlecruiser"
Z symbolize "Fishing-Boat"
X symbolize "Destroyer"
Before this, I've done an extraction of data by extracting the individual coordinates out like "A1","A2","A3" and store them in an array. And I compare the input of the user with the array and if the input and coordinate matches, it will show "Hit!". But now what I want to do is that, the system knows what the user has hit when he "fired" the shot e.g "A3".
Instead of "Hit!", I want to do something that identify it as a BattleCruiser. So it will cout "You've hit a Battlecruiser!" and subsequently for the other types of ship. How can I do this?
// Assume shipType is the matched value you got from the user
cout << "You've hit a ";
if(shipType == "X") {
cout << "Destroyer!";
} elseif(shipType == "Y") {
cout << "Battlecruiser!";
} else {
cout << "Fishing-Boat!";
}
So when u extract the coordinate it'll store them like this in the array - "A1" , "A2" , "A3"
So i need think of a way to extract that "Y" out and do a if-else condition..
What I did now was to declare a variable for each of the letter symbols like this A1;A2;A3=S
So its "S" in this case, which will resembles submarine. Then i do a "find() to find those letter in the lines and store each of these find() into a variable for example subFound = line.find(submarine);.
So right now, I want to do a condition as followed:
1. If the user-input is = any of the variable in the array
AND
2. If the line matches with .e.g subFound (find() for submarine)
Then it will cout "You hit a submarine!"
Something like that, that's my logic on doing this.. still trying to figure..