view src/alice/test/topology/aquarium/fx/PositionController.java @ 7:75f7a75bec83

use only ImageView
author e095732
date Mon, 28 Jan 2013 16:59:39 +0900
parents ae0a39622a58
children e027d228c455
line wrap: on
line source

package alice.test.topology.aquarium.fx;

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

public class PositionController extends CodeSegment{
	
	private Receiver data = ids.create(CommandType.PEEK);
	double max = 600;
	
	public PositionController(String key){
		this.data.setKey(key);
	}
	
	public PositionController(String key ,int index){
		this.data.setKey(key, index);
	}

	@Override
	public void run() {
		//System.out.println(data.val);
		synchronized(this){
			try {
				// TODO
				// Waiting should be done in Alice kernel
				// ids.create(CommandType.WAIT);
			 
				wait(20);
		
		FishData fd = data.asClass(FishData.class);
		if(fd.getX()+2.0>max){
			System.out.println("over "+this.data.key);
			fd.SetXYZ(50, fd.getY(), fd.getZ());
			
		} else {
			
			fd.SetXYZ(fd.getX()+3.0, fd.getY(), fd.getZ());
		}

		new PositionController(data.key, data.index);
		ods.update("local", data.key, fd);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

}