summaryrefslogtreecommitdiff
path: root/engine/Action.java
diff options
context:
space:
mode:
Diffstat (limited to 'engine/Action.java')
-rw-r--r--engine/Action.java83
1 files changed, 77 insertions, 6 deletions
diff --git a/engine/Action.java b/engine/Action.java
index 3009fa0..3f2f365 100644
--- a/engine/Action.java
+++ b/engine/Action.java
@@ -1,29 +1,38 @@
package mahjong.engine;
+import java.util.Random;
+
/**
* Created by joe on 12/3/14.
+ * Action handles information passing between server and clients
*/
public class Action {
// TODO Generic action
// Requirement: printable,parseable,coverage
// Coverage: System,player
- public enum Type {System,Player};
+ private static Random idGen = new Random();
+ private static int cnter = 0;
+ public enum Type {System,Player}
// System info merely reflect system state
// Player info pertaining to players;
- public enum Place {Info,East,South,West,North};
- public enum Act {Info,CardDraw,CardPut,Aside};
+ public enum Place {Info,East,South,West,North}
+ public enum Act {Info,Draw,Put,Meld}
Type type;
Act act;
Place place;
String message;
+ int guid;
- public Type getType() {
- return type;
+ public void newGUID()
+ {
+ this.guid=(idGen.nextInt()&0xFFF000)+cnter;
+ cnter = (cnter+1)&0xFFF;
}
public Action(Type type,Place place,Act act,String message)
{
+ newGUID();
this.type = type;
this.place = place;
this.act = act;
@@ -31,10 +40,72 @@ public class Action {
}
public Action(String str)
{
+ String[] res=str.trim().split("\t");
+ guid = Integer.parseInt(res[0]);
+ switch (res[1].trim().toUpperCase().charAt(0))
+ {
+ case 'S':
+ type=Type.System;
+ break;
+ case 'P':
+ type=Type.Player;
+ }
+ switch (res[2].trim().toUpperCase().charAt(0))
+ {
+ case 'I':
+ place=Place.Info;
+ break;
+ case 'E':
+ place=Place.East;
+ break;
+ case 'S':
+ place=Place.South;
+ break;
+ case 'W':
+ place=Place.West;
+ break;
+ case 'N':
+ place=Place.North;
+ }
+ switch (res[3].trim().toUpperCase().charAt(0))
+ {
+ case 'I':
+ act=Act.Info;
+ break;
+ case 'D':
+ act=Act.Draw;
+ break;
+ case 'P':
+ act=Act.Put;
+ break;
+ case 'M':
+ act=Act.Meld;
+ }
+ message=res[4];
}
@Override
public String toString() {
- return super.toString();
+ return String.format("%d\t%c\t%c\t%c\t%s",guid,type.toString().charAt(0),place.toString().charAt(0),act.toString().charAt(0),message);
+ }
+
+ public Act getAct() {
+ return act;
+ }
+
+ public Place getPlace() {
+ return place;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public int getGuid() {
+ return guid;
+ }
+
+ public Type getType() {
+ return type;
}
}