У вас вопросы?
У нас ответы:) SamZan.net

WrCrocodile; -- This is the nme of the wr crocodile

Работа добавлена на сайт samzan.net: 2015-07-05

Поможем написать учебную работу

Если у вас возникли сложности с курсовой, контрольной, дипломной, рефератом, отчетом по практике, научно-исследовательской и любой другой работой - мы готовы помочь.

Предоплата всего

от 25%

Подписываем

договор

Выберите тип работы:

Скидка 25% при заказе до 5.4.2025

import java.util.*;

public class WarCrocodile extends Crocodile{

private static final String SPECIES = "WarCrocodile"; //— This is the name of the war crocodile.

private static final int ENERGY_TO_LOOK_FOR_ENEMIES = 1; //— This is the amount of energy spent to look for enemies.

private static final int ENERGY_TO_ATTACK = 5; //— This is the amount of energy spent to attack enemies.

private String tribe; //— This is the tribe to which this crocodile belongs.

public static final String RED_TRIBE_ID = "red"; //— This is a string that identifies members of the red tribe.

public static final String GREEN_TRIBE_ID = "green"; //— This is a string that identifies members of the green tribe.

public WarCrocodile(int initialRow,

     int initialColumn,

     Simulation initialSimulation,

     String initialTribe){

 super(initialRow, initialColumn, initialSimulation);

 tribe = initialTribe;

}

public String getSpecies(){

 return SPECIES;

}

 

public String getTribe(){

 return tribe;

}

 

public String getImage(){

 if (this.tribe.equals(GREEN_TRIBE_ID)){

  if(getDirection() == UP){

   return "/Crocodile-up.gif";

  }

  if(getDirection() == DOWN){

   return "/Crocodile-down.gif";

  }

  if(getDirection() == RIGHT){

   return "/Crocodile-right.gif";

  }

  if(getDirection() == LEFT){

   return "/Crocodile-left.gif";

  }

   return "/Crocodile-right.gif";

 } else {

  if(getDirection() == UP){

   return "/RedCrocodile-up.gif";

  }

  if(getDirection() == DOWN){

   return "/RedCrocodile-down.gif";

  }

  if(getDirection() == RIGHT){

   return "/RedCrocodile-right.gif";

  }

  if(getDirection() == LEFT){

   return "/RedCrocodile-left.gif";

  }

   return "/RedCrocodile-left.gif";

 }

}

 

private boolean inMyTribe(WarCrocodile croc){

 if(this.getTribe().equals(croc.getTribe())){

  return true;

 } else {

  return false;

 }

}

 

private WarCrocodile lookForEnemy(){

 setEnergy(getEnergy() - ENERGY_TO_LOOK_FOR_ENEMIES);

 Vector assassin = simulation.getNeighbors(getRow(), getColumn(), 0);

 for (int neighborIndex = 0;neighborIndex < assassin.size();neighborIndex++){

  if(assassin.get(neighborIndex) instanceof WarCrocodile){

   WarCrocodile victim = (WarCrocodile) assassin.get(neighborIndex);

   if (!inMyTribe(victim)){

    return victim;

   }

  }

 }

 return null;

}

 

private void killEnemy(WarCrocodile enemy){

 setEnergy(getEnergy() -  ENERGY_TO_ATTACK);

 enemy.die();

}

 

private void attackEnemiesIfPossible(){

 if (getEnergy() > ENERGY_TO_LOOK_FOR_ENEMIES){

  WarCrocodile victim = lookForEnemy();

  if(getEnergy() >= ENERGY_TO_ATTACK && lookForEnemy() != null){

   killEnemy(victim);

  } else {

  }

 }

}

 

public void liveALittle(){

 if (!isDead()){

  attackEnemiesIfPossible();

  super.liveALittle();

 }

}

 

}

 

import java.util.Vector;

/*

* Created on Jul 6, 2003

*

*/

