Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- /**
- * Created by Ricsko on 2017. 03. 09..
- */
- public class ClassTorpedo {
- private boolean[] boatlocations = new boolean[7];
- private int hits = 0;
- private boolean[] boatCheck = new boolean[7];
- public ClassTorpedo(int[] pos) {
- for(int j = 0; j < pos.length;j++) {
- for (int i = 0; i < boatlocations.length; i++) {
- if(pos[j] == i){
- boatlocations[i] = true;
- }
- }
- }
- boatCheck = this.boatlocations;
- }
- public void hitTorepedo (int position){
- if(boatlocations[position]){
- boatlocations[position] = false;
- hits++;
- hit(position);
- checkDestroy();
- }else{
- nothit();
- }
- }
- public void checkDestroy(){
- if(hits == 3)
- destroy();
- }
- public void nothit(){
- System.out.println("nem talat");
- }
- public void destroy(){
- System.out.println("destroyed the ship");
- }
- public void hit(int pos1){
- System.out.println("Talalt :" + pos1);
- }
- public void kiir(){
- System.out.println(this);
- }
- public boolean[] getBoatCheck() {
- return boatCheck;
- }
- public boolean[] getBoatlocations() {
- return boatlocations;
- }
- public void setBoatlocations(boolean[] boatlocations) {
- this.boatlocations = boatlocations;
- }
- public int getHits() {
- return hits;
- }
- public void setHits(int hits) {
- this.hits = hits;
- }
- @Override
- public String toString() {
- return "ClassTorpedo{" +
- "boatlocations=" + Arrays.toString(boatlocations) +
- ", hits=" + hits +
- '}';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment