Advertisement
xFazz

battle ships

Oct 22nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package Battleship;
  2.  
  3. public class Boat {
  4. //private instance variables
  5. private String shipName;
  6. private Position shipPosition;
  7. private String direction;
  8.  
  9. private int size;
  10. private boolean[] hitsOnBoat;
  11. }
  12.  
  13. //constructor
  14. public Boat(String shipName, Position, shipPosition, String direction) {
  15. this.shipName = shipName;
  16. this.shipPosition = shipPosition;
  17. this.direcion = direction;
  18.  
  19. //set size based on shipName
  20. if (this.shipName.substring(0,1).equals("A")
  21. this.size = 5;
  22. else if (this.shipName.substring(0,1).equals("B"))
  23. this.size = 4;
  24. else if (this.shipName.substring(0,1).equals("C"))
  25. this.size = 3;
  26. else if (this.shipName.substring(0,1).equals("D"))
  27. this.size = 2;
  28. else if (this.shipName.substring(0,1).equals("S"))
  29. this.size = 3;
  30. else
  31. this.size = 2; // defaule case
  32.  
  33. //sets hitsOnBoat array
  34. hitsOnBoat = new boolean(this.size);
  35.  
  36. }
  37.  
  38. public String name() {
  39. return this.shipName;
  40. }
  41.  
  42. public char abbreviation() {
  43. return (this.shipname.charAt(0));
  44. }
  45.  
  46. public int size() {
  47. return this.size;
  48. }
  49.  
  50. public String direction() {
  51. return this.direction;
  52. }
  53.  
  54. public Position position() {
  55. return shipPosition;
  56. }
  57.  
  58. public boolean onBoat(Position checkPosition) {
  59. return false;
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement