Advertisement
Guest User

fml

a guest
Dec 8th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. public boolean Jager(int x, int y) {
  2.         int cx, cy;
  3.         int[][] directions = new int[][] { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };
  4.         for (int i = 0; i < directions.length; i++) {
  5.             cx = x + directions[i][0];
  6.             cy = y + directions[i][1];
  7.  
  8.             if (cx > antarktis.length - 1) {
  9.                 cx = 0;
  10.             }
  11.             if (cx < 0) {
  12.                 cx = antarktis.length - 1;
  13.             }
  14.             if (cy > antarktis[0].length - 1) {
  15.                 cy = 0;
  16.             }
  17.  
  18.             if (cy < 0) {
  19.                 cy = antarktis[0].length - 1;
  20.             }
  21.  
  22.             if (antarktis[cx][cy] != null) {
  23.                 if (antarktis[cx][cy].canEat(this)) {
  24.                     return true;
  25.                 }
  26.             }
  27.         }
  28.         return false;
  29.     }
  30.  
  31.     // Directions von der Pinguinlabyrinthaufgabe Loesung
  32.     public void move() {
  33.         int x;
  34.         int y;
  35.         int[][] directions = new int[][] { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };
  36.         for (int i = 0; i < directions.length; i++) {
  37.             x = getX() + directions[i][0];
  38.             y = getY() + directions[i][1];
  39.  
  40.             if (x > antarktis.length - 1) {
  41.                 x = 0;
  42.             }
  43.             if (x < 0) {
  44.                 x = antarktis.length - 1;
  45.             }
  46.             if (y > antarktis[0].length - 1) {
  47.                 y = 0;
  48.             }
  49.  
  50.             if (y < 0) {
  51.                 y = antarktis[0].length - 1;
  52.             }
  53.  
  54.             if (antarktis[x][y] != null) {
  55.                 if (canEat(antarktis[x][y]) && !Jager(x, y)) {
  56.                     antarktis[getX()][getY()] = null;
  57.                     antarktis[x][y].setAlive(false);
  58.                     this.x = x;
  59.                     this.y = y;
  60.                     antarktis[x][y] = this;
  61.                     return;
  62.                 }
  63.             }
  64.  
  65.         }
  66.         for (int i = 0; i < directions.length; i++) {
  67.             x = getX() + directions[i][0];
  68.             y = getY() + directions[i][1];
  69.  
  70.             if (x > antarktis.length - 1) {
  71.                 x = 0;
  72.             }
  73.             if (x < 0) {
  74.                 x = antarktis.length - 1;
  75.             }
  76.             if (y > antarktis[0].length - 1) {
  77.                 y = 0;
  78.             }
  79.  
  80.             if (y < 0) {
  81.                 y = antarktis[0].length - 1;
  82.             }
  83.  
  84.             if (antarktis[x][y] == null) {
  85.                 if (!Jager(x, y)) {
  86.                     antarktis[getX()][getY()] = null;
  87.                     this.x = x;
  88.                     this.y = y;
  89.                     antarktis[x][y] = this;
  90.                     return;
  91.                 }
  92.             }
  93.         }
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement