I am nearly done with creating my battleship game. It uses a 10x10 game board and has 5 ships. I am however having problems with my one class where it says that it does not name a type. I've been googling, trying to figure where my problem might be but I'm totally lost now.
If I could get some help that would be most appreciated!
Here is my Game.h file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef GAME_H
#define GAME_H
class GAME {
public:
GAME();
PLAYER& getPlayer(int id);
void fire(PLAYER&, int, int); //attacks enemy ship
void writefile() ;
int userwincount = 0 ;
int oppwincount = 0 ;
private:
PLAYER player1 ;
PLAYER player2 ;
};
#endif /* GAME_H */
One obvious error that I see is that in battleship.h at lines 12-13 is the order of your includes.
game.h users PLAYER, therefore player.h should be included BEFORE game.h.
If that doesn't fix your undefined type, please post the EXACT error messages from your compiler.
Wow! Thanks so much, I'm an idiot!
Now the last thing that I am not sure how to do is to write out to a file where it will output:
The user has won 'x' times.
The CPU has won 'y' times.
where x and y are variables that increment each integer the game ends.
Here's what I have so far but I already know it's wrong as errors come up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void writefile(filename)
{
fstream win ;
win.open("filename.txt") ;
std::string user = "The user has won: " + userwincount + " times." ;
std::string opp = "The CPU has won: " + oppwincount + " times." ;
if (!win.fail())
{
}
elsereturn 0 ;
}