Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void addShip(Ship typeOfShip, Coordinate startingCoordinate, Coordinate endingCoordinate) {
- //check if ship already exists
- std::map<Ship,shipCoordinate>::iterator it;
- it = PlayersShips.find(typeOfShip);
- if (it != this->PlayersShips.end())
- std::cout << "Ship Found";
- int ShipLength = this->ShipProperties.at(*&typeOfShip);
- if (*&startingCoordinate.x != *&endingCoordinate.x && *&startingCoordinate.y != *&endingCoordinate.y) {
- std::cout << "Cant Place a Ship Here !";
- return void();
- }
- else if (*&startingCoordinate.x == *&endingCoordinate.x) {
- if (*&startingCoordinate.y - *& endingCoordinate.y != ShipLength-1 && *&startingCoordinate.y - *& endingCoordinate.y != -ShipLength+1)
- std::cout << "Cant Place a Ship Here !";
- return void();
- }
- else if (*&startingCoordinate.y == *&endingCoordinate.y) {
- if (*&startingCoordinate.x - *& endingCoordinate.x != ShipLength - 1 && *&startingCoordinate.x - *& endingCoordinate.x != -ShipLength + 1)
- std::cout << "Cant Place a Ship Here !";
- return void();
- }
- else {
- //add all of the ships spots taken up into the shipCoordinate array
- shipCoordinate coordinate = { *&startingCoordinate, *&endingCoordinate };
- this->PlayersShips.insert(std::make_pair(*&typeOfShip, *&coordinate));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement