1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#ifndef BSBOARD_H
#define BSBOARD_H
#include <fstream>
#include <iostream>
// Since this code is simplified, the following identifier must be in strict
// alphabetic order (ANSI table).
enum SHIPS_NAMES : char { AIRCRAFT = 'A',
BATTLESHIP = 'B',
CRUISER = 'C',
DESTROYER = 'D',
SUBMARINE = 'E' };
class BsBoard {
public:
int ac; // Aircraft Carrier
int bat; // Battleship
int cur; // Cruiser
int sub; // Submarine
int des; // Destroyer
// this array is the actual member to be changed in player.cpp,
// and meant to be saved in the player.dat
char b[11][11] = {
{' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'},
{'0', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'1', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'2', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'3', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'4', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'5', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'6', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'7', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'8', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{'9', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
BsBoard() : ac {5}, bat {4}, cur {3}, sub {3}, des {2}
{}
friend std::ofstream& operator<<(std::ofstream& of, const BsBoard& board)
{
for(int i{1}; i!=11; ++i) { // skip first row
for(int j{1}; j!=11; ++j) { // skip first column
of << board.b[i][j] << ' ';
}
}
return of;
}
friend std::ifstream& operator>>(std::ifstream& inf, BsBoard& board)
{
for(int i{1}; i!=11; ++i) { // skip first row
for(int j{1}; j!=11; ++j) { // skip first column
inf >> board.b[i][j];
}
}
return inf;
}
friend std::ostream& operator<<(std::ostream& os, const BsBoard& board)
{
for(int i{0}; i<11; ++i) {
for(int j{0}; j<11; ++j) {
os << board.b[i][j] << ' ';
}
os << '\n';
}
return os;
}
};
#endif // BSBOARD_H
|