Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1.  void addShip(Ship typeOfShip, Coordinate startingCoordinate, Coordinate endingCoordinate) {
  2.  
  3.         //check if ship already exists
  4.         std::map<Ship,shipCoordinate>::iterator it;
  5.         it = PlayersShips.find(typeOfShip);
  6.  
  7.         if (it != this->PlayersShips.end())
  8.             std::cout << "Ship Found";
  9.  
  10.         int ShipLength = this->ShipProperties.at(*&typeOfShip);
  11.         if (*&startingCoordinate.x != *&endingCoordinate.x && *&startingCoordinate.y != *&endingCoordinate.y) {
  12.             std::cout << "Cant Place a Ship Here !";
  13.             return void();
  14.         }
  15.         else if (*&startingCoordinate.x == *&endingCoordinate.x) {
  16.             if (*&startingCoordinate.y - *& endingCoordinate.y != ShipLength-1 && *&startingCoordinate.y - *& endingCoordinate.y != -ShipLength+1)
  17.                 std::cout << "Cant Place a Ship Here !";
  18.             return void();
  19.         }
  20.         else if (*&startingCoordinate.y == *&endingCoordinate.y) {
  21.             if (*&startingCoordinate.x - *& endingCoordinate.x != ShipLength - 1 && *&startingCoordinate.x - *& endingCoordinate.x != -ShipLength + 1)
  22.                 std::cout << "Cant Place a Ship Here !";
  23.             return void();
  24.         }
  25.         else {
  26.             //add all of the ships spots taken up into the shipCoordinate array
  27.             shipCoordinate coordinate = { *&startingCoordinate, *&endingCoordinate };
  28.             this->PlayersShips.insert(std::make_pair(*&typeOfShip, *&coordinate));
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement