From 81697889e9eb195779cf2f0126b05dcfa7b8672a Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 22 Apr 2013 02:10:24 +0000 Subject: [PATCH] Add Spades class and tie things together Spades gets messages from the Main Activity and will checks the various rhawk IRC messages formats and the command the Cards view to display the appropriate information. It will also get commands from the Cards view, checks them for validity, and then format them as IRC messages to send to the Task/Client. --- src/org/pileus/spades/Cards.java | 2 ++ src/org/pileus/spades/Main.java | 12 +++++-- src/org/pileus/spades/Spades.java | 59 +++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/org/pileus/spades/Spades.java diff --git a/src/org/pileus/spades/Cards.java b/src/org/pileus/spades/Cards.java index 9085a8f..e4c566e 100644 --- a/src/org/pileus/spades/Cards.java +++ b/src/org/pileus/spades/Cards.java @@ -124,6 +124,7 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer private Map index; // card name to index map /* Properties */ + public Spades game; // the spades game public String[] hand; // cards to display public String[] pile; // played cards to display @@ -293,6 +294,7 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer } if (y >= this.ylim && this.drag && up) { //Os.debug("Cards: onTouchEvent - playing card"); + this.game.onPlay(this.hand[this.pick]); } if (up) { //Os.debug("Cards: onTouchEvent - ending drag"); diff --git a/src/org/pileus/spades/Main.java b/src/org/pileus/spades/Main.java index 502d5ae..56691e4 100644 --- a/src/org/pileus/spades/Main.java +++ b/src/org/pileus/spades/Main.java @@ -32,6 +32,7 @@ public class Main extends Activity private String topic; private String names; private Cards cards; + private Spades game; /* Widgets */ private TabHost window; @@ -113,7 +114,8 @@ public class Main extends Activity private void onRegister(Task task) { Os.debug("Main: onRegister"); - this.task = task; + this.task = task; + this.game.task = task; this.running = this.task.isRunning(); for (Object obj : this.task.getLog()) { if (String.class.isInstance(obj)) @@ -133,6 +135,7 @@ public class Main extends Activity switch (msg.type) { case PRIVMSG: this.display(msg); + this.game.onMessage(msg); break; case TOPIC: if (!msg.txt.equals(this.topic)) @@ -253,8 +256,13 @@ public class Main extends Activity .setIndicator("Debug") .setContent(R.id.debug)); - // Setup OpenGL view + // Setup Spades game and cards view + this.game = new Spades(); this.cards = new Cards(this); + + this.game.cards = this.cards; + this.cards.game = this.game; + this.spades.addView(cards); // Attach to background service diff --git a/src/org/pileus/spades/Spades.java b/src/org/pileus/spades/Spades.java new file mode 100644 index 0000000..a9fd150 --- /dev/null +++ b/src/org/pileus/spades/Spades.java @@ -0,0 +1,59 @@ +package org.pileus.spades; + +public class Spades +{ + /* Private data */ + public Task task; + public Cards cards; + + /* Widget callback functions */ + public Spades() + { + } + + /* IRC Callbacks */ + public void onMessage(Message msg) + { + Os.debug("Spades: onMessage"); + } + + /* UI Callbacks */ + public boolean onBid(int bid) + { + Os.debug("Spades: onBid - " + bid); + return this.send(".bid " + bid); + } + + public boolean onPass(String card) + { + Os.debug("Spades: onPass - " + card); + return this.send(".pass " + card); + } + + public boolean onLook() + { + Os.debug("Spades: onLook"); + return this.send(".look"); + } + + public boolean onPlay(String card) + { + Os.debug("Spades: onPlay - " + card); + return this.send(".play " + card); + } + + public boolean onTurn() + { + Os.debug("Spades: onTurn"); + return this.send(".turn"); + } + + /* Helper functions */ + private boolean send(String msg) + { + if (this.task == null) + return false; + this.task.send(msg); + return true; + } +} -- 2.43.2