/**

* Crocodile - to simulate artificial life. Eats small fish.

*

* @author iCarnegie av

*

*/

public class WarCrocodile extends Crocodile {

 

/**

 * Name of species

 */

private static final String SPECIES = "WarCrocodile";

 

/**

*This is the amount of energy spent to look for enemies.

*/

private static final int ENERGY_TO_LOOK_FOR_ENEMIES = 1;

 

/**

*This is the tribe to which this crocodile belongs.

*/

private String tribe = "";

 

/**

*This is a string that identifies members of the red tribe.

*/

public static final String RED_TRIBE_ID = "red";

 

/**

*This is a string that identifies members of the green tribe.

*/

public static final String GREEN_TRIBE_ID = "green";

/**

*This is the amount of energy spent to attack enemies.

*/

private static final int ENERGY_TO_ATTACK = 5;

 

/**

 * Number of Crocodiles created so far

 */

private static int nWarCrocodilesCreated = 0;

/**

 * Construct and initialize a Crocodile.

 *

 * @param initialRow - the row at which the crocodile is located

 * @param initialColumn - the column at which the crocodile is located

 * @param initialSimulation - the simulation that the crocodile belongs to

 */

public WarCrocodile(

 int initialRow,

 int initialColumn,

 Simulation initialSimulation,

 String initialTribe) {

 super(

  initialRow,

  initialColumn,

  initialSimulation);

  tribe = initialTribe;

  ++nWarCrocodilesCreated;

}

/**

 * Get the species

 *

 * @return a string indicating the species

 */

public String getSpecies() {

 return SPECIES;

}

/**

*This returns the string specified by the instance variable tribe.

*/

public String getTribe(){

 return tribe;

}

 

/**

 * Get the filename that contains an image of the Crocodile

 *

 * @return filename of Crocodile image

 */

public String getImage() {

 String image = "";

 if(tribe.equals(RED_TRIBE_ID))  image = "Red";

  if (getDirection() == RIGHT) {

   return "/" + image+ "Crocodile-right.gif";

  }

  if (getDirection() == LEFT) {

   return "/" + image+ "Crocodile-left.gif";

  }

  if (getDirection() == UP) {

   return "/" + image+ "Crocodile-up.gif";

  }

  if (getDirection() == DOWN) {

   return "/" + image+ "Crocodile-down.gif";

  }

 return "Crocodile-right.gif";

}

private boolean inMyTribe(WarCrocodile croc){

 if(tribe.equals(croc.getTribe())){

  return true;

 }

 return false;

}

 

private WarCrocodile lookForEnemy(){

 setEnergy(getEnergy() - ENERGY_TO_LOOK_FOR_ENEMIES);

 Vector myCell = simulation.getNeighbors(getRow(), getColumn(), 0);

 for(int i = 0; i<myCell.size(); i++){

  if(myCell.get(i) instanceof WarCrocodile){

   WarCrocodile croco = (WarCrocodile) myCell.get(i);

   if(!inMyTribe(croco)){

    return croco;

   }

  }

 }

 return null;

}

 

/**

*This method will consume the amount of energy necessary to attack another crocodile.

*/

private void killEnemy(WarCrocodile enemy){

 

 setEnergy(getEnergy() - ENERGY_TO_ATTACK);

 enemy.die();

}

 

private void attackEnemiesIfPossible(){

 if(getEnergy()>ENERGY_TO_LOOK_FOR_ENEMIES) {

  WarCrocodile enemy = lookForEnemy();

  if((null != enemy) && (getEnergy() >= ENERGY_TO_ATTACK)){

   killEnemy(enemy);

  }

 }

}

/**

*If this crocodile is not dead, invoke attackEnemiesIfPossible, then invoke the method liveALittle of the super class.

*/

public void liveALittle(){

 if (isDead()) {

  return;

 }

 super.liveALittle();

 attackEnemiesIfPossible();

}

}

import java.util.Vector;

