-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFleet.cpp
67 lines (53 loc) · 1.9 KB
/
Fleet.cpp
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
//
// Fleet.cpp
// BATTLESHIP
//
#include "Fleet.h"
// Fleet constructor
Fleet::Fleet()
{
}
// Fleet initconstructor which fills its private data fields with appropriate ship data
Fleet::Fleet( const Ship ships[] )
{
Cruiser = ships[ CRUISER ];
Frigate = ships[ FRIGATE ];
Submarine = ships[ SUBMARINE ];
Escort = ships[ ESCORT ];
Battleship = ships[ BATTLESHIP ];
}
// Returns true if player has no more usuable ship (i.e. all sunk)
bool Fleet::FleetIsSunk( const Board& opponentBoard)
{
// Calls the .isSunk() function for each of the player's ships
return ( Cruiser.isSunk(opponentBoard) && Frigate.isSunk(opponentBoard) && Submarine.isSunk(opponentBoard) && Escort.isSunk(opponentBoard) && Battleship.isSunk(opponentBoard) );
}
// Prints the coordinates of each of the user's ships to the console
void Fleet::ShowUserFleet()
{
// Print coordinate locations for Cruiser
cout << Cruiser.GetName() << " location points: ";
for( int i = 0; i < Cruiser.GetLength(); i++ )
cout << Cruiser.GetSpaceOccupied()[i] << " ";
cout << endl;
// Print coordinate locations for Frigate
cout << Frigate.GetName() << " location points: ";
for( int i = 0; i < Frigate.GetLength(); i++ )
cout << Frigate.GetSpaceOccupied()[i] << " ";
cout << endl;
// Print coordinate location for Submarine
cout << Submarine.GetName() << " location points: ";
for( int i = 0; i < Submarine.GetLength(); i++ )
cout << Submarine.GetSpaceOccupied()[i] << " ";
cout << endl;
// Print coordinate locations for Escort
cout << Escort.GetName() << " location points: ";
for( int i = 0; i < Escort.GetLength(); i++ )
cout << Escort.GetSpaceOccupied()[i] << " ";
cout << endl;
// Print coordinate locations for Battleship
cout << Battleship.GetName() << " location points: ";
for( int i = 0; i < Battleship.GetLength(); i++ )
cout << Battleship.GetSpaceOccupied()[i] << " ";
cout << endl;
}