---
title: "AlCroc and Poisalgae"
description: "import java.util.*; public class AllergicCrocodile extends Crocodile { static private final String ..."
author: "Duke"
published: "2011-05-25T15:21:15+00:00"
modified: "2011-05-25T15:21:15+00:00"
locale: "ru"
canonical_url: "https://yvision.kz/post/alcroc-and-poisalgae-153755"
markdown_url: "https://yvision.kz/post/alcroc-and-poisalgae-153755/markdown"
site_name: "Yvision.kz"
---

# AlCroc and Poisalgae

> import java.util.*; public class AllergicCrocodile extends Crocodile { static private final String ...

import java.util.*;

public class AllergicCrocodile extends Crocodile {

static private final String SPECIES = "Allergic Croc"; private static final int SUFFOCATION_THRESHOLD = 2; private static final String CROCODILE_WITHOUT_ALLERGY_IMAGE = "/Crocodile-without-allergy.gif"; private static final String CROCODILE_WITH_ALLERGY_IMAGE = "/Crocodile-with-allergy.gif"; private static int nAllergicCrocsCreated =0 ; int allergenLevel=0;

public AllergicCrocodile(int initialRow, int initialColumn, Simulation initialSimulation) { super (initialRow, initialColumn,initialSimulation, SPECIES + nAllergicCrocsCreated ); ++ nAllergicCrocsCreated; }

public String getSpecies() { return SPECIES; }

public String getImage() { if (allergenLevel== 0) { return CROCODILE_WITHOUT_ALLERGY_IMAGE; } else { return CROCODILE_WITH_ALLERGY_IMAGE; } } protected void catchAllergy() { Vector localVector = simulation.getNeighbors(getRow(), getColumn(), 0);

for (int i = 0; i  SUFFOCATION_THRESHOLD) { isDead(); } } } /** Live for a block of time.*/ public void liveALittle() { if (isDead()) { return; } catchAllergy(); super.liveALittle(); } }

 
 
 
 
 
 
 
 

import java.util.*;

public class PoisonAlgae extends AlgaeColony {

private static final String SPECIES ="PoisonAlgae";

private static final int ENERGY_TO_GROW =2;

private static final int ADULT_AGE = 2;

private static int nPoisonAlgaeCreated = 0;

private int age = 0;

public PoisonAlgae(int initialRow, int initialColumn, Simulation initialSimulation) { super ( initialRow, initialColumn, initialSimulation , SPECIES + nPoisonAlgaeCreated); nPoisonAlgaeCreated++; }

public String getSpecies() { return SPECIES; }

public boolean isPoisonous() { if ( getAge() >= ADULT_AGE ) { return true; }else{ return false; } }

private boolean isAlgaeAt(int row, int col) { Vector neighbors = new Vector(); neighbors= simulation.getNeighbors(row,col,0); for (int index = 0;index = ADULT_AGE && getEnergy() >= ENERGY_TO_GROW) { for (int i = getRow() - 1; i = simulation.getFirstRow() && i = simulation.getFirstColumn() && j <= simulation.getLastColumn() && isAlgaeAt(i,j) == false) { PoisonAlgae Palgae = new PoisonAlgae(i, j, simulation); simulation.addLivingBeing(Palgae); setEnergy(getEnergy() - ENERGY_TO_GROW); return true; } } } return false; } else { return false; } }

public void liveALittle() { if (isDead()) { return; } growIfPossible(); super.liveALittle(); } }

---

Source: [https://yvision.kz/post/alcroc-and-poisalgae-153755](https://yvision.kz/post/alcroc-and-poisalgae-153755)