/*

* Created on 19 March 2004 NB

*

*/

/**

* WarCrocodile - to simulate artificial life. Eats small fish.  Attacks different colored crocs

*

* @author iCarnegie NB

*

*/

public class WarCrocodile extends Crocodile {

 

/**

 * Identifier for the red tribe

 */

public static final String RED_TRIBE_ID = "red";

/**

 * Identifier for the green tribe

 */

public static final String GREEN_TRIBE_ID = "green";

/**

 * Energy consumed by looking for enemies

 */

private static final int ENERGY_TO_LOOK_FOR_ENEMIES = 1;

/**

 * Energy consumed by attacking

 */

private static final int ENERGY_TO_ATTACK = 4;

/**

 * Name of species

 */

private static final String SPECIES = "WarCrocodile";

/**

 * Name of tribe (red or green)

 */

private String tribe;

/**

 * Construct and initialize a WarCrocodile.

 *

 * @param initialRow - the row at which the crocodile is located

 * @param initialColumn - the column at which the crocodile is located

 * @param initialSimulation - the simulation that the crocodile belongs to

 * @param initialTribe - the tribe to which this crocodiel belongs

 */

public WarCrocodile(

 int initialRow,

 int initialColumn,

 Simulation initialSimulation,

 String initialTribe) {

 super(

  initialRow,

  initialColumn,

  initialSimulation);

  

  tribe = initialTribe;

}

/**

 * Get the species

 *

 * @return a string indicating the species

 */

public String getSpecies() {

 return SPECIES;

}

/**

 * Get the tribe of the Crocodile

 *

 * @return the crocodile's tribe

 */

private String getTribe() {

 return tribe;

}

/**

 * Get the filename that contains an image of the Crocodile

 *

 * @return filename of Crocodile image

 */

public String getImage() {

 if (getTribe().equals(GREEN_TRIBE_ID)) {

  

  return super.getImage();

  

 } else {

  if (getDirection() == RIGHT) {

   return "/RedCrocodile-right.gif";

  }

  if (getDirection() == LEFT) {

   return "/RedCrocodile-left.gif";

  }

  if (getDirection() == UP) {

   return "/RedCrocodile-up.gif";

  }

  if (getDirection() == DOWN) {

   return "/RedCrocodile-down.gif";

  }

  

  return "/RedCrocodile-right.gif";

 }

}

/**

 * Live for a block of time.

 */

public void liveALittle() {

 

 if(isDead()) {

  return;

 }

 attackEnemyIfPossible();

 super.liveALittle();

 return;

}

/**

 * Look for enemy crocodiles in the same cell.  

 * Attack if one is found

 */

private WarCrocodile lookForEnemy() {

 Vector potentialEnemies;

 int neighborIndex;

 setEnergy(getEnergy() - ENERGY_TO_LOOK_FOR_ENEMIES);

 potentialEnemies = simulation.getNeighbors(getRow(), getColumn(), 0);

 for (neighborIndex = 0;

  neighborIndex < potentialEnemies.size();

  ++neighborIndex) {

  if (potentialEnemies.get(neighborIndex) instanceof WarCrocodile) {

   WarCrocodile enemy = (WarCrocodile) potentialEnemies.get(neighborIndex);

   if(!inMyTribe(enemy)) {

     return enemy;

   }

  }

 }

 return null;

}

/**

 * Checks to see if we are in the same tribe

 *

 * @param croc a crocodile; potentially a friend or enemy

 * @return true if another tribal crocodile, false otherwise

 */

private boolean inMyTribe(WarCrocodile croc) {

 return getTribe().equals(croc.getTribe());

}

/**

 * Kills an enemy crocodile in the same cell

 *

 * @param enemy the victim

 */

private void killEnemy(WarCrocodile enemy) {

 

 setEnergy(getEnergy() - ENERGY_TO_ATTACK);

 enemy.die();

}

/**

 * Attacks an enemy crocodile in the same cell

 *

 * @param enemy the victim

 */

private void attackEnemyIfPossible() {

 

 if (getEnergy() >= ENERGY_TO_LOOK_FOR_ENEMIES) {  

  WarCrocodile enemy = lookForEnemy();   

  if (enemy != null && getEnergy() >= ENERGY_TO_ATTACK) {

   killEnemy(enemy);

  }

 }

}

}

