-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryBasedScreen.java
More file actions
75 lines (50 loc) · 1.95 KB
/
InventoryBasedScreen.java
File metadata and controls
75 lines (50 loc) · 1.95 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
package roguelike.Inventory;
import asciiPanel.AsciiPanel;
import com.sun.glass.ui.Screen;
import roguelike.entities.Creature;
import java.util.ArrayList;
public abstract class InventoryBasedScreen {
protected Creature player;
private String letters;
protected abstract String getVerb();
protected abstract boolean isAcceptable(Item item);
protected abstract Screen use(Item item);
public InventoryBasedScreen(Creature player){
this.player = player;
this.letters = "abcdefghijklmnopqrstuvwxyz";
}
public void displayOutput(AsciiPanel terminal) {
ArrayList<String> lines = getList();
int y = 23 - lines.size();
int x = 4;
if (lines.size() > 0)
terminal.clear(' ', x, y, 20, lines.size());
for (String line : lines){
terminal.write(line, x, y++);
}
terminal.clear(' ', 0, 23, 80, 1);
terminal.write("What would you like to " + getVerb() + "?", 2, 23);
terminal.repaint();
}
private Inventory inventory = new Inventory(20);
public Inventory inventory() { return inventory; }
private ArrayList<String> getList() {
ArrayList<String> lines = new ArrayList<String>();
Item[] inventory = player.inventory().getItems();
for (int i = 0; i < inventory.length; i++){
Item item = inventory[i];
if (item == null || !isAcceptable(item))
continue;
String line = letters.charAt(i) + " - " + item.glyph() + " " + item.name();
lines.add(line);
}
return lines;
}
private Screen userExits(){
for (Item item : player.inventory().getItems()){
if (item != null && item.name().equals("teddy bear"))
return new WinScreen();
}
return new LoseScreen();
}
}