-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
113 lines (96 loc) · 2.4 KB
/
Player.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
import java.util.HashMap;
import java.util.Scanner;
import java.util.Collections;
/**
* Creates a new player upon starting the game.
*
* @author 162224
* @version 15/11
*
*/
public class Player
{
//The player variables are their name and inventory
public String playerName;
public HashMap<String, Item> inventory;
public HashMap<String, Creature> friends;
public HashMap<String, Creature> defeated;
public Player()
{
inventory = new HashMap<String, Item>();
friends = new HashMap<String, Creature>();
defeated = new HashMap<String, Creature>();
}
/**
* Retrieves an item from the inventory.
* @param Item string description
* @return Item object
*/
public Item getItem(String content)
{
return inventory.get(content);
}
/**
* Adds an item to the inventory.
*/
public void addItem(String content, Item item)
{
inventory.put(content, item);
}
/**
* Removes an item from the inventory.
*/
public void removeItem(String item)
{
inventory.remove(item);
}
/**
*Brings a companion with you on your journey.
*/
public void addCompanion(String friend, Creature companion)
{
friends.put(friend, companion);
}
/**
*Stores which bosses have been defeated.
*/
public void addBoss(String dead, Creature boss)
{
defeated.put(dead, boss);
}
/**
*Removes a companion from the players friends.
*/
public void removeCompanion(String friend)
{
friends.remove(friend);
}
/**
* Retrieves an item from the inventory.
* @param Creature string description
* @return Creature object
*/
public Creature getCompanion(String friend)
{
return friends.get(friend);
}
/**
* Prints a list of the items the player currently posseses.
*/
public void viewInventory()
{
for (Item item : inventory.values()){
String itemD = item.itemDesc;
System.out.println(itemD);
}
}
/**
* Prints a list of the companions the player currently posseses.
*/
public void viewCompanions()
{
for (Creature companion : friends.values()) {
System.out.println(companion.name);
}
}
}