import java.io.*; import java.net.*; public class User implements Runnable{ PrintWriter pw; BufferedReader br; String username; Work worker; Socket sc; String linepart=""; double x, y, angle, step, dangle; public User(Socket sc, Work worker){ this.sc=sc; this.worker=worker; x=Start.AREA_WIDTH*Math.random(); y=Start.AREA_HEIGHT*Math.random(); angle=6.28*Math.random(); step=5; dangle=0.1; new Thread(this).start(); } public void run(){ try{ pw=new PrintWriter(sc.getOutputStream(), true); br=new BufferedReader(new InputStreamReader(sc.getInputStream())); pw.println("Your name, please: "); username=br.readLine(); worker.add(this); } catch(Exception ex){ex.printStackTrace();} } public String toString(){ return username+","+(int)x+","+(int)y+","+(int)Math.toDegrees(angle); } public void front(){ System.out.println("execute front"); x+=step*Math.cos(angle); y+=step*Math.sin(angle); } public void right(){ angle+=dangle; } public void execute(String command){ command=command.trim(); //delete \r from input if(command.equals("f")){front();} if(command.equals("r")){right();} } }