-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTrain.java
78 lines (72 loc) · 2.19 KB
/
Train.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
import java.awt.*;
import java.util.*;
import java.io.File;
/**
* Write a description of class Train here.
*
* @author Sean Walsh
* @version 1.0
*/
public class Train extends Card {
RouteColor color;
private static final String path =
"resources\\images\\cards\\train cards\\";
/**
* import from csv in the format RouteColor
*/
public Train(RouteColor color) {
this.color = color;
}
/**
* a method that returns a image representing this object
* @return an image that represents this object
*/
public Image getImage() {
String filePath = path + color + ".jpg";
try (Scanner sc = new Scanner(new File(filePath))) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
return toolkit.getImage(filePath);
} catch (Exception e) {
System.err.println("(ERR Train.getImage): Cannot find file \""
+ filePath + "\"");
}
return null;
}
/**
* static method to get a genral image for this object type
* @param color type of card
* @return an image based on the type of card
*/
public static Image getImage(RouteColor color) {
String filePath = path + color + ".jpg";
try (Scanner sc = new Scanner(new File(filePath))) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
return toolkit.getImage(filePath);
} catch (Exception e) {
System.err.println("(ERR Train.getImage): Cannot find file \""
+ filePath + "\"");
}
return null;
}
/**
* method to compare this Train card to other Objects
*
* @param o A Object to compare to
* @return false if the Objects are not equal
*/
@Override
public boolean equals(Object o) {
if (o instanceof Train)
if (this.color == ((Train) o).color)
return true;
return false;
}
/**
* method that returns a unique int for this object
* @return a unique int for this object
*/
@Override
public int hashCode() {
return color.hashCode();
}
}