]> Pileus Git - ~andy/spades/commitdiff
Setup game automatically
authorAndy Spencer <andy753421@gmail.com>
Fri, 6 Nov 2015 22:44:26 +0000 (22:44 +0000)
committerAndy Spencer <andy753421@gmail.com>
Fri, 6 Nov 2015 22:49:11 +0000 (22:49 +0000)
src/Client.java
src/Main.java
src/Spades.java
src/Task.java

index b56decd472f91c29c4b8b305750c9007933153e1..dc7c2dbba04c4106e442191107e03f7de9f1a1f0 100644 (file)
@@ -116,19 +116,24 @@ public class Client
                }
        }
 
-       public Message send(String txt)
+       public Message send(String dst, String txt)
        {
                if (txt == null || txt.length() == 0)
                        return null;
                if (this.validate() != State.READY)
                        return null;
-               Message msg = new Message(this.channel, this.name, txt);
+               Message msg = new Message(dst, this.name, txt);
                if (msg.type == Message.Type.JOIN)
                        this.channel = msg.msg;
                this.raw(msg.line);
                return msg;
        }
 
+       public Message send(String txt)
+       {
+               return this.send(this.channel, txt);
+       }
+
        public Message recv()
        {
                while (true) try {
index 231fee0e16994447bbf9a21258c3e6bdf2850ac5..0b29dbad516662d39776170ef7b9409865c8786d 100644 (file)
@@ -423,6 +423,7 @@ public class Main extends Activity
                                        break;
                                case Task.CONNECT:
                                        Main.this.update(true);
+                                       Main.this.game.onConnect();
                                        break;
                                case Task.DISCONNECT:
                                        Main.this.update(false);
index 17eacfaa99259d8073d799e1a613d831751ebc82..31878442460291f6564af9b8164b72e94dc39ec0 100644 (file)
@@ -6,6 +6,7 @@ public class Spades
        public  Task    task;
        public  Cards   cards;
        public  String  admin;
+       public  boolean looked;
 
        /* Static methods */
        private static String[] getCards(String msg, String regex)
@@ -37,6 +38,10 @@ public class Spades
                        return;
 
                String txt = msg.txt;
+               if (txt.matches(".*turn!.*") && !this.looked) {
+                       this.send(this.admin, ".look");
+                       this.looked = true;
+               }
                if (txt.startsWith("You have: ")) {
                        this.cards.hand = Spades.getCards(txt, "You have: (.*)");
                        this.cards.requestRender();
@@ -48,6 +53,15 @@ public class Spades
        }
 
        /* UI Callbacks */
+       public boolean onConnect()
+       {
+               Os.debug("Spades: onConnect");
+               this.looked = false;
+               this.send(this.admin, ".status");
+               this.send(this.admin, ".turn");
+               return true;
+       }
+
        public boolean onBid(int bid)
        {
                Os.debug("Spades: onBid - " + bid);
@@ -57,7 +71,7 @@ public class Spades
        public boolean onPass(String card)
        {
                Os.debug("Spades: onPass - " + card);
-               return this.send(".pass " + card);
+               return this.send(this.admin, ".pass " + card);
        }
 
        public boolean onLook()
@@ -79,6 +93,13 @@ public class Spades
        }
 
        /* Helper functions */
+       private boolean send(String dst, String msg)
+       {
+               if (this.task == null)
+                       return false;
+               this.task.send(dst, msg);
+               return true;
+       }
        private boolean send(String msg)
        {
                if (this.task == null)
index 97fe9b9311d2ee777f53b38323025f20fd05bd3b..26e0bd872343b7ce1a09c78755970ff5920d9ca6 100644 (file)
@@ -100,6 +100,16 @@ public class Task extends Service implements Runnable
        }
 
        /* Public methods */
+       public Message send(String dst, String txt)
+       {
+               if (this.client == null)
+                       return null;
+               Message msg = this.client.send(dst, txt);
+               if (msg != null)
+                       this.command(MESSAGE, msg);
+               return msg;
+       }
+
        public Message send(String txt)
        {
                if (this.client == null)