-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShop.java
More file actions
69 lines (64 loc) · 1.61 KB
/
Shop.java
File metadata and controls
69 lines (64 loc) · 1.61 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
import java.util.*;
/**
*@author Tyler Lericos
*@version 1.0
*Interfaces
*Spring Semester/Freshman
*/
public class Shop extends Village {
char charChoice;
String shopName;
ArrayList<Item> items = new ArrayList<Item>();
/*
* Parameterized Constructor
*/
public Shop(String shopName, ArrayList<Item> items) {
super();
this.shopName = shopName;
this.items = items;
}
/*
* Getter
*/
public String getShopName() {
return shopName;
}
/*
* Setter
*/
public void setShopName(String shopName) {
this.shopName = shopName;
}
/*
* Getter for items uses a for loop to display items in shop
*/
public void getItems() {
for (int i = 0; i< items.size(); i++) {
System.out.println(items.get(i).name);
}
}
/*
* Holds a generic type for item as a parameter
*/
public void setItems(ArrayList<Item> items) {
this.items = items;
}
/*
* Buy items method that will add one of the shops items to your inventory and take your player's gold
*/
public void BuyItems(Player player, Scanner scan) {
System.out.println("What would you like to purchase?\n");
for (int i = 0; i<items.size(); i++) {
System.out.println(i + ". " + items.get(i).name + " Cost: " + items.get(i).cost + " gold");
}
int intchoice = scan.nextInt();
if (player.gold <=0) {
System.out.println("You do not have enough gold!");
}
else if(player.gold > 0) {
player.inventory.add(items.get(intchoice));
player.gold = player.gold - items.get(intchoice).cost;
System.out.println(items.get(intchoice).name + " was added to inventory");
}
}
}