SlideShare a Scribd company logo
public class Monster {
protected String clanAffiliation;
protected int ferocity;
protected int defense;
protected int magic;
protected int treasure;
protected int health;
public Monster(String clanAffiliation, int ferocity, int defense, int magic) {
this.clanAffiliation = clanAffiliation;
this.ferocity = ferocity;
this.defense = defense;
this.magic = magic;
this.treasure = 0;
this.health = 100;
}
public String getClanAffiliation() {
return clanAffiliation;
}
public int getFerocity() {
return ferocity;
}
public int getDefense() {
return defense;
}
public int getMagic() {
return magic;
}
public int getTreasure() {
return treasure;
}
public int getHealth() {
return health;
}
public void addTreasure(int treasure) {
if (health > 0) {
this.treasure += treasure;
}
}
public void subtractTreasure(int treasure) {
if (health > 0) {
this.treasure -= treasure;
if (this.treasure < 0) {
this.treasure = 0;
}
}
}
public void addHealth(int amount) {
if (health > 0) {
health += amount;
}
}
public void subtractHealth(int amount) {
if (health > 0) {
health -= amount;
if (health < 0) {
health = 0;
}
}
}
public boolean isAlive() {
return health > 0;
}
public double getBattleScore() {
if (health <= 0) {
return 0;
}
return (ferocity + defense + magic) / 3.0;
}
public abstract void attack(Monster opponent);
public abstract void defend(double opponentBattleScore);
@Override
public String toString() {
return "Monster{" +
"clanAffiliation='" + clanAffiliation + ''' +
", ferocity=" + ferocity +
", defense=" + defense +
", magic=" + magic +
", treasure=" + treasure +
", health=" + health +
'}';
}
}
public class Orc extends Monster {
private OrcCommander commander;
public Orc(String clan, int ferocity, int defense, int magic, int treasure, int health) {
super(clan, ferocity, defense, magic, treasure, health);
}
public void setCommander(OrcCommander commander) {
this.commander = commander;
}
public OrcCommander getCommander() {
return commander;
}
public int getLeadership() {
if (this instanceof Warlord) {
Warlord warlord = (Warlord) this;
return warlord.getLeadership();
}
return 0;
}
public int getInfantryCount() {
if (this instanceof Warlord) {
Warlord warlord = (Warlord) this;
return warlord.getInfantryCount();
}
return 0;
}
public void setInfantry(Warlord warlord) {
if (this instanceof Infantry) {
Infantry infantry = (Infantry) this;
infantry.setCommander(warlord);
}
}
@Override
public void attack(Monster opponent) {
int attackScore = calculateAttackScore();
int defenseScore = opponent.calculateDefenseScore();
int damage = Math.max(attackScore - defenseScore, 0);
opponent.takeDamage(damage);
}
}
public class Warlord extends Orc {
private int leadershipRating;
private Infantry[] infantry;
public Warlord(String name, int ferocity, int defense, int magic, int leadershipRating) {
super(name, ferocity, defense, magic);
this.leadershipRating = leadershipRating;
this.infantry = new Infantry[5];
}
public int getLeadershipRating() {
return leadershipRating;
}
public void setLeadershipRating(int leadershipRating) {
if (leadershipRating >= 1 && leadershipRating <= 5) {
this.leadershipRating = leadershipRating;
} else {
System.out.println("Leadership rating must be between 1 and 5");
}
}
public Infantry[] getInfantry() {
return infantry;
}
public void addInfantry(Infantry newInfantry) {
boolean added = false;
for (int i = 0; i < infantry.length; i++) {
if (infantry[i] == null) {
infantry[i] = newInfantry;
newInfantry.setWarlord(this);
added = true;
break;
}
}
if (!added) {
System.out.println("Could not add Infantry - this Warlord already has 5 Infantry in their
command.");
}
}
public void removeInfantry(Infantry infantryToRemove) {
for (int i = 0; i < infantry.length; i++) {
if (infantry[i] == infantryToRemove) {
infantry[i] = null;
infantryToRemove.setWarlord(null);
break;
}
}
}
public void soundBattleCry() {
if (getHealth() > 0) {
int boost = leadershipRating * 5;
System.out.println(getName() + " sounds their battle cry, boosting the health of their Infantry by " +
boost);
for (Infantry soldier : infantry) {
if (soldier != null) {
soldier.receiveHealthBoost(boost);
}
}
} else {
System.out.println(getName() + " cannot sound their battle cry - they are dead.");
}
}
}
public class Infantry extends Monster {
private Warlord commander;
public Infantry(String clan, int ferocity, int defense, int magic, int treasure, int health, Warlord
commander) {
super(clan, ferocity, defense, magic, treasure, health);
this.commander = commander;
}
public Warlord getCommander() {
return commander;
}
public void setCommander(Warlord commander) {
this.commander = commander;
}
public void attack(Monster monster) {
if (this.getHealth() <= 0 || monster.getHealth() <= 0) {
return;
}
double battleScore = (this.getFerocity() + this.getDefense() + this.getMagic()) / 3.0;
if (this.commander != null && this.commander.getLeadership() > 0) {
battleScore *= 1.5;
}
if (monster instanceof Warlord) {
battleScore *= 0.5;
}
if (battleScore > monster.getBattleScore()) {
int damage = (int) Math.round(battleScore - monster.getBattleScore());
monster.setHealth(monster.getHealth() - damage);
if (monster.getHealth() <= 0 && monster instanceof Orc) {
((Orc) monster).removeInfantry(this);
}
}
}
}
public class Goblin extends Monster {
private Goblin swornEnemy;
public Goblin(String clanAffiliation, int ferocity, int defense, int magic, int treasure, int health,
Goblin swornEnemy) {
super(clanAffiliation, ferocity, defense, magic, treasure, health);
this.swornEnemy = swornEnemy;
}
public Goblin getSwornEnemy() {
return swornEnemy;
}
public void setSwornEnemy(Goblin swornEnemy) {
this.swornEnemy = swornEnemy;
}
}
public class Manticore extends Monster {
private String clanAffiliation;
public Manticore(String clanAffiliation, int ferocity, int defense, int magic, int treasure, int health) {
super(clanAffiliation, ferocity, defense, magic, treasure, health);
this.clanAffiliation = clanAffiliation;
}
public String getClanAffiliation() {
return clanAffiliation;
}
public void setClanAffiliation(String clanAffiliation) {
this.clanAffiliation = clanAffiliation;
}
@Override
public double getBattleScore() {
return (getFerocity() + getDefense() + getMagic()) / 3.0 * 1.5;
}
}
public abstract void attack (Monster opponent): public abstroct vaid befend double ononpublic
class Warlord extends Orc { private int leadershipRating; private Infantry[] infantry; public
Warlord(String name, int ferocity, int defense, int magic, int leadershipRating) { super(name,
ferocity, defense, magic); this. leadershipRating = leadershipRating; this. infantry = new Infantry [5
]; 3 public int getleadershipRating() ( return leadershipRating; (3) public void
setLeadershipRating(int leadershipRating) { if (leadershipRating >=1 s& leadershipRating <=5 ) f
this, leadershipRating = leadershipRating; 3 else System.out. println("Leadership rating must be
between 1 and 5 ); 3 3 public Infantry[] getinfantry () { return infantry; 3 public void addInfantry
(Infantry newinfantry) & boolean added = false; for (Int 1=0;1< infantry, 1ength; 1++)< if (infantry [i]
=n= nu11) { infantry [1]= newinfantry; newinfantry, setwarlord(this); added = true; break; ) 3 if
(ladded) { System,out, println("Could not add Infantry. this Wariord already has 5 Infantry in th (
comsand. "); 3 public void removeInfantry (Infantry infantry ToRemove) if. for { int 1 * 3;1< infantry.
Length; 1+} i If (infantry[ 1 in infantryToremove) {public class Infantry extends Monster { private
Warlord commander; public Infantry(String clan, int ferocity, int defense, int magic, int treasure, int
health, Warlord commander) { super(clan, ferocity, defense, magic, treasure, health); this .
commander = commander; 3 public Warlord getCommander() { return commander; 3 public void
setCommander(Warlord commander) ( this. commander = commander; 3 public void
attack(Monster monster) ( return; 7 double battlescore - (this, getferocity ()+ this.getDefense() +
this.getMagic()) 3.0 ; if (this. commander I= nu11 && this. commander.getLeadership ( ) > ) {
battlescore =1.5 3 if (monster instanceof Warlord) & battlescore 0.5; 3 if (battlescore >
monster.getBattlescore()) { int damage = (int) Math. round (battleScore - monster.
getBattlescore()); monster.setHealth(monster, getHealth() - damage); If (monster, gethealth ( ) <=
0&& monster instanceof Orc) { ((orc) monster). removeInfantry(this); 3public class Goblin extends
Monster { private Goblin swornEnemy; public Goblin(String clanAffiliation, int ferocity, int defense,
int magic, int treasure, int health, Goblin sworntnemy) & super(clandffiliation, ferocity, defense,
magic, treasure, health); this. swornenemy = swornEnemy; 3 public Goblin getswornemony() &
return swornEnemy; 3 public void setSwornEnemy (Goblin swornEnemy) & this. swornEnemy =
swornEnemy; l

More Related Content

More from addtechglobalmarketi

pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
pular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdfpular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdf
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
addtechglobalmarketi
 
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdfPrpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
addtechglobalmarketi
 
Program 02 Based on the previous problem you should impleme.pdf
Program 02 Based on the previous problem you should impleme.pdfProgram 02 Based on the previous problem you should impleme.pdf
Program 02 Based on the previous problem you should impleme.pdf
addtechglobalmarketi
 
Programming Assignment 3 CSCE 3530 Introduction to Comput.pdf
Programming Assignment 3 CSCE 3530  Introduction to Comput.pdfProgramming Assignment 3 CSCE 3530  Introduction to Comput.pdf
Programming Assignment 3 CSCE 3530 Introduction to Comput.pdf
addtechglobalmarketi
 

More from addtechglobalmarketi (20)

pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
pular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdfpular  Madde 5  Aadaki durumda orijinal kaynak materyal b.pdf
pular Madde 5 Aadaki durumda orijinal kaynak materyal b.pdf
 
Puede crear numerosas vistas personalizadas para usar con to.pdf
Puede crear numerosas vistas personalizadas para usar con to.pdfPuede crear numerosas vistas personalizadas para usar con to.pdf
Puede crear numerosas vistas personalizadas para usar con to.pdf
 
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdfpublie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
publie elass h 1 pahlte clamsia axcends A pablie clann Main .pdf
 
Puede una empresa ser buena en responsabilidad social corpo.pdf
Puede una empresa ser buena en responsabilidad social corpo.pdfPuede una empresa ser buena en responsabilidad social corpo.pdf
Puede una empresa ser buena en responsabilidad social corpo.pdf
 
Provide three evidences with scholar reference that support.pdf
Provide three evidences with scholar  reference that support.pdfProvide three evidences with scholar  reference that support.pdf
Provide three evidences with scholar reference that support.pdf
 
Provincial Government The name of the representative of the .pdf
Provincial Government The name of the representative of the .pdfProvincial Government The name of the representative of the .pdf
Provincial Government The name of the representative of the .pdf
 
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdfPrpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
Prpugh shicti the bloset fides 1 rightventikiele+3 Fxet.pdf
 
Provide three evidences with reliable reference that suppor.pdf
Provide three evidences with reliable  reference that suppor.pdfProvide three evidences with reliable  reference that suppor.pdf
Provide three evidences with reliable reference that suppor.pdf
 
Provide the Independent variables Dependent variables a.pdf
Provide the Independent variables Dependent variables a.pdfProvide the Independent variables Dependent variables a.pdf
Provide the Independent variables Dependent variables a.pdf
 
Provide your example of a firm or a small business from the .pdf
Provide your example of a firm or a small business from the .pdfProvide your example of a firm or a small business from the .pdf
Provide your example of a firm or a small business from the .pdf
 
Provide the steps for the following In order to install sof.pdf
Provide the steps for the following In order to install sof.pdfProvide the steps for the following In order to install sof.pdf
Provide the steps for the following In order to install sof.pdf
 
Provide land use land cover images and photos using shape.pdf
Provide land use land cover images and photos  using shape.pdfProvide land use land cover images and photos  using shape.pdf
Provide land use land cover images and photos using shape.pdf
 
Provide SQL that creates two database tables Employee and D.pdf
Provide SQL that creates two database tables Employee and D.pdfProvide SQL that creates two database tables Employee and D.pdf
Provide SQL that creates two database tables Employee and D.pdf
 
Provide examples of risk and responsibilities relating to ts.pdf
Provide examples of risk and responsibilities relating to ts.pdfProvide examples of risk and responsibilities relating to ts.pdf
Provide examples of risk and responsibilities relating to ts.pdf
 
Provide an example of a user interface such as a webbased.pdf
Provide an example of a user interface such as a webbased.pdfProvide an example of a user interface such as a webbased.pdf
Provide an example of a user interface such as a webbased.pdf
 
Provide an example of an unintentional tort Discuss 3 occas.pdf
Provide an example of an unintentional tort Discuss 3 occas.pdfProvide an example of an unintentional tort Discuss 3 occas.pdf
Provide an example of an unintentional tort Discuss 3 occas.pdf
 
Program 02 Based on the previous problem you should impleme.pdf
Program 02 Based on the previous problem you should impleme.pdfProgram 02 Based on the previous problem you should impleme.pdf
Program 02 Based on the previous problem you should impleme.pdf
 
Programming Assignment 3 CSCE 3530 Introduction to Comput.pdf
Programming Assignment 3 CSCE 3530  Introduction to Comput.pdfProgramming Assignment 3 CSCE 3530  Introduction to Comput.pdf
Programming Assignment 3 CSCE 3530 Introduction to Comput.pdf
 
Prove the following by induction 1ini32nn+122n+12nn3.pdf
Prove the following by induction 1ini32nn+122n+12nn3.pdfProve the following by induction 1ini32nn+122n+12nn3.pdf
Prove the following by induction 1ini32nn+122n+12nn3.pdf
 
Provide a design for a cryptography problem which was illus.pdf
Provide a design for a cryptography problem which was illus.pdfProvide a design for a cryptography problem which was illus.pdf
Provide a design for a cryptography problem which was illus.pdf
 

Recently uploaded

Recently uploaded (20)

How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 

public class Monster protected String clanAffiliation pro.pdf

  • 1. public class Monster { protected String clanAffiliation; protected int ferocity; protected int defense; protected int magic; protected int treasure; protected int health; public Monster(String clanAffiliation, int ferocity, int defense, int magic) { this.clanAffiliation = clanAffiliation; this.ferocity = ferocity; this.defense = defense; this.magic = magic; this.treasure = 0; this.health = 100; } public String getClanAffiliation() { return clanAffiliation; } public int getFerocity() { return ferocity; } public int getDefense() { return defense; } public int getMagic() { return magic; } public int getTreasure() { return treasure; } public int getHealth() { return health; } public void addTreasure(int treasure) { if (health > 0) { this.treasure += treasure; } } public void subtractTreasure(int treasure) { if (health > 0) { this.treasure -= treasure; if (this.treasure < 0) {
  • 2. this.treasure = 0; } } } public void addHealth(int amount) { if (health > 0) { health += amount; } } public void subtractHealth(int amount) { if (health > 0) { health -= amount; if (health < 0) { health = 0; } } } public boolean isAlive() { return health > 0; } public double getBattleScore() { if (health <= 0) { return 0; } return (ferocity + defense + magic) / 3.0; } public abstract void attack(Monster opponent); public abstract void defend(double opponentBattleScore); @Override public String toString() { return "Monster{" + "clanAffiliation='" + clanAffiliation + ''' + ", ferocity=" + ferocity + ", defense=" + defense + ", magic=" + magic + ", treasure=" + treasure + ", health=" + health + '}'; } } public class Orc extends Monster { private OrcCommander commander;
  • 3. public Orc(String clan, int ferocity, int defense, int magic, int treasure, int health) { super(clan, ferocity, defense, magic, treasure, health); } public void setCommander(OrcCommander commander) { this.commander = commander; } public OrcCommander getCommander() { return commander; } public int getLeadership() { if (this instanceof Warlord) { Warlord warlord = (Warlord) this; return warlord.getLeadership(); } return 0; } public int getInfantryCount() { if (this instanceof Warlord) { Warlord warlord = (Warlord) this; return warlord.getInfantryCount(); } return 0; } public void setInfantry(Warlord warlord) { if (this instanceof Infantry) { Infantry infantry = (Infantry) this; infantry.setCommander(warlord); } } @Override public void attack(Monster opponent) { int attackScore = calculateAttackScore(); int defenseScore = opponent.calculateDefenseScore(); int damage = Math.max(attackScore - defenseScore, 0); opponent.takeDamage(damage); } } public class Warlord extends Orc { private int leadershipRating; private Infantry[] infantry; public Warlord(String name, int ferocity, int defense, int magic, int leadershipRating) { super(name, ferocity, defense, magic);
  • 4. this.leadershipRating = leadershipRating; this.infantry = new Infantry[5]; } public int getLeadershipRating() { return leadershipRating; } public void setLeadershipRating(int leadershipRating) { if (leadershipRating >= 1 && leadershipRating <= 5) { this.leadershipRating = leadershipRating; } else { System.out.println("Leadership rating must be between 1 and 5"); } } public Infantry[] getInfantry() { return infantry; } public void addInfantry(Infantry newInfantry) { boolean added = false; for (int i = 0; i < infantry.length; i++) { if (infantry[i] == null) { infantry[i] = newInfantry; newInfantry.setWarlord(this); added = true; break; } } if (!added) { System.out.println("Could not add Infantry - this Warlord already has 5 Infantry in their command."); } } public void removeInfantry(Infantry infantryToRemove) { for (int i = 0; i < infantry.length; i++) { if (infantry[i] == infantryToRemove) { infantry[i] = null; infantryToRemove.setWarlord(null); break; } } } public void soundBattleCry() { if (getHealth() > 0) {
  • 5. int boost = leadershipRating * 5; System.out.println(getName() + " sounds their battle cry, boosting the health of their Infantry by " + boost); for (Infantry soldier : infantry) { if (soldier != null) { soldier.receiveHealthBoost(boost); } } } else { System.out.println(getName() + " cannot sound their battle cry - they are dead."); } } } public class Infantry extends Monster { private Warlord commander; public Infantry(String clan, int ferocity, int defense, int magic, int treasure, int health, Warlord commander) { super(clan, ferocity, defense, magic, treasure, health); this.commander = commander; } public Warlord getCommander() { return commander; } public void setCommander(Warlord commander) { this.commander = commander; } public void attack(Monster monster) { if (this.getHealth() <= 0 || monster.getHealth() <= 0) { return; } double battleScore = (this.getFerocity() + this.getDefense() + this.getMagic()) / 3.0; if (this.commander != null && this.commander.getLeadership() > 0) { battleScore *= 1.5; } if (monster instanceof Warlord) { battleScore *= 0.5; } if (battleScore > monster.getBattleScore()) { int damage = (int) Math.round(battleScore - monster.getBattleScore()); monster.setHealth(monster.getHealth() - damage); if (monster.getHealth() <= 0 && monster instanceof Orc) { ((Orc) monster).removeInfantry(this);
  • 6. } } } } public class Goblin extends Monster { private Goblin swornEnemy; public Goblin(String clanAffiliation, int ferocity, int defense, int magic, int treasure, int health, Goblin swornEnemy) { super(clanAffiliation, ferocity, defense, magic, treasure, health); this.swornEnemy = swornEnemy; } public Goblin getSwornEnemy() { return swornEnemy; } public void setSwornEnemy(Goblin swornEnemy) { this.swornEnemy = swornEnemy; } } public class Manticore extends Monster { private String clanAffiliation; public Manticore(String clanAffiliation, int ferocity, int defense, int magic, int treasure, int health) { super(clanAffiliation, ferocity, defense, magic, treasure, health); this.clanAffiliation = clanAffiliation; } public String getClanAffiliation() { return clanAffiliation; } public void setClanAffiliation(String clanAffiliation) { this.clanAffiliation = clanAffiliation; } @Override public double getBattleScore() { return (getFerocity() + getDefense() + getMagic()) / 3.0 * 1.5; } } public abstract void attack (Monster opponent): public abstroct vaid befend double ononpublic class Warlord extends Orc { private int leadershipRating; private Infantry[] infantry; public Warlord(String name, int ferocity, int defense, int magic, int leadershipRating) { super(name, ferocity, defense, magic); this. leadershipRating = leadershipRating; this. infantry = new Infantry [5 ]; 3 public int getleadershipRating() ( return leadershipRating; (3) public void setLeadershipRating(int leadershipRating) { if (leadershipRating >=1 s& leadershipRating <=5 ) f this, leadershipRating = leadershipRating; 3 else System.out. println("Leadership rating must be
  • 7. between 1 and 5 ); 3 3 public Infantry[] getinfantry () { return infantry; 3 public void addInfantry (Infantry newinfantry) & boolean added = false; for (Int 1=0;1< infantry, 1ength; 1++)< if (infantry [i] =n= nu11) { infantry [1]= newinfantry; newinfantry, setwarlord(this); added = true; break; ) 3 if (ladded) { System,out, println("Could not add Infantry. this Wariord already has 5 Infantry in th ( comsand. "); 3 public void removeInfantry (Infantry infantry ToRemove) if. for { int 1 * 3;1< infantry. Length; 1+} i If (infantry[ 1 in infantryToremove) {public class Infantry extends Monster { private Warlord commander; public Infantry(String clan, int ferocity, int defense, int magic, int treasure, int health, Warlord commander) { super(clan, ferocity, defense, magic, treasure, health); this . commander = commander; 3 public Warlord getCommander() { return commander; 3 public void setCommander(Warlord commander) ( this. commander = commander; 3 public void attack(Monster monster) ( return; 7 double battlescore - (this, getferocity ()+ this.getDefense() + this.getMagic()) 3.0 ; if (this. commander I= nu11 && this. commander.getLeadership ( ) > ) { battlescore =1.5 3 if (monster instanceof Warlord) & battlescore 0.5; 3 if (battlescore > monster.getBattlescore()) { int damage = (int) Math. round (battleScore - monster. getBattlescore()); monster.setHealth(monster, getHealth() - damage); If (monster, gethealth ( ) <= 0&& monster instanceof Orc) { ((orc) monster). removeInfantry(this); 3public class Goblin extends Monster { private Goblin swornEnemy; public Goblin(String clanAffiliation, int ferocity, int defense, int magic, int treasure, int health, Goblin sworntnemy) & super(clandffiliation, ferocity, defense, magic, treasure, health); this. swornenemy = swornEnemy; 3 public Goblin getswornemony() & return swornEnemy; 3 public void setSwornEnemy (Goblin swornEnemy) & this. swornEnemy = swornEnemy; l