this.ylim = 0.4f;
- this.hand = new String[] {
- "As", "7s", "6s", "6h", "2h", "Ac",
- "Kc", "3c", "10d", "9d", "8d", "7d", "2d"
- };
-
- this.pile = new String[] {
- "As", "7s", "6s"
- };
+ this.hand = "As Ks Qs Js 10s 9s 8s 7s 6s 5s 4s 3s 2s".split(" ");
+ this.pile = "Ah Ac Ad".split(" ");
this.index = new HashMap<String,Integer>(52);
for (int i = 0; i < 52; i++)
.setContent(R.id.debug));
// Setup Spades game and cards view
- this.game = new Spades();
+ this.game = new Spades("rhawk");
this.cards = new Cards(this);
this.game.cards = this.cards;
this.cards.game = this.game;
this.spades.addView(cards);
-
+
// Attach to background service
this.register();
public String to = "";
public String txt = "";
+ /* Static methods */
+ public static String clean(String msg)
+ {
+ String num = "0?[0-9]|1[0-5]";
+ return msg.replaceAll("[\\002\\011\\017\\025]", "")
+ .replaceAll("[\\003\\013]("+num+")(,"+num+")?", "");
+ }
+
/* Private methods */
private String notnull(String string)
{
public class Spades
{
- /* Private data */
- public Task task;
- public Cards cards;
+ /* Properties */
+ public Task task;
+ public Cards cards;
+ public String admin;
+
+ /* Static methods */
+ private static String[] getCards(String msg, String regex)
+ {
+ String cards = Message.clean(msg)
+ .replaceAll(regex, "$1")
+ .replaceAll(",", " ")
+ .replaceAll("♠", "s")
+ .replaceAll("♥", "h")
+ .replaceAll("♦", "d")
+ .replaceAll("♣", "c");
+ Os.debug("Cards: getCards - [" + cards + "]:" + Os.base64(cards));
+ return cards.split("\\s+");
+ }
/* Widget callback functions */
- public Spades()
+ public Spades(String admin)
{
+ this.admin = admin;
}
/* IRC Callbacks */
public void onMessage(Message msg)
{
- Os.debug("Spades: onMessage");
+ Os.debug("Spades: onMessage - " + msg.msg);
+ if (msg.type != Message.Type.PRIVMSG)
+ return;
+ if (!msg.from.equals(this.admin))
+ return;
+
+ String txt = msg.txt;
+ if (txt.startsWith("You have: ")) {
+ this.cards.hand = Spades.getCards(txt, "You have: (.*)");
+ this.cards.requestRender();
+ }
+ if (txt.matches("turn!")) {
+ this.cards.pile = Spades.getCards(txt, ".*turn! (.*)");
+ this.cards.requestRender();
+ }
}
/* UI Callbacks */