view src/alice/test/topology/movement/checkLocation.java @ 88:33a19ca88e43 working

Singleton is removed .
author sugi
date Mon, 04 Jun 2012 16:08:53 +0900
parents src/alice/test/topology/movement/SendLocation.java@899b2b78ac75
children e269cedd8bae
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 checkLocation extends CodeSegment{
	
	public Receiver nowX = ids.create(CommandType.PEEK);
	public Receiver host = ids.create(CommandType.PEEK);
	public MakeFrame frame;
	public MakeObject obj;
	Pattern pattern = Pattern.compile("^(cli)([0-9]+)$");
	
	public checkLocation(MakeFrame MF , MakeObject MO){
		this.frame = MF;
		this.obj = MO;
	}
	
	@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;
		float x = (float)this.nowX.asInteger()/1000;
		System.out.println("now position is :" + x);
		if (startX < x && x < endX){
			obj.setLocation(x - 2*(num-1), 0);
			ods.update("parent", "fish1X", this.nowX.asInteger()+1);
			
		} else if(startX == x){
			this.obj = new MakeObject(frame.getCanvas());
			frame.register(obj.createBranch());
			ods.update("parent", "fish1X", this.nowX.asInteger()+1);
			
		} else if(endX == x){
			System.out.println("out of range");
		}
		
		
		checkLocation cs = new checkLocation(this.frame,this.obj);
		cs.host.setKey("local","host");
		cs.nowX.setKey("parent","fish1X",this.nowX.index);
	
		
		
		
				
	}
	

}