Repository navigation
Expand file tree
/
Copy pathKey.java
More file actions
56 lines (50 loc) · 1.55 KB
/
Copy pathKey.java
File metadata and controls
56 lines (50 loc) · 1.55 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
import javafx.scene.image.Image;
/**
* Represents a Key tile in the game.
* This tile can be entered/walked over and is
* represented by an image based on the colour of the key.
* @author Joshua Aka
*/
public class Key extends Element {
/**
* The colour of the key.
*/
private final KeyColour colour;
/**
* Creates a new Key tile at the specified row
* and column with the specified key colour.
* @param row the row position of the tile
* @param column the column position of the tile
* @param colour the colour of the key
*/
public Key(final int row, final int column, final KeyColour colour) {
super(row, column);
this.colour = colour;
canBeEntered = true;
name = colour + "Key";
canExplode = true;
switch (colour) {
case RED -> image = new Image("images/RedKey.png");
case GREEN -> image = new Image("images/GreenKey.png");
case YELLOW -> image = new Image("images/YellowKey.png");
case BLUE -> image = new Image("images/BlueKey.png");
case RAINBOW -> image = new Image("images/RainbowKey.png");
}
}
/**
* Gets the colour of the key.
* @return the colour of the key
*/
public KeyColour getColour() {
return colour;
}
/**
* Returns a string representation of the key and
* what colour it is.
* @return the string representation of the key
*/
@Override
public String toString() {
return "Key Colour: " + colour;
}
}