-
Notifications
You must be signed in to change notification settings - Fork 1
/
RubbishMaster.java
124 lines (104 loc) · 2.86 KB
/
RubbishMaster.java
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.net.*;
public class RubbishMaster
{
private Rubbish rubbishErik;
private Rubbish rubbishHolding;
private Rubbish rubbishIan1;
private Rubbish rubbishIan2;
private Rubbish rubbishIdle1;
private Rubbish rubbishIdle2;
private Rubbish rubbishIdle3;
RubbishMaster( Rubbish obj1, Rubbish obj2, Rubbish obj3 )
{
rubbishErik = null;
rubbishIan1 = null;
rubbishIan2 = null;
rubbishIdle1 = obj1;
rubbishIdle2 = obj2;
rubbishIdle3 = obj2;
}
public void newErik()
{
if ( rubbishIdle1 == null )
throw new Error("Run out of Rubbish objects");
if ( rubbishErik != null )
return;
//throw new Error("Already rubbishErik element");
rubbishErik = rubbishIdle1;
rubbishIdle1 = rubbishIdle2;
rubbishIdle2 = rubbishIdle3;
rubbishIdle3 = null;
}
public void newHolding()
{
if ( rubbishHolding != null )
throw new Error("Holding already has a rubbish");
if ( rubbishErik == null )
throw new Error("Nothing to move to holdingRubbish");
rubbishHolding = rubbishErik;
rubbishErik = null;
}
public void newIan()
{
if ( rubbishHolding == null )
throw new Error("Nothing to move to holdingRubbish");
if ( rubbishIan1 == null )
{
rubbishHolding.setMasterIndex(1);
rubbishIan1 = rubbishHolding;
}
else if ( rubbishIan2 == null )
{
rubbishHolding.setMasterIndex(2);
rubbishIan2 = rubbishHolding;
}
else
{
// This can happen occationly - just deal with
throw new Error("Ian Already has a rubbish");
}
rubbishHolding = null;
}
public void removeErik()
{
addToIdle( rubbishErik );
rubbishErik.setSize(0,0);
rubbishErik = null;
rubbishHolding.setImageSize();
rubbishHolding.makeTheMove();
}
public void removeIan( int index )
{
if ( index == 1 )
{
addToIdle( rubbishIan1 );
rubbishIan1.setSize( 0, 0 );
rubbishIan1 = null;
}
else
{
addToIdle( rubbishIan2 );
rubbishIan2.setSize( 0, 0 );
rubbishIan2 = null;
}
}
private void addToIdle( Rubbish newIdle )
{
if ( rubbishIdle1 == null )
rubbishIdle1 = newIdle;
else if ( rubbishIdle2 == null )
rubbishIdle2 = newIdle;
else if ( rubbishIdle3 == null )
rubbishIdle3 = newIdle;
else
throw new Error("No space to put new idle in");
}
public Rubbish getErik()
{
return rubbishErik;
}
public Rubbish getHolding()
{
return rubbishHolding;
}
}