Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Fix bug in move.
Browse files Browse the repository at this point in the history
  • Loading branch information
darnuria committed Mar 16, 2016
1 parent ad9d431 commit 10a2664
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions app/src/main/java/android/rushdroid/GameView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ final public class GameView extends SurfaceView {
private final int game_height = 6;
private final int[] xs = new int[game_width];
private final int[] ys = new int[game_height];
private final Context context;
private final Context context;
private Integer current = null;
private int down_x;
private int down_y;
private final Model m;
private boolean ret;
// private Bitmap bitmap;

private void fillArray(int[] a, int game_size, int surface_size) {
Expand Down Expand Up @@ -93,11 +94,11 @@ private void drawGrid(Canvas c) {
Paint p = new Paint();
p.setColor(Color.RED);
int Y = this.surface_height;
for (int x: this.xs) {
for (int x : this.xs) {
c.drawLine(x, 1, x, Y, p);
}
int X = this.surface_width;
for (int y: this.ys) {
for (int y : this.ys) {
c.drawLine(1, y, X, y, p);
}
c.drawLine(0, Y - 1, X - 1, Y - 1, p);
Expand Down Expand Up @@ -158,13 +159,12 @@ public void onDraw(@NonNull Canvas c) {
* @see Position
*/
private Position interpolation(int x, int y) {
return new Position(x * this.game_width / this.surface_width,
y * this.game_height / this.surface_height);
return new Position(x * this.game_width / this.surface_width, y * this.game_height / this.surface_height);
}

// Mouhahaha ternary power!
// A lot of side effects.
private boolean help_move(int prev, int now) {
return (prev <= now) ? this.m.moveForward(this.current) : this.m.moveBackward(this.current);
return prev <= now ? this.m.moveForward(this.current) : this.m.moveBackward(this.current);
}

@Override
Expand All @@ -178,17 +178,17 @@ public boolean onTouchEvent(@NonNull MotionEvent e) {
this.down_x = x;
this.down_y = y;
return true;
} case MotionEvent.ACTION_MOVE: {
return false;
} case MotionEvent.ACTION_UP: {
// Si current non null : ajouter le deplacement dans la queue.
boolean ret = false;
}
case MotionEvent.ACTION_UP: {
if (this.current != null) {
ret = (m.getOrientation(current) == Direction.HORIZONTAL) ? help_move(down_y, y) : help_move(down_x, x);
this.ret = m.getOrientation(current) == Direction.VERTICAL
? help_move(down_y, y)
: help_move(down_x, x);
this.current = null;
}
return ret;
} default: {
return true;
}
default: {
return false;
}
}
Expand Down

0 comments on commit 10a2664

Please sign in to comment.