ricskooo

Untitled

Mar 9th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. /**
  4. * Created by Ricsko on 2017. 03. 09..
  5. */
  6. public class ClassTorpedo {
  7. private boolean[] boatlocations = new boolean[7];
  8. private int hits = 0;
  9. private boolean[] boatCheck = new boolean[7];
  10.  
  11. public ClassTorpedo(int[] pos) {
  12. for(int j = 0; j < pos.length;j++) {
  13. for (int i = 0; i < boatlocations.length; i++) {
  14. if(pos[j] == i){
  15. boatlocations[i] = true;
  16. }
  17. }
  18. }
  19. boatCheck = this.boatlocations;
  20. }
  21.  
  22. public void hitTorepedo (int position){
  23. if(boatlocations[position]){
  24. boatlocations[position] = false;
  25. hits++;
  26. hit(position);
  27. checkDestroy();
  28. }else{
  29. nothit();
  30. }
  31. }
  32.  
  33. public void checkDestroy(){
  34. if(hits == 3)
  35. destroy();
  36. }
  37.  
  38. public void nothit(){
  39. System.out.println("nem talat");
  40. }
  41.  
  42. public void destroy(){
  43. System.out.println("destroyed the ship");
  44. }
  45.  
  46. public void hit(int pos1){
  47. System.out.println("Talalt :" + pos1);
  48. }
  49.  
  50. public void kiir(){
  51. System.out.println(this);
  52. }
  53.  
  54. public boolean[] getBoatCheck() {
  55. return boatCheck;
  56. }
  57.  
  58. public boolean[] getBoatlocations() {
  59. return boatlocations;
  60. }
  61.  
  62. public void setBoatlocations(boolean[] boatlocations) {
  63. this.boatlocations = boatlocations;
  64. }
  65.  
  66. public int getHits() {
  67. return hits;
  68. }
  69.  
  70. public void setHits(int hits) {
  71. this.hits = hits;
  72. }
  73.  
  74. @Override
  75. public String toString() {
  76. return "ClassTorpedo{" +
  77. "boatlocations=" + Arrays.toString(boatlocations) +
  78. ", hits=" + hits +
  79. '}';
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment