diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-19 17:15:03 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-01-19 17:15:03 +0100 |
commit | 081b90f0e64ce7796692bc2b6d3528279c5a1e59 (patch) | |
tree | 12bb678fe330ab9342e72b06f43767ae223134c9 /same-android/src/main/java/com/orbekk/GameView.java | |
parent | 3c33d22719225630761cb1ad97252dab977e2e36 (diff) |
Change the android client to use the Same interface.
Diffstat (limited to 'same-android/src/main/java/com/orbekk/GameView.java')
-rw-r--r-- | same-android/src/main/java/com/orbekk/GameView.java | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/same-android/src/main/java/com/orbekk/GameView.java b/same-android/src/main/java/com/orbekk/GameView.java index edb41cb..1240671 100644 --- a/same-android/src/main/java/com/orbekk/GameView.java +++ b/same-android/src/main/java/com/orbekk/GameView.java @@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory; import com.orbekk.same.State.Component; import com.orbekk.same.ClientService; import com.orbekk.same.ClientServiceImpl; +import com.orbekk.same.SameInterface; +import com.orbekk.same.UpdateConflict; import android.content.Context; import android.graphics.Canvas; @@ -28,13 +30,13 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback { private Context context; private Paint background; private Paint paint; - private ClientServiceImpl client; + private SameInterface same; public GameThread(SurfaceHolder holder, Context context, - ClientServiceImpl client) { + SameInterface client) { this.holder = holder; this.context = context; - this.client = client; + this.same = client; posX = 100; posY = 100; paint = new Paint(); @@ -72,20 +74,16 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback { posX = x; posY = y; run(); - long rev = 0; - Component c = client.getState("position"); - if (c != null) { - rev = c.getRevision(); - } - - if (client.sendStateUpdate("position", this.posX + "," + this.posY, - rev + 1)) { - logger.warn("Unable to set state."); + try { + same.set("position", this.posX + "," + this.posY); + } catch (UpdateConflict e) { + logger.warn("Update conflict.", e); } + } } - public GameView(Context context, ClientServiceImpl client) { + public GameView(Context context, SameInterface client) { super(context); getHolder().addCallback(this); thread = new GameThread(getHolder(), context, client); |