1 package org.pileus.spades;
12 private static String[] getCards(String msg, String regex)
15 .replaceAll(regex, "$1")
20 .replaceAll("♣", "c");
21 Os.debug("Cards: getCards - [" + cards + "]:" + Os.base64(cards));
22 return cards.split("\\s+");
25 /* Widget callback functions */
26 public Spades(String admin)
32 public void onMessage(Message msg)
34 Os.debug("Spades: onMessage - " + msg.msg);
35 if (msg.type != Message.Type.PRIVMSG)
37 if (!msg.from.equals(this.admin))
41 if (txt.matches(".*turn!.*") && !this.looked) {
42 this.send(this.admin, ".look");
45 if (txt.startsWith("You have: ")) {
46 this.cards.hand = Spades.getCards(txt, "You have: (.*)");
47 this.cards.requestRender();
49 if (txt.matches(".*turn!.*")) {
50 this.cards.pile = Spades.getCards(txt, ".*turn! \\((.*)\\)");
51 this.cards.requestRender();
56 public boolean onConnect()
58 Os.debug("Spades: onConnect");
60 this.send(this.admin, ".status");
61 this.send(this.admin, ".turn");
65 public boolean onBid(int bid)
67 Os.debug("Spades: onBid - " + bid);
68 return this.send(".bid " + bid);
71 public boolean onPass(String card)
73 Os.debug("Spades: onPass - " + card);
74 return this.send(this.admin, ".pass " + card);
77 public boolean onLook()
79 Os.debug("Spades: onLook");
80 return this.send(".look");
83 public boolean onPlay(String card)
85 Os.debug("Spades: onPlay - " + card);
86 return this.send(".play " + card);
89 public boolean onTurn()
91 Os.debug("Spades: onTurn");
92 return this.send(".turn");
95 /* Helper functions */
96 private boolean send(String dst, String msg)
98 if (this.task == null)
100 this.task.send(dst, msg);
103 private boolean send(String msg)
105 if (this.task == null)