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
}
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");
private String topic;
private String names;
private Cards cards;
+ private Spades game;
/* Widgets */
private TabHost window;
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))
switch (msg.type) {
case PRIVMSG:
this.display(msg);
+ this.game.onMessage(msg);
break;
case TOPIC:
if (!msg.txt.equals(this.topic))
.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
--- /dev/null
+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;
+ }
+}