view src/alice/test/topology/movement/CheckFishLocation.java @ 105:993a9f194615 working

success share TEST
author sugi
date Tue, 03 Jul 2012 15:58:08 +0900
parents df786bf8f036
children
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;
	String key;
	Pattern pattern = Pattern.compile("^(cli)([0-9]+)$");
	
	public CheckFishLocation(MakeObject MO ,String key,int index){
		this.obj = MO;
		this.key = key;
		this.host.setKey("local","host");
		this.position.setKey("local",key,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);
		obj.setLocation(FP.getX(), FP.getY());
		/*
		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.key,this.position.index);

		
						
	}
	

}