Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Battleship;
- public class Boat {
- //private instance variables
- private String shipName;
- private Position shipPosition;
- private String direction;
- private int size;
- private boolean[] hitsOnBoat;
- }
- //constructor
- public Boat(String shipName, Position, shipPosition, String direction) {
- this.shipName = shipName;
- this.shipPosition = shipPosition;
- this.direcion = direction;
- //set size based on shipName
- if (this.shipName.substring(0,1).equals("A")
- this.size = 5;
- else if (this.shipName.substring(0,1).equals("B"))
- this.size = 4;
- else if (this.shipName.substring(0,1).equals("C"))
- this.size = 3;
- else if (this.shipName.substring(0,1).equals("D"))
- this.size = 2;
- else if (this.shipName.substring(0,1).equals("S"))
- this.size = 3;
- else
- this.size = 2; // defaule case
- //sets hitsOnBoat array
- hitsOnBoat = new boolean(this.size);
- }
- public String name() {
- return this.shipName;
- }
- public char abbreviation() {
- return (this.shipname.charAt(0));
- }
- public int size() {
- return this.size;
- }
- public String direction() {
- return this.direction;
- }
- public Position position() {
- return shipPosition;
- }
- public boolean onBoat(Position checkPosition) {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement