Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean Jager(int x, int y) {
- int cx, cy;
- int[][] directions = new int[][] { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };
- for (int i = 0; i < directions.length; i++) {
- cx = x + directions[i][0];
- cy = y + directions[i][1];
- if (cx > antarktis.length - 1) {
- cx = 0;
- }
- if (cx < 0) {
- cx = antarktis.length - 1;
- }
- if (cy > antarktis[0].length - 1) {
- cy = 0;
- }
- if (cy < 0) {
- cy = antarktis[0].length - 1;
- }
- if (antarktis[cx][cy] != null) {
- if (antarktis[cx][cy].canEat(this)) {
- return true;
- }
- }
- }
- return false;
- }
- // Directions von der Pinguinlabyrinthaufgabe Loesung
- public void move() {
- int x;
- int y;
- int[][] directions = new int[][] { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };
- for (int i = 0; i < directions.length; i++) {
- x = getX() + directions[i][0];
- y = getY() + directions[i][1];
- if (x > antarktis.length - 1) {
- x = 0;
- }
- if (x < 0) {
- x = antarktis.length - 1;
- }
- if (y > antarktis[0].length - 1) {
- y = 0;
- }
- if (y < 0) {
- y = antarktis[0].length - 1;
- }
- if (antarktis[x][y] != null) {
- if (canEat(antarktis[x][y]) && !Jager(x, y)) {
- antarktis[getX()][getY()] = null;
- antarktis[x][y].setAlive(false);
- this.x = x;
- this.y = y;
- antarktis[x][y] = this;
- return;
- }
- }
- }
- for (int i = 0; i < directions.length; i++) {
- x = getX() + directions[i][0];
- y = getY() + directions[i][1];
- if (x > antarktis.length - 1) {
- x = 0;
- }
- if (x < 0) {
- x = antarktis.length - 1;
- }
- if (y > antarktis[0].length - 1) {
- y = 0;
- }
- if (y < 0) {
- y = antarktis[0].length - 1;
- }
- if (antarktis[x][y] == null) {
- if (!Jager(x, y)) {
- antarktis[getX()][getY()] = null;
- this.x = x;
- this.y = y;
- antarktis[x][y] = this;
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement