-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMoveThread.java
More file actions
105 lines (95 loc) · 3.4 KB
/
MoveThread.java
File metadata and controls
105 lines (95 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.logging.Level;
import java.util.logging.Logger;
import java.net.*;
public class MoveThread extends Thread
{
private MovementDetails details;
private Movable object;
private int curX;
private int curY;
private int curSpeed;
private Boolean pageBagging = false;
MoveThread( Movable object )
{
this.details = details;
this.object = object;
}
public void addDetails( MovementDetails details )
{
this.details = details;
}
public void run()
{
updateCurs();
if ( !object.getStopForCleaner() )
move();
return;
}
private void updateCurs()
{
curX = details.getCurX();
curY = details.getCurY();
curSpeed = details.getCurSpeed();
}
private void move()
{
while ( object.isMoving() )
{
if ( object.updateMove(curX, curY, curSpeed, details) )
{
if ( details.isMore() )
{
details.nextIndex();
if ( details.getCurType().equals(MovementType.MoveToTarget) )
updateCurs();
else if ( details.getCurType() == MovementType.Pause )
pause( details.getCurPause() );
else if ( details.getCurType() == MovementType.EveryoneStop )
details.everyoneStop();
else if (details.getCurType() == MovementType.ThrowRubbish)
details.runThrowRubbish();
else if ( details.getCurType() == MovementType.RubbishAtIan )
{
if ( ( object.getClass().getName() ).equals("Rubbish"))
details.rubbishAtIan();
else
throw new Error( "Object should be Rubbish but"
+ "isnt, it is "
+ object.getClass().getName() );
}
else if ( details.getCurType() == MovementType.RubbishAtBin )
details.rubbishAtBin();
else if ( details.getCurType() == MovementType.StartToBag )
{
pageBagging = true;
details.startToBag();
}
else if ( details.getCurType() == MovementType.ReturnWithoutBag )
{
pageBagging = true;
details.returnWithoutBag();
}
else if ( details.getCurType() == MovementType.PageSitDown )
details.pageSitDown();
else if ( details.getCurType() == MovementType.DisplayLoseScreen )
details.displayLoseScreen();
}else{
if ( !pageBagging )
object.setMoving( false );
if ( details.getFinalDir() != -1 )
object.finalDir( details.getFinalDir() );
return;
}
}
pause( 50 );
}
}
private void pause( int time )
{
try {
Thread.sleep(time);
} catch (InterruptedException ex) {
Logger.getLogger(Movable.class.getName()).log(Level.SEVERE, null, ex);
}
}
}