亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? crocodile.java

?? SSD1 EX7 SSD1 EX7 SSD1 EX7 SSD1 EX7 SSD1 EX7
?? JAVA
字號:
import java.util.Vector;

/**
 * Crocodile - simulates a crocodile - can wade, eat, and consume 
 * energy in the process.
 */
public class Crocodile extends LivingBeing {

	/**
	 * The crocodile is born "alive". 
	 * Then it dies, becoming a corpse. 
	 */
	private static final String ALIVE = "alive";

	/**
	 * The crocodile is born "alive". 
	 * Then it dies, becoming a "dead" corpse. 
	 */
	private static final String DEAD = "dead";


	/**
	 * Energy needed to wade in a block of time.
	 */
	private static final int ENERGY_TO_WADE = 2;

	/**
	 * debugging level. 
	 */
	private static final int DEBUG = 0;
		
	/**
	 * Energy needed to look for food once.
	 */
	private static final int ENERGY_TO_LOOK_FOR_FOOD = 1;
	
	/**
	 * Energy expended to eat once.
	 */
	private static final int ENERGY_TO_EAT = 1;
	
	/**
	 * Energy gained when a full meal is eaten.
	 */
	private static final int ENERGY_IN_A_FULL_MEAL = 10;
	
	/**
	 * Lowest possible energy needed for a baby to survive. 
	 */
	private static final int BABY_MIN_ENERGY = 15;
	
	/**
	 * Maximum energy that a baby can store. 
	 */
	private static final int BABY_MAX_ENERGY = 100;

	/**
	 * For each block of time, the min energy grows by a certain amount
	 */
	private static final int MIN_ENERGY_GROWTH_INCREMENT = 5;
	
	/**
	 * For each block of time, the max energy grows by a certain amount
	 */
	private static final int MAX_ENERGY_GROWTH_INCREMENT = 10;
	
	// Concept example: final. since it is a constant 
	// Concept example: static. since only one value is needed 
	// 						irrespective of number of object instances 
	/**
	 * String constant - used to indicate the direction crocodile is facing.
	 */
	private static final String RIGHT = "right";

	/**
	 * String constant - used to indicate the direction crocodile is facing.
	 */
	private static final String LEFT = "left";

	/**
	 * String constant - used to indicate the direction crocodile is facing.
	 */
	private static final String UP = "up";

	/**
	 * String constant - used to indicate the direction crocodile is facing.
	 */
	private static final String DOWN = "down";

	/**
	 * Name of species
	 */
	private static final String SPECIES = "Crocodile";

	/**
	 * Row-wise location of the crocodile
	 */
	private int row;

	/**
	 * Column-wise location of the crocodile
	 */
	private int column;

	/**
	 * Is the crocodile dead or alive?
	 */
	private String deadOrAlive;
	
	/**
	 * Amount of energy the crocodile has.
	 */
	private int energy;

	/**
	 * Age expressed as blocks of time lived
	 */
	private int age = 0;

	/**
	 * Name of this crocodile.
	 */
	private final String name;

	/**
	 * The simulation to which this crocodile belongs.
	 * This is needed so the crocodile can send a message 
	 * to simulation and ask
	 * for prey (or predator) in the neighboring locations. 
	 * Prey is food. Food is good!
	 */
	private Simulation simulation;

	/**
	 * Minimum energy level needed to survive.
	 * The minimum could increase as the individual grows.
	 */
	private int minEnergy;
	
	/**
	 * Maximum energy level that the crocodile could carry.
	 * The maximum could change as the individual grows.
	 */
	private int maxEnergy;
	
	/**
	 * Which direction am I facing.
	 */
	private String direction; 

	/**
	 * 
	 * Number of Crocodile created
	 */
	private static int nCrocodileCreated = 0; 

