Commit 7b5d88e2 authored by Omid Sayfun's avatar Omid Sayfun

No Movement bug fixed

parent 2bedad5a
package lab.game; package lab.game;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.io.IOException; import java.io.IOException;
...@@ -128,13 +129,16 @@ public class Board{ ...@@ -128,13 +129,16 @@ public class Board{
} }
yShift = rand.nextInt(3) - 1; yShift = rand.nextInt(3) - 1;
} }
this.thiefMoves++; if( xShift != 0 || yShift != 0 ){
this.thief.setCoordinates(this.thief.getX() + xShift, this.thief.getY() + yShift);
if( isTakenByPolice(this.thief.getX() + xShift, this.thief.getY() + yShift) ){ this.thiefMoves++;
this.thief.setCoordinates(this.thief.getX() + xShift, this.thief.getY() + yShift);
if( isTakenByPolice(this.thief.getX() + xShift, this.thief.getY() + yShift) ){
return false; return false;
}else{ }else{
break; break;
}
} }
} }
// Move Polices // Move Polices
...@@ -158,17 +162,19 @@ public class Board{ ...@@ -158,17 +162,19 @@ public class Board{
} }
yShift = rand.nextInt(3) - 1; yShift = rand.nextInt(3) - 1;
} }
if( !isTakenByPolice(p.getX() + xShift, p.getY() + yShift) ){ if( xShift != 0 || yShift != 0 ){
if( !isTakenByPolice(p.getX() + xShift, p.getY() + yShift) ){
p.setCoordinates(p.getX() + xShift, p.getY() + yShift); p.setCoordinates(p.getX() + xShift, p.getY() + yShift);
if( isThiefInRange(p.getX(), p.getY()) ){ if( isThiefInRange(p.getX(), p.getY()) ){
for( Police police : this.polices ){ for( Police police : this.polices ){
police.setTarget(this.thief); police.setTarget(this.thief);
}
} }
this.policeMoves++;
break;
} }
this.policeMoves++;
break;
} }
} }
}else{// Move based on thought :D }else{// Move based on thought :D
...@@ -224,15 +230,17 @@ public class Board{ ...@@ -224,15 +230,17 @@ public class Board{
} }
yShift = rand.nextInt(3) - 1; yShift = rand.nextInt(3) - 1;
} }
if( !isTakenByPolice(p.getX() + xShift, p.getY() + yShift) ){ if( xShift != 0 || yShift != 0 ){
if( !isTakenByPolice(p.getX() + xShift, p.getY() + yShift) ){
p.setCoordinates(p.getX() + xShift, p.getY() + yShift); p.setCoordinates(p.getX() + xShift, p.getY() + yShift);
this.policeMoves++; this.policeMoves++;
if( p.getY() == prevY && p.getX() == prevX ){ if( p.getY() == prevY && p.getX() == prevX ){
return false; return false;
}
break;
} }
break;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment