-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShop.java
More file actions
35 lines (30 loc) · 1.05 KB
/
Copy pathShop.java
File metadata and controls
35 lines (30 loc) · 1.05 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
import java.util.ArrayList;
public class Shop {
ArrayList<Item> itemList = new ArrayList<Item>();
public Item createItem(String name, Double price) {
Item thisItem = new Item();
thisItem.item(name, price);
return thisItem;
}
public void shop() {
itemList.add(createItem("Candy", 2.0));
itemList.add(createItem("Sword", 90.0));
itemList.add(createItem("5.0 CAP", 9000.0));
}
public void buyItem(Player player, int itemIndex) {
if (player.Money >= itemList.get(itemIndex).price) {
player.Money -= itemList.get(itemIndex).price;
player.inventory.add(itemList.get(itemIndex));
System.out.println("You just bought a " + itemList.get(itemIndex).name);
} else {
System.out.println("Not enough money");
}
}
public void printItemList() {
int index = 0;
for (Item item : itemList) {
System.out.println(index + ": " + item.name + ". Item price is " + item.price);
index += 1;
}
}
}