SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
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

Más contenido relacionado

Más de 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
 

Más de 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
 

Último

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Último (20)

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.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