-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIceCreamLine.java
More file actions
87 lines (78 loc) · 1.71 KB
/
IceCreamLine.java
File metadata and controls
87 lines (78 loc) · 1.71 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
import javax.swing.Box;
import javax.swing.BoxLayout;
/**
* This class maintains a queue of ice cream cone orders
*
* @author Ching2 Huang
*
*/
public class IceCreamLine extends Box {
// order is the queue list to store the data
private QueueLL<IceCreamCone> order;
/**
* constructor initializes the order and use BoxLayOut
*/
public IceCreamLine() {
// use boxLayout vertically
super(BoxLayout.Y_AXIS);
// setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
order = new QueueLL<IceCreamCone>();
}
/**
* add a random cone
*/
public void addCone() {
// every time the method is called, create a new cone
IceCreamCone aCone = new IceCreamCone();
// randomize the scoops and flavor
aCone.randomCone();
// add the cone to the panel
add(aCone);
// add the data to the queue list
order.enqueue(aCone);
// added a component
revalidate();
// repaint now that it's changed
repaint();
}
/**
* remove a cone from the queue list
*/
public void removeCone() {
// if the order exists, remove it from the order
if (order.peek() != null) {
order.dequeue();
// remove the first component
remove(0);
}
}
/**
* see the first order
*
* @return the first order's ice cream
*/
public IceCreamCone iceCream() {
return order.peek();
}
/**
* check whether there's order
*
* @return true when the queue is empty
*/
public boolean emptyLine() {
return order.isEmpty();
}
/**
* check if there are four orders then
* @return true when there are 4 orders
*/
public boolean gameOver() {
//check the size of the list
if(order.getSize() == 4){
//when there are four orders, end the game
return true;
}
//otherwise, keep playing
return false;
}
}