Professional Documents
Culture Documents
com
Row = 0
Column = 0
rows
A grid is a
structure that
has rows and
columns.
cols
A+ Computer Science - www.apluscompsci.com
Row = 2
Column = 1
Location
frequently used methods
Name
Use
Location(row, col)
getCol()
getRow()
import info.gridworld.grid.Location;
OUTPUT
The Location class
stores row and column
information.
A+ Computer Science - www.apluscompsci.com
(3, 5)
3
5
reference variable
Location theLoc = new Location(3,4);
object instantiation
reference
command / method
theLoc.getRow();
Location
frequently used fields
Name
Use
NORTH
SOUTH
EAST
WEST
import info.gridworld.grid.Location;
NORTH - 0
WEST - 270
Dude
SOUTH - 180
A+ Computer Science - www.apluscompsci.com
EAST - 90
System.out.println(Location.NORTH);
System.out.println(Location.SOUTH);
System.out.println(Location.EAST);
System.out.println(Location.WEST);
OUTPUT
0
180
90
270
A+ Computer Science - www.apluscompsci.com
Location
frequently used methods
Name
Use
getAdjacentLocation(dir)
getDirectionToward(dest)
compareTo(thang)
equals(thang)
import info.gridworld.grid.Location;
0,1
0,2
0,3
0,4
1,0
1,1
1,2
1,3
1,4
2,0
2,1
2,2
2,3
2,4
3,0
3,1
3,2
3,3
3,4
OUTPUT
(1, 1)
(3, 1)
(2, 2)
(2, 0)
45
OUTPUT
false
1
-1
A+ Computer Science - www.apluscompsci.com
Actor
frequently used methods
Name
Use
Actor()
act()
getColor()
getDirection()
getLocation()
setColor(col)
setDirection(dir)
moveTo(loc)
When you
click on
an actor,
a list of
methods
is shown.
What does an
Actor do when
its act() method
is called ?
Actor
frequently used methods
Name
Use
getGrid()
toString()
import info.gridworld.actor.Actor;
A+ Computer Science - www.apluscompsci.com
chucky.putSelfInGrid(grid, loc);
A+ Computer Science - www.apluscompsci.com
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
cols
A+ Computer Science - www.apluscompsci.com
World is used to
show the grid
graphically.
Grid
Use
get(loc)
getNumCols()
getNumRows()
isValid(loc)
put(loc, obj)
remove(loc)
import info.gridworld.grid.Grid;