-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.java
More file actions
89 lines (80 loc) · 2.22 KB
/
Copy pathTile.java
File metadata and controls
89 lines (80 loc) · 2.22 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
public class Tile{
// colors for the terminal
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
public TileType tileType;
public Position position;
public Entity entity;
public Tile(TileType type, Position pos){
tileType = type;
position = pos;
entity = null;
}
public Tile(TileType type, Position pos, Entity ent){
tileType = type;
position = pos;
entity = ent;
}
// sets entity and updates the tileType to be equal with the entity
public void setEntity(Entity e){
entity = e;
if(e instanceof LivingBeing lb){
if(lb.name != null){
if(lb.name.equals("Player")) tileType = TileType.player;
if(lb.name.equals("Enemy")) tileType = TileType.enemy;
}
}else if(e instanceof Chest c){
if(c.isLocked) tileType = TileType.crate;
else{
tileType = TileType.key;
entity = c.content;
}
}else if(e instanceof Key){
tileType = TileType.key;
}else if(e instanceof Door d){
if(d.isLocked) tileType = TileType.lockedDoor;
else tileType = TileType.openDoor;
}else{
if(tileType != TileType.wall) tileType = TileType.empty;
}
}
// prints the tile and a blank space afterwards
public void printTile(){
setEntity(entity);
switch(tileType){
case empty: // Empty
System.out.print(RESET + "." + RESET);
break;
case player: // Player
System.out.print(CYAN + "@" + RESET);
break;
case lockedDoor: // lockedDoor
System.out.print(RED + "#" + RESET);
break;
case openDoor: // openDoor
System.out.print(GREEN + "#" + RESET);
break;
case crate: // crate/chest
System.out.print(PURPLE + "%" + RESET);
break;
case key: // key
System.out.print(YELLOW + "$" + RESET);
break;
case wall: // wall
System.out.print(RESET + "#" + RESET);
break;
case enemy: // enemy
System.out.print(RED + "@" + RESET);
break;
case none: // used for errors
System.out.print(BLUE + "~" + RESET);
break;
}
System.out.print(" ");
}
}