]> Pileus Git - ~andy/spades/commitdiff
Add Spades class and tie things together
authorAndy Spencer <andy753421@gmail.com>
Mon, 22 Apr 2013 02:10:24 +0000 (02:10 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 22 Apr 2013 02:10:24 +0000 (02:10 +0000)
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
src/org/pileus/spades/Main.java
src/org/pileus/spades/Spades.java [new file with mode: 0644]

index 9085a8f94c679347de34a1dca201f776975c04d5..e4c566e1afc4c5c60859de63c71821ee345f6894 100644 (file)
@@ -124,6 +124,7 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer
        private Map<String,Integer> 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");
index 502d5ae9b735e8da076d26461fe84be0c66cc0fd..56691e403306cd11426593676d7deae4468996f8 100644 (file)
@@ -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 (file)
index 0000000..a9fd150
--- /dev/null
@@ -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;
+       }
+}