1 package org.pileus.spades;
11 private static String[] getCards(String msg, String regex)
13 String cards = Message.clean(msg)
14 .replaceAll(regex, "$1")
19 .replaceAll("♣", "c");
20 Os.debug("Cards: getCards - [" + cards + "]:" + Os.base64(cards));
21 return cards.split("\\s+");
24 /* Widget callback functions */
25 public Spades(String admin)
31 public void onMessage(Message msg)
33 Os.debug("Spades: onMessage - " + msg.msg);
34 if (msg.type != Message.Type.PRIVMSG)
36 if (!msg.from.equals(this.admin))
40 if (txt.startsWith("You have: ")) {
41 this.cards.hand = Spades.getCards(txt, "You have: (.*)");
42 this.cards.requestRender();
44 if (txt.matches("turn!")) {
45 this.cards.pile = Spades.getCards(txt, ".*turn! (.*)");
46 this.cards.requestRender();
51 public boolean onBid(int bid)
53 Os.debug("Spades: onBid - " + bid);
54 return this.send(".bid " + bid);
57 public boolean onPass(String card)
59 Os.debug("Spades: onPass - " + card);
60 return this.send(".pass " + card);
63 public boolean onLook()
65 Os.debug("Spades: onLook");
66 return this.send(".look");
69 public boolean onPlay(String card)
71 Os.debug("Spades: onPlay - " + card);
72 return this.send(".play " + card);
75 public boolean onTurn()
77 Os.debug("Spades: onTurn");
78 return this.send(".turn");
81 /* Helper functions */
82 private boolean send(String msg)
84 if (this.task == null)