1 / 12

Movement

Movement. Fixed Movement setLocation (x, y) Makes the crab move to a fixed cell x,y Relative Movement The functions: getX () getY () Fetch the x and y coordinate of the crab’s present location. We can use this!.

emile
Download Presentation

Movement

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Movement

  2. Fixed Movement setLocation (x, y) Makes the crab move to a fixed cell x,y Relative Movement The functions: getX() getY() Fetch the x and y coordinate of the crab’s present location. We can use this!

  3. Look at the following function call:setLocation (getX(), getY()+1)In which direction will the crab move? • North • South • East • West

  4. Movement Method Call

  5. Turning Parameter What happens to the crab if you use a negative number?

  6. Standard Java Class Import (Library) Statements Class Signature Method Signature

  7. Functions and Methods A function is a named sequence of statements that performs a desired operation. This operation is specified in a function definition. NAME( LIST OF PARAMETERS ): STATEMENTS There can be any number of statements inside the function, but they have to be indented from the left margin. Creating a new function gives you an opportunity to name a group of statements. Functions can simplify a program by hiding a complex computation behind a single command and by using English words in place of arcane code. Creating a new function can make a program smaller by eliminating repetitive code.

  8. Look at the following class:

  9. How many other functions does the function act() call in its statements? • One • Two • Three • Four +

  10. Look at the following class:

  11. Method Call This conditional statement uses a built in function to turn an object if it hits the edge of the world. Method Body Method Call

  12. Function (or Method) Call The value or variable, which is called the argument of the function, has to be enclosed in parentheses. It is common to say that a function “takes” an argument and “returns” a result. The result is called the return value. turn (angle);

More Related