-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServingConveyor.java
More file actions
126 lines (111 loc) · 4.76 KB
/
ServingConveyor.java
File metadata and controls
126 lines (111 loc) · 4.76 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList; //imports array lists
/**
* Takes different soups and completes orders based off of the order list
* which then gives the player coins in return for their success.
* Credit to Mario for the coins sound effect
*
* @author Isaac Chan
* @version January 28, 2022
*/
public class ServingConveyor extends Counter
{
//finds the array list
ArrayList<Order> orderList;
//variable used to calculate the number of coins earned
private static int currVal;
public void act()
{
serveFood();
}
public void serveFood() //when soup is place on the serving conveyor
{
if(isTouching(Plate.class)){ //if this is touching a plate
//finds the specific plate that this object interacts with
Actor findPlate = getOneIntersectingObject(Plate.class);
Plate foundPlate = (Plate)findPlate;
//finds the plate station that this object interacts with
Actor findPlateStation = getObjectsInRange(GameWorld.getGrid() * 2, PlateStation.class).get(0);
PlateStation foundPlateStation = (PlateStation)findPlateStation;
//grabs the order list from the game world
orderList = ((GameWorld)getWorld()).getOrderList();
if(foundPlate.getOnionSoup() && onionExists()){ //if onion soup matches the order
//return one plate back to the plate station
foundPlateStation.setPlates(1);
removeTouching(Plate.class);
//earn coins
coinsEarned();
} else if(foundPlate.getTomatoSoup() && tomatoExists()){ //if tomato soup matches the order
//return one plate back to the plate station
foundPlateStation.setPlates(1);
removeTouching(Plate.class);
//earn coins
coinsEarned();
}
}
}
public boolean onionExists() //checks if the onion order exists
{
for(int i = 0; i < 3; i++){
//searches for an order that has onino soup
Order oldOrder = orderList.get(i);
//prepares a new order to replace the old one
Order newOrder = new Order();
int orderX = orderList.get(i).getX();
int orderY = orderList.get(i).getY();
if(orderList.get(i).getOnionOrder()){ //if the order list contains onion soup
//stores the current value of the stat bar
currVal = oldOrder.getCurrVal();
//replaces the order in the list
orderList.remove(i);
orderList.add(newOrder);
((GameWorld)getWorld()).removeObject(oldOrder);
((GameWorld)getWorld()).addObject(newOrder, orderX, orderY);
return true;
}
}
return false;
}
public boolean tomatoExists() //checks if the tomato order exists
{
for(int i = 0; i < 3; i++){
//searches for an order that has onino soup
Order oldOrder = orderList.get(i);
//prepares a new order to replace the old one
Order newOrder = new Order();
int orderX = orderList.get(i).getX();
int orderY = orderList.get(i).getY();
if(orderList.get(i).getTomatoOrder()){ //if the order list contains tomato soup
//stores the current value of the stat bar
currVal = oldOrder.getCurrVal();
//replaces the order in the list
orderList.remove(i);
orderList.add(newOrder);
((GameWorld)getWorld()).removeObject(oldOrder);
((GameWorld)getWorld()).addObject(newOrder, orderX, orderY);
return true;
}
}
return false;
}
public void coinsEarned() //determines the number of coins earned
{
//finds the coins object
Coins coins = ((GameWorld)getWorld()).getObjects(Coins.class).get(0);
//makes a sound when coins are earned
GreenfootSound sound = new GreenfootSound("MarioCoinSound.wav");
sound.setVolume(80);
sound.play();
//creates a multiplier for the points based on the current value of the stat bar
int multiplier;
if(currVal > 3250){
multiplier = 2;
} else {
multiplier = 1;
}
//calculates the coins earned
int coinsEarned = currVal * multiplier/ 100 + 150;
//adds the coins earned to the coins object
coins.earnCoins(coinsEarned);
}
}