-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sword.java
127 lines (108 loc) Β· 3.06 KB
/
Sword.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* A weapon which inflicts an increased number of damage to an enemy.
*
* @author Maas Lalani
* @version 1.2 2016-11-14
*/
public class Sword
{
/* class fields */
/** The hitpoints of a wood sword. */
public static final int WOOD_HITPOINTS = 10;
/** The damage increase of a wood sword. */
public static final int WOOD_DAMAGE_INCREASE = 5;
/** The hitpoints of a metal sword. */
public static final int METAL_HITPOINTS = 15;
/** The damage increase of a metal sword. */
public static final int METAL_DAMAGE_INCREASE = 10;
/** The hitpoints of a gold sword. */
public static final int GOLD_HITPOINTS = 20;
/** The damage increase of a gold sword. */
public static final int GOLD_DAMAGE_INCREASE = 15;
/* instance fields */
private int damageIncrease;
private int hitpoints;
private String name;
/**
* Constructs a sword with the specified characteristics.
*
* @param type the type of this sword
*/
public Sword(String type)
{
if (type == null) return;
name = type + " sword";
switch (type)
{
case "wood":
hitpoints = WOOD_HITPOINTS;
damageIncrease = WOOD_DAMAGE_INCREASE;
break;
case "metal":
hitpoints = METAL_HITPOINTS;
damageIncrease = METAL_DAMAGE_INCREASE;
break;
case "gold":
hitpoints = GOLD_HITPOINTS;
damageIncrease = GOLD_DAMAGE_INCREASE;
break;
default:
name = "wood sword";
hitpoints = WOOD_HITPOINTS;
damageIncrease = WOOD_DAMAGE_INCREASE;
break;
} // end of switch (type)
} // end of constructor Sword(String type)
/**
* Returns the name of this sword.
*
* @return name
*/
public String name()
{
return name;
} // end of method name()
/**
* Returns the hitpoints of this sword.
*
* @return hitpoints
*/
public int hitpoints()
{
return hitpoints;
} // end of method hitpoints()
/**
* Returns the damageIncrease of this sword.
*
* @return damageIncrease
*/
public int damageIncrease()
{
return damageIncrease;
} // end of method damageIncrease()
/**
* Changes the name of this sword to the specified name.
*
* @param name the name of this sword
*/
public void setName(String name)
{
this.name = name;
} // end of method setName(String name)
/**
* Uses this sword when attacking an enemy, reduces hitpoints.
*/
public void useSword()
{
hitpoints--;
} // end of method useSword()
/**
* Adds hitpoints to sword, repairing the sword.
*
* @param hitpointsToRepair how many hitpoints the sword will be repaired by
*/
public void repairSword(int hitpointsToRepair)
{
hitpoints = hitpoints + hitpointsToRepair;
} // end of method repairSword(int hitpoints)
} // end of class Sword