-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeapon.java
More file actions
77 lines (64 loc) · 2.38 KB
/
Copy pathWeapon.java
File metadata and controls
77 lines (64 loc) · 2.38 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
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
/**
* A weapon class which represents the possible murder weapon
*
* @Team MAGA
* @Author Gajun Young - 16440714
* @Author Royal Thomas - 16326926
* @Author Richard Otroshchenko - 16353416
*/
public class Weapon {
private String type; //Type of weapon
private Tile position; //Position of weapon
//Adjust coordinates such that the initial is at the middle of the tile
private static final float X_OFFSET = 6f;
private static final float Y_OFFSET = 16f;
private static final int S_OFFSET = 2;
private static final int SQUARE = 18;
//Constructor
public Weapon(String type, Tile position) {
this.position = position;
this.type = type;
}
//Accessor method to obtain a weapon's name.
public String getWeaponName() {
return type;
}
//Weapon's position
public Tile getPosition() {
return position;
}
//Move weapon to a new position
public void moveBy(Tile position) {
this.position = position;
}
//Checks if two tokens are on the same tile
public boolean hasTile(Tile tile) {
return this.getPosition().showRoom().equals(tile.showRoom());
}
//If name is same
public boolean hasName(String type) {
return this.type.toLowerCase().equals(type.toLowerCase().trim());
}
//Draw the initials of the weapon
public void drawWeapon(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.BLACK);
//Background of weapon
Rectangle2D.Double rectangleBlack = new Rectangle2D.Double(position.getXCord() + S_OFFSET, position.getYCord() + S_OFFSET, SQUARE , SQUARE);
g2.fill(rectangleBlack);
//Foreground of weapon
Rectangle2D.Double rectangleColor = new Rectangle2D.Double(position.getXCord() + S_OFFSET + 2, position.getYCord() + S_OFFSET + 2, SQUARE - 4 , SQUARE - 4);
g2.setColor(Color.lightGray);
g2.fill(rectangleColor);
//Weapon initial
Font font = new Font("Comic Sans MS", Font.BOLD, 14); //Font Comic Sans
g2.setFont(font);
g2.setColor(Color.yellow); //Blue color
g2.drawString(type.substring(0, 1), position.getXCord() + X_OFFSET, position.getYCord() + Y_OFFSET);
}
}