DJ

import java.util.Vector;

public class WarCrocodile extends Crocodile

{

 public static final String RED_TRIBE_ID = "red";

 public static final String GREEN_TRIBE_ID = "green";

 private static final int o = 1;

 private static final int p = 4;

 private static final String q = "WarCrocodile";

 private String r;

 public WarCrocodile(int paramInt1, int paramInt2, Simulation paramSimulation, String paramString)

 {

   super(paramInt1, paramInt2, paramSimulation);

   this.r = paramString;

 }

 public String getSpecies()

 {

   return "WarCrocodile";

 }

 private String c()

 {

   return this.r;

 }

 public String getImage()

 {

   boolean bool = Simulation.i;

   if (!(bool))

     if (c().equals("green"))

       return super.getImage();

   if (!(bool))

     if (getDirection() == "right")

       return "/RedCrocodile-right.gif";

   if (!(bool))

     if (getDirection() == "left")

       return "/RedCrocodile-left.gif";

   if (!(bool))

   {

     if (getDirection() == "up")

       return "/RedCrocodile-up.gif";

     if (bool)

       return;

   }

   if (getDirection() == "down")

     return "/RedCrocodile-down.gif";

   return "/RedCrocodile-right.gif";

 }

 public void liveALittle()

 {

   if (!(Simulation.i))

   {

     if (isDead())

       return;

     e();

   }

   super.liveALittle();

 }

 private WarCrocodile d()

 {

   boolean bool = Simulation.i;

   setEnergy(getEnergy() - 1);

   Vector localVector = this.simulation.getNeighbors(getRow(), getColumn(), 0);

   int i = 0;

   do

   {

     if (i >= localVector.size())

       break;

     if ((bool) || (localVector.get(i) instanceof WarCrocodile))

     {

       WarCrocodile localWarCrocodile = (WarCrocodile)localVector.get(i);

       if (bool)

         continue;

       if (!(a(localWarCrocodile)))

         return localWarCrocodile;

     }

     ++i;

   }

   while (!(bool));

   return null;

 }

 private boolean a(WarCrocodile paramWarCrocodile)

 {

   return c().equals(paramWarCrocodile.c());

 }

 private void b(WarCrocodile paramWarCrocodile)

 {

   setEnergy(getEnergy() - 4);

   paramWarCrocodile.die();

 }

 private void e()

 {

   boolean bool = Simulation.i;

   if ((bool) || (getEnergy() >= 1))

   {

     WarCrocodile localWarCrocodile = d();

     if ((((bool) || (localWarCrocodile != null))) && (((bool) || (getEnergy() >= 4))))

       b(localWarCrocodile);

   }

 }

}




1. А.Смит и промышленный переворот
2. 1992 Plce of birth- Kherson Ntionlity- Ukrine Civil Sttus- Single Rnk- Third Officer ddres
3. Введение Жёсткая конкуренция на рынке ускорение изменений в макросреде глобализация бизнеса борьба за ре.
4. тематизацию пройденного учебного материала на базе которого студенты выстраивают свои выводы и заключения
5. Творчество Михаила Лермонтова
6. Лабораторная работа 5 ОРГАНИЗАЦИЯ ЦИКЛОВ И РАБОТА С МАССИВАМИ Цель работы
7. тема Первые греческие философы по текстам досократиков ЗАДАНИЕ 1 Выберете одну из философских ш
8. Тема Содержание Колво часов Модуль 1
9. і Використання людиною підземних порожнин відоме з початку її існування
10. Производственные запасы