view src/alice/test/topology/movement/CheckFishLocation.java @ 97:df786bf8f036 working

add FishPoint.java and Test
author sugi
date Tue, 26 Jun 2012 16:48:09 +0900
parents 38f4021353c5
children 993a9f194615
line wrap: on
line source

package alice.test.topology.movement;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;


public class CheckFishLocation extends CodeSegment{
	
	private Receiver position = ids.create(CommandType.PEEK);
	private Receiver host = ids.create(CommandType.PEEK);
	MakeObject obj;
	Pattern pattern = Pattern.compile("^(cli)([0-9]+)$");
	
	public CheckFishLocation(MakeObject MO ,String str){
		this.obj = MO;
		this.position.key = str;
		this.host.setKey("local","host");
		this.position.setKey("parent",this.position.key,this.position.index);
	}
	
	@Override
	public void run(){
		String name = host.asString();
		Matcher matcher = pattern.matcher(name);
		matcher.find();
		int num = new Integer(matcher.group(2));
		
		float startX = 2*num - 3.0f;
		float endX = 2*num -0.9f;
		FishPoint FP = this.position.asClass(FishPoint.class);
		System.out.println(this.position.key+" :" + FP.getX());
		
		if (startX <= FP.getX() && FP.getX() < endX){
			obj.setLocation(FP.getX() - 2*(num-1), FP.getY());
			//if(this.position.key!="fish3X")
				//ods.update("parent", this.position.key, this.position.asInteger()+1);
		}
				
		new CheckFishLocation(this.obj,this.position.key);

		
						
	}
	

}