package cdc;
import java.awt.Point;
import java.util.Map;
import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import entity.Item;
import entity.ItemInfo;
import entity.Player;
import entity.PlayerInfo;
import entity.Monster;
import entity.Projector;
import tcp.codes;
public class CDC
{
	final static int MaxPlayerno=4;
	private static Point playerinitlocation[];
	private Map<Integer,Player> player;
	private Map<Integer,Item> item;
	private Map<Integer,Monster> monster;
	private Map<Integer,Projector> projector;
	private int itemid=0;
	private int monsterid=0;
	private int projectorid=0;
	public static CDC uniqueinstance;
	private CDC()
	{
		player=new ConcurrentHashMap<>();
		item=new ConcurrentHashMap<>();
		monster=new ConcurrentHashMap<>();
		projector=new ConcurrentHashMap<>();
	}
	public static synchronized CDC getInstance()
	{
		if(uniqueinstance==null)
		{
			uniqueinstance=new CDC();
		}
		return uniqueinstance;
	}
	public Map getPlayer(){return player;}
	public Map getItem(){return item;}
	public Map getMonster(){return monster;}
	public Map getProjector(){return projector;}
	public void keyDown(int clientno,int action)
	{
		assert player.get(clientno)!=null:"The clientno is invalid";
		if(action==codes.ATTACK)
			player.get(clientno).playerAttack();
		else
			player.get(clientno).playerMove(action);
	}
	public void keyRelease(int clientno,int action)
	{
		assert player.get(clientno)!=null:"The clientno is invalid";
		if(action==codes.ATTACK)
			player.get(clientno).attackingEnd();
		else
			player.get(clientno).movingEnd();
	}
	public int getMonsterNewId()
	{
		int tmp=monsterid;
		monsterid+=1;
		return tmp;
	}
	public int getItemNewId()
	{
		int tmp=itemid;
		itemid+=1;
		return tmp;
	}
	public int getProjectorId()
	{
		int tmp=projectorid;
		projectorid+=1;
		return tmp;
	}
	public void addPlayer(int clientno,int type)
	{
		assert clientno>=0&&clientno<4:"The clientno is invalid";
		player.put(clientno,new Player(type,playerinitlocation[clientno],PlayerInfo.getInstance().getTypeInfo(type)));
	}
	public void addItem(Point point,int type)
	{
		Item tmp=new Item(point,type,ItemInfo.getInstance().getTypeInfo(type));
		item.putIfAbsent(itemid,tmp);
		itemid+=1;
	}
	public Vector getUpdatInfo()
	{
		Vector<String> v=new Vector<String>();
		int cnt=0;
		for(Map.Entry<Integer,Player> entry:player.entrySet())
		{
			String str="";
			str=entry.toString();
			v.add(cnt,str);
			cnt+=1;
		}
		for(Map.Entry<Integer,Monster> entry:monster.entrySet())
		{
			String str;
			str=entry.toString();
			v.add(cnt,str);
			cnt+=1;
		}
		for(Map.Entry<Integer,Item> entry:item.entrySet())
		{
			String str;
			str=entry.toString();
			v.add(cnt,str);
			cnt+=1;
		}
		return v;
	}
	/*public static void main(String[] args)
	{
		
	}*/
}

@@ -870,24 +870,245 @@
 ashMap%3C%3E();%0A
+%09%09playerinitlocation=new Point%5BMaxPlayerno%5D;%0A%09%09playerinitlocation%5B0%5D=new Point(100,100);%0A%09%09playerinitlocation%5B1%5D=new Point(1000,1000);%0A%09%09playerinitlocation%5B2%5D=new Point(0,1000);%0A%09%09playerinitlocation%5B3%5D=new Point(1000,0);%0A
 %09%7D%0A%09public s
@@ -3026,10 +3026,8 @@
 %09%7D%0A%09
-/*
 publ
@@ -3070,12 +3070,150 @@
 %7B%0A%09%09
+CDC cdc;%0A%09%09cdc=CDC.getInstance();%0A%09%09CDC.getInstance().addPlayer(1,0);%0A%09%09System.out.println(CDC.getInstance().getPlayer().get(1).toString());
 %0A%09%7D
-*/
 %0A%7D%0A

Add case to CDC.java to test