	/**
	 * Constructor. Initialize an algae to start life at a specified 
	 * location with a specified energy. If location is out of bounds,
	 * locate the crocodile at the nearest edge.
	 * 
	 * @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 Crocodile(
		int initialRow,
		int initialColumn,
		Simulation initialSimulation) {

			simulation = initialSimulation;

			deadOrAlive = ALIVE; 

			// Set the Row within bounds
			if (initialRow > initialSimulation.getLastRow()) {
				row = initialSimulation.getLastRow();
			} else if (initialRow < initialSimulation.getFirstRow()) {
				row = initialSimulation.getFirstRow();
			} else {
				row = initialRow;
			}

			// Set the Column within bounds
			if (initialColumn > initialSimulation.getLastColumn()) {
				column = initialSimulation.getLastColumn();
			} else if (initialColumn < initialSimulation.getFirstColumn()) {
				column = initialSimulation.getFirstColumn();
			} else {
				column = initialColumn;
			}

			// Set the minEnergy and maxEnergy
			minEnergy = BABY_MIN_ENERGY;
			maxEnergy = BABY_MAX_ENERGY;

			energy =
				simulation.getRand().nextInt(maxEnergy - minEnergy) + minEnergy;

			age = 0;
			name = SPECIES + nCrocodileCreated;
			
			direction = RIGHT; // Start by facing east.

			++nCrocodileCreated;
	}
	
	/**
	 * Get the row at which the crocodile is located 
	 * 
	 * @return - the row of the crocodile's location. 
	 */		
	public int getRow() {
		return row;
	}

	/**
	 * Get the column at which the crocodile is located
	 * 
	 * @return - the column of the crocodile's location. 
	 */		
	public int getColumn() {
		return column;
	}

	/**
	 * Get the crocodile's age
	 * 
	 * @return the age of the crocodile expressed in blocks of time
	 */
	public int getAge() {
		return age;
	}

	/**
	 * Color of the crocodile expressed in hex notation.
	 * For example, the "green-est" color is "#00FF00",
	 * "blue-est" is "#0000FF", the "red-est" is "#FF0000".
	 * 
	 * @return the rgb color in hex notation. preceded by a pound character '#'
	 */
	public String getColor() {
		return "#FFFFFF"; // default is white.
	}

	/**
	 * Get the name of this crocodile
	 * 
	 * @return the name of the crocodile.
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Get the minimum energy needed to live.
	 * 
	 * @return the minimum energy needed for the crocodile to live.
	 */
	private int getMinEnergy() {
		return minEnergy;
	}
	
	/**
	 * get the maximum energy that the crocodile can carry.
	 * 
	 * @return the maximum energy the crocodile can carry.
	 */
	private int getMaxEnergy() {
		return maxEnergy;
	}
	

	/**
	 * Get the energy currently carried by the crocodile.
	 * 
	 * @return current energy level of the organism
	 */
	public int getEnergy() {
		return energy;
	}

	/**
	 * Sets energy level.
	 * If new energy level is less than minimum energy level, the organism dies.
	 * New energy level is capped at maximum energy level.
	 */
	private void setEnergy(int newEnergy) {
		
		if (newEnergy < getMinEnergy()) {
			energy = newEnergy;
			die();
		} else if (newEnergy > getMaxEnergy()) {
			energy = getMaxEnergy();
		} else {
			energy = newEnergy;
		}
	}

	/**
	 * Die: Change the deadOrAlive to DEAD.
	 */
	public void die() {
		deadOrAlive = DEAD;
	}

	/**
	 * Is the crocodile dead?
	 * 
	 * @return <code>true</code> if dead. <code>false</code>, otherwise.
	 */
	public boolean isDead() {
		return (deadOrAlive == DEAD);
	}

	/**
	 * Get the direction faced by the crocodile.
	 * 
	 * @return the facing direction.
	 */
	private String getDirection() {
		return direction;
	}

	/** 
	 * Is the crocodile hungry?
	 * 
	 * @return True, if hungry. False, otherwise.
	 */
	private boolean isHungry() {
		
		// Hungry, if current energy level is less than twice the 
		// amount needed for survival.
		return (getEnergy() < (2 * getMinEnergy()));
	}

