📄 fish.html
字号:
<A NAME="Fish(Environment, Location, Direction)"><!-- --></A><H3>Fish</H3><PRE>public <B>Fish</B>(<A HREF="Environment.html">Environment</A> env, <A HREF="Location.html">Location</A> loc, <A HREF="Direction.html">Direction</A> dir)</PRE><DL><DD>Constructs a fish at the specified location and direction in a given environment. The Fish is assigned a random color. (Precondition: parameters are non-null; <code>loc</code> is valid for <code>env</code>.)<DD><DL><DT><B>Parameters:</B><DD><CODE>env</CODE> - environment in which fish will live<DD><CODE>loc</CODE> - location of the new fish in <code>env</code><DD><CODE>dir</CODE> - direction the new fish is facing</DL></DD></DL><HR><A NAME="Fish(Environment, Location, Direction, java.awt.Color)"><!-- --></A><H3>Fish</H3><PRE>public <B>Fish</B>(<A HREF="Environment.html">Environment</A> env, <A HREF="Location.html">Location</A> loc, <A HREF="Direction.html">Direction</A> dir, java.awt.Color col)</PRE><DL><DD>Constructs a fish of the specified color at the specified location and direction. (Precondition: parameters are non-null; <code>loc</code> is valid for <code>env</code>.)<DD><DL><DT><B>Parameters:</B><DD><CODE>env</CODE> - environment in which fish will live<DD><CODE>loc</CODE> - location of the new fish in <code>env</code><DD><CODE>dir</CODE> - direction the new fish is facing<DD><CODE>col</CODE> - color of the new fish</DL></DD></DL><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="randomColor()"><!-- --></A><H3>randomColor</H3><PRE>protected java.awt.Color <B>randomColor</B>()</PRE><DL><DD>Generates a random color.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the new random color</DL></DD></DL><HR><A NAME="id()"><!-- --></A><H3>id</H3><PRE>public int <B>id</B>()</PRE><DL><DD>Returns this fish's ID.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the unique ID for this fish</DL></DD></DL><HR><A NAME="environment()"><!-- --></A><H3>environment</H3><PRE>public <A HREF="Environment.html">Environment</A> <B>environment</B>()</PRE><DL><DD>Returns this fish's environment.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the environment in which this fish lives</DL></DD></DL><HR><A NAME="color()"><!-- --></A><H3>color</H3><PRE>public java.awt.Color <B>color</B>()</PRE><DL><DD>Returns this fish's color.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the color of this fish</DL></DD></DL><HR><A NAME="location()"><!-- --></A><H3>location</H3><PRE>public <A HREF="Location.html">Location</A> <B>location</B>()</PRE><DL><DD>Returns this fish's location.<DD><DL><DT><B>Specified by: </B><DD><CODE><A HREF="Locatable.html#location()">location</A></CODE> in interface <CODE><A HREF="Locatable.html">Locatable</A></CODE></DL></DD><DD><DL><DT><B>Returns:</B><DD>the location of this fish in the environment</DL></DD></DL><HR><A NAME="direction()"><!-- --></A><H3>direction</H3><PRE>public <A HREF="Direction.html">Direction</A> <B>direction</B>()</PRE><DL><DD>Returns this fish's direction.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the direction in which this fish is facing</DL></DD></DL><HR><A NAME="isInEnv()"><!-- --></A><H3>isInEnv</H3><PRE>public boolean <B>isInEnv</B>()</PRE><DL><DD>Checks whether this fish is in an environment.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD><code>true</code> if the fish is in the environment (and at the correct location); <code>false</code> otherwise</DL></DD></DL><HR><A NAME="toString()"><!-- --></A><H3>toString</H3><PRE>public java.lang.String <B>toString</B>()</PRE><DL><DD>Returns a string representing key information about this fish.<DD><DL><DT><B>Overrides:</B><DD><CODE>toString</CODE> in class <CODE>java.lang.Object</CODE></DL></DD><DD><DL><DT><B>Returns:</B><DD>a string indicating the fish's ID, location, and direction</DL></DD></DL><HR><A NAME="act()"><!-- --></A><H3>act</H3><PRE>public void <B>act</B>()</PRE><DL><DD>Acts for one step in the simulation.<DD><DL></DL></DD></DL><HR><A NAME="breed()"><!-- --></A><H3>breed</H3><PRE>protected boolean <B>breed</B>()</PRE><DL><DD>Attempts to breed into neighboring locations.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD><code>true</code> if fish successfully breeds; <code>false</code> otherwise</DL></DD></DL><HR><A NAME="generateChild(Location)"><!-- --></A><H3>generateChild</H3><PRE>protected void <B>generateChild</B>(<A HREF="Location.html">Location</A> loc)</PRE><DL><DD>Creates a new fish with the color of its parent.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>loc</CODE> - location of the new fish</DL></DD></DL><HR><A NAME="move()"><!-- --></A><H3>move</H3><PRE>protected void <B>move</B>()</PRE><DL><DD>Moves this fish in its environment.<DD><DL></DL></DD></DL><HR><A NAME="nextLocation()"><!-- --></A><H3>nextLocation</H3><PRE>protected <A HREF="Location.html">Location</A> <B>nextLocation</B>()</PRE><DL><DD>Finds this fish's next location. A fish may move to any empty adjacent locations except the one behind it (fish do not move backwards). If this fish cannot move, <code>nextLocation</code> returns its current location.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the next location for this fish</DL></DD></DL><HR><A NAME="emptyNeighbors()"><!-- --></A><H3>emptyNeighbors</H3><PRE>protected java.util.ArrayList <B>emptyNeighbors</B>()</PRE><DL><DD>Finds empty locations adjacent to this fish.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>an ArrayList containing neighboring empty locations</DL></DD></DL><HR><A NAME="changeLocation(Location)"><!-- --></A><H3>changeLocation</H3><PRE>protected void <B>changeLocation</B>(<A HREF="Location.html">Location</A> newLoc)</PRE><DL><DD>Modifies this fish's location and notifies the environment.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>newLoc</CODE> - new location value</DL></DD></DL><HR><A NAME="changeDirection(Direction)"><!-- --></A><H3>changeDirection</H3><PRE>protected void <B>changeDirection</B>(<A HREF="Direction.html">Direction</A> newDir)</PRE><DL><DD>Modifies this fish's direction.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>newDir</CODE> - new direction value</DL></DD></DL><HR><A NAME="die()"><!-- --></A><H3>die</H3><PRE>protected void <B>die</B>()</PRE><DL><DD>Removes this fish from the environment.<DD><DL></DL></DD></DL><!-- ========= END OF CLASS DATA ========= --><HR><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_bottom"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_bottom_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="overview-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>AP® Computer Science Marine Biology Simulation</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="Environment.html"><B>PREV CLASS</B></A> <A HREF="Locatable.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="Fish.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><i>Copyright© 2002 College Entrance Examination Board</i></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -