Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/mapstuff/block
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv10632/src/games/stendhal/server/entity/mapstuff/block
Modified Files:
Block.java
Log Message:
extract method to pre-calculate position after pushing based on a direction
Index: Block.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/mapstuff/block/Block.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Block.java 10 Jan 2013 20:08:26 -0000 1.2
--- Block.java 14 Jan 2013 18:16:49 -0000 1.3
***************
*** 70,78 ****
*/
public void push(Direction d) {
! if(this.mayBePushed()) {
! this.setPosition(this.getX() + d.getdx(), this.getY() + d.getdy());
}
}
private boolean wasPushed() {
boolean xChanged = this.getInt("x") != this.getInt("start_x");
--- 70,86 ----
*/
public void push(Direction d) {
! if(this.mayBePushed(d)) {
! this.setPosition(getXAfterPush(d), getYAfterPush(d));
}
}
+ protected int getYAfterPush(Direction d) {
+ return this.getY() + d.getdy();
+ }
+
+ protected int getXAfterPush(Direction d) {
+ return this.getX() + d.getdx();
+ }
+
private boolean wasPushed() {
boolean xChanged = this.getInt("x") != this.getInt("start_x");
***************
*** 81,85 ****
}
! private boolean mayBePushed() {
boolean pushed = wasPushed();
boolean multiPush = this.getBool("multi");
--- 89,93 ----
}
! private boolean mayBePushed(Direction d) {
boolean pushed = wasPushed();
boolean multiPush = this.getBool("multi");
|