Newer
Older
hanabi-networking / src / card / CardInfo.java
package card;

import server.Move;

import server.InternalHanabiError;
import server.Message;

public class CardInfo {
	private int type;
	private boolean is;
	private int what;
	private int from;

	public CardInfo(int type, boolean is, int what, int from) {
		this.type = type;
		this.is = is;
		this.what = what;
		this.from = from;
	}
	
	public CardInfo(Message msg, Card c, int from) {
		Move m = msg.getMove();
		if(m.getMoveType() != Move.HINT) throw new InternalHanabiError("Card info of non-hint move requested.");
		type = m.getHintType();
		if(type == Move.HINT_COLOR) {
			what = m.getColor();
			is = c.getColorInt() == what;
		} else {
			what = m.getValue();
			is = c.getValue() == what;
		}
		this.from = from;
	}
	
//	public JSONObject toJson() throws JSONException {
//		JSONObject root = new JSONObject();
//		root.put("type", type);
//		root.put("is", is);
//		root.put("what", what);
//		root.put("from", from);
//		return root;
//	}
	
//	private void fromJson(JSONObject jo) throws JSONException {
//		type = jo.getInt("type");
//		is = jo.getBoolean("is");
//		what = jo.getInt("what");
//		from = jo.getInt("from");
//	}

	public int getType() { return type; }
	public boolean isIs() { return is; }
	public int getWhat() { return what; }
	public int getFrom() { return from; }
}