	/**
	 * Move the crocodile to a new row, if new row is within lake bounds.
	 * 
	 * @param newRow - the row to move to.
	 * @return the row moved to. Lake boundary limits movement. -1, if dead.
	 */
	private int moveToRow(int newRow) {
		
		if (isDead()) {
			return -1;
		}

		// Keep the new value within lake boundary.
		if (newRow > simulation.getLastRow()) {
			newRow = simulation.getLastRow();
		} else if (newRow < simulation.getFirstRow()) {
			newRow = simulation.getFirstRow();
		}

		// I might face a new direction.
		if (newRow < row) {
			direction = UP;
		} else if (newRow > row) {
			direction = DOWN;
		}
		row = newRow;

		return row;
	}

	/**
	 * Move the crocodile to a new column, if new column is within lake bounds.
	 * 
	 * @param newColumn - the column to move to.
	 * @return the column moved to. Lake boundary limits movement.
	 */
	private int moveToColumn(int newColumn) {

		if (isDead()) {
			return -1;
		}

		// System.out.println("column = " + column + ", newCOlumn = " + newColumn);
		// System.out.flush();
		// Keep the new value within lake boundary.
		if (newColumn > simulation.getLastColumn()) {
			newColumn = simulation.getLastColumn();
		} else if (newColumn < simulation.getFirstColumn()) {
			newColumn = simulation.getFirstColumn();
		}

		// I might face a new direction.
		if (newColumn < column) {
			direction = LEFT;
		} else if (newColumn > column) {
			direction = RIGHT;
		}

		column = newColumn;

		return column;
	}

	/**
	 * This individual belongs to the Crocodile species.
	 *  
	 * @return The string indicating the species
	 */
	public String getSpecies() {
		return SPECIES;
	}

	/**
	 * Crocodile should be displayed as an image.
	 * 
	 * @return a constant defined in {@link Simulation#IMAGE Simulation} class
	 */
	public String getDisplayMechanism() {
		return Simulation.IMAGE;
	}

	/**
	 * Get the image of the crocodile
	 * 
	 * @return filename of Crocodile image
	 */
	public String getImage() {
		
		if (getDirection() == RIGHT) {
			return "/Crocodile-right.gif";
		}
		if (getDirection() == LEFT) {
			return "/Crocodile-left.gif";
		}
		if (getDirection() == UP) {
			return "/Crocodile-up.gif";
		}
		if (getDirection() == DOWN) {
			return "/Crocodile-down.gif";
		}
		
		return "Crocodile-right.gif";
	}

	/**
	 * Look for food in the neighborhood. Consume some energy in the process.
	 * 
	 * @return a neighboring algae that is food.
	 */
	private Catfish lookForFoodInNeighborhood() {
		
		int neighborIndex;
		// Looking for food consumes energy.
		setEnergy(getEnergy() - ENERGY_TO_LOOK_FOR_FOOD);

		if (isDead()) {

			return null;
		}

		Vector neighbors =
			simulation.getNeighbors(getRow(), getColumn(), 1);

		for (neighborIndex = 0;
			neighborIndex < neighbors.size();
			++neighborIndex) {
			if (neighbors.get(neighborIndex) instanceof Catfish) {

				return (Catfish) neighbors.get(neighborIndex);
			}
		}

		return null;
	}


	// ******************************** Add your code here ********************************
	// ******************************** Add your code here ********************************

	/**
	 * Crocodile can wade in the lake.
	 */
	public void wadeIfPossible()
	{
		int firstRow;
		int lastRow;
		int firstColumn;
		int lastColumn;
		int newRow;
		int newColumn;
		setEnergy(getEnergy() - ENERGY_TO_WADE);

		if(isDead())
			{
			return;
			}
		else
			{
			firstRow=simulation.getFirstRow();
			lastRow=simulation.getLastRow();
			firstColumn=simulation.getFirstColumn();
			lastColumn=simulation.getLastColumn();
			newRow=simulation.getRand().nextInt(lastRow-firstRow+1);
			newColumn=simulation.getRand().nextInt(lastColumn-firstColumn+1);
			newRow+=firstRow;
			newColumn+=lastColumn;
			moveToRow(newRow);
			moveToColumn(newColumn);
			}
	}


	/**
	 * Crocodile can look for Catfish to eat in the lake.
	 */
      private void eatIfPossible()

	{
		if(isDead())
			{
			return;
			}

		Vector foodMaybe = simulation.getNeighbors(getRow(), getColumn(), 0);
			for(int neighborIndex = 0; neighborIndex < foodMaybe.size(); neighborIndex++)
				{
				if(foodMaybe.get(neighborIndex) instanceof Catfish)
					{
					Catfish alg = (Catfish)foodMaybe.get(neighborIndex);
					int energyGained = alg.getEnergy();
					setEnergy((getEnergy() + energyGained) - 1);
					return;
					}
				}
	}


	/**
	 * Crocodile lives its life. It may lose or gain energy.
	 */
	public void liveALittle()
	{

	if(isDead())
		{
		return;
		}
	else
		{
		age++;
		wadeIfPossible();
		eatIfPossible();
		minEnergy += MIN_ENERGY_GROWTH_INCREMENT;
		maxEnergy += MAX_ENERGY_GROWTH_INCREMENT;
		return;
		}

	}


}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩高清中文字幕一区| 国产亚洲人成网站| 日韩欧美国产一二三区| 亚洲精品一区二区精华| 国产精品乱码一区二区三区软件 | 亚洲午夜精品网| 亚洲成av人影院| 精品在线免费视频| 9l国产精品久久久久麻豆| 在线日韩av片| 日韩西西人体444www| 国产精品美女久久久久久久久| 亚洲影视资源网| 国产一区二区三区免费播放| 99精品欧美一区| 日韩欧美中文字幕一区| 国产精品国产自产拍高清av王其| 亚洲一区二区四区蜜桃| 久久99精品国产麻豆婷婷| 91网站在线播放| 欧美成人高清电影在线| 亚洲人成网站精品片在线观看| 日本亚洲天堂网| 99re免费视频精品全部| 日韩一区二区麻豆国产| 国产精品成人免费| 午夜av电影一区| av一区二区三区四区| 日韩一区二区在线观看| 亚洲日本一区二区三区| 国产在线精品免费av| 在线亚洲一区二区| 国产精品免费免费| 免费精品视频在线| 欧美在线视频日韩| 国产精品免费免费| 精彩视频一区二区三区| 欧美性欧美巨大黑白大战| 国产亚洲一区二区三区四区| 视频一区视频二区中文字幕| 99视频在线观看一区三区| 日韩欧美中文字幕制服| 亚洲国产毛片aaaaa无费看| 高清视频一区二区| 欧美成人性战久久| 水野朝阳av一区二区三区| 成人黄色777网| 精品久久久久久久久久久久包黑料| 亚洲免费成人av| 成人黄色一级视频| 久久久国产综合精品女国产盗摄| 亚洲国产欧美一区二区三区丁香婷| 成人h动漫精品一区二| 欧美不卡视频一区| 日日夜夜一区二区| 欧美亚洲国产一区在线观看网站 | av激情亚洲男人天堂| 精品卡一卡二卡三卡四在线| 日韩黄色免费网站| 欧美日韩成人在线| 亚洲高清在线视频| 欧美在线观看你懂的| 国产精品久久久久国产精品日日| 国产乱妇无码大片在线观看| 日韩色在线观看| 日韩和的一区二区| 欧美日韩三级一区| 亚洲电影一级片| 欧美日韩国产123区| 一区二区三区四区国产精品| 99热99精品| 国产精品乱人伦| av日韩在线网站| 国产精品久久久久影视| 懂色一区二区三区免费观看| 久久久www成人免费无遮挡大片| 久久99精品国产| 欧美α欧美αv大片| 麻豆精品在线观看| 欧美成人一级视频| 国产一区二区三区免费观看| 精品国产麻豆免费人成网站| 奇米四色…亚洲| 久久先锋资源网| 成人深夜在线观看| 亚洲丝袜精品丝袜在线| 色婷婷综合久久久久中文| 一区二区三区在线视频免费| 欧美日韩一级黄| 喷白浆一区二区| 久久这里只精品最新地址| 国产精品影音先锋| 国产精品入口麻豆原神| 色综合欧美在线视频区| 一区二区三区免费网站| 欧美中文字幕久久| 日韩av电影一区| 精品精品欲导航| 国产寡妇亲子伦一区二区| 国产精品欧美一级免费| 91片在线免费观看| 午夜精彩视频在线观看不卡| 69久久99精品久久久久婷婷| 精品亚洲porn| 国产精品久久免费看| 在线观看亚洲成人| 青青国产91久久久久久| 337p日本欧洲亚洲大胆精品| 国产成人精品免费在线| 国产精品初高中害羞小美女文| 91网站最新网址| 日韩中文字幕不卡| 26uuu欧美| 91在线播放网址| 日韩国产欧美一区二区三区| 国产视频一区二区在线| 色94色欧美sute亚洲线路一ni| 日本不卡视频在线| 国产精品国产馆在线真实露脸| 欧美日韩你懂的| 国产v日产∨综合v精品视频| 亚洲一区二区三区爽爽爽爽爽| 欧美zozozo| 色综合激情五月| 韩国精品在线观看| 亚洲精品中文字幕乱码三区| 日韩欧美亚洲另类制服综合在线| 成人动漫一区二区| 青青草国产精品97视觉盛宴| 亚洲婷婷综合色高清在线| 欧美精品一卡二卡| 99精品视频免费在线观看| 久久国内精品视频| 亚洲在线观看免费视频| 国产欧美视频在线观看| 欧美电影在哪看比较好| 成人激情视频网站| 麻豆一区二区三区| 亚洲综合色视频| 国产色婷婷亚洲99精品小说| 欧美巨大另类极品videosbest| 成人黄色av网站在线| 久久激情综合网| 亚洲国产一二三| 国产精品国产自产拍在线| 欧美tickling挠脚心丨vk| 欧美性一级生活| 不卡av电影在线播放| 激情综合一区二区三区| 亚洲午夜久久久久久久久久久| 国产精品色婷婷| 精品剧情在线观看| 欧美精品色综合| 在线视频国内一区二区| 成人黄色免费短视频| 国产麻豆精品一区二区| 免费欧美日韩国产三级电影| 亚洲自拍偷拍网站| 国产精品免费看片| 久久精品一区二区三区四区| 在线不卡欧美精品一区二区三区| 99re成人精品视频| 国产精品66部| 理论片日本一区| 强制捆绑调教一区二区| 亚洲国产精品天堂| 亚洲在线免费播放| 亚洲激情校园春色| 中文字幕+乱码+中文字幕一区| 精品国产sm最大网站| 欧美日韩国产a| 欧美性猛交一区二区三区精品| 99re成人精品视频| 国产精品资源网| 国产伦精品一区二区三区免费 | 91精品国产福利| 欧美亚洲国产一区在线观看网站| 色综合网站在线| 91麻豆成人久久精品二区三区| 色综合色综合色综合色综合色综合 | 色呦呦国产精品| 91片在线免费观看| 91色视频在线| 色久优优欧美色久优优| 不卡的电影网站| 97久久精品人人做人人爽50路| 成人免费视频视频在线观看免费| 国产美女视频91| 国产精品综合网| 高清视频一区二区| 成人av网址在线| 国产成人在线免费观看| 国产精品一区一区| 国产不卡免费视频| 成人免费av网站| thepron国产精品| 91香蕉视频污在线| 欧美午夜影院一区| 91精品国产乱码久久蜜臀| 91精品国产综合久久久蜜臀粉嫩 |