Exercise : Ants and Chips
0. REFERENCE
Thinks of a variable as a BOX
DECLARE a variable of type Apple at the BEGINNING of the class
public static Apple myApple ;
INITIALIZE a variable of type Apple in the CONSTRUCTOR or POPULATE method
myApple = new Apple();
ADD apple in the WORLD in the POPULATE method
addObject(myApple, 100,100);
MOVE things around
myApple.setLocation(getX(), getY()+100)
1. DECLARE.... save space for a variable
DECLARE all the variables we need at the beginning of the class in ChipsWorld class
- variable doritos of type Chips.
- variable lays of type Chips.
- variable redAnt of type Ant
- variable blackAnt of type Ant
2. INITIALIZE .... put something in the variable
INITIALIZE all the variables that we need in the CONSTRUCTOR or POPULATE method in the ChipsWorld class
- initalize doritos
- initialize lays
- initalize redAnt
- initialize blackAnt
3. POPULATE THE WORLD ... add stuff to the world so that we can see it!
AddObjects in the POPULATE method in the ChipsWorld class
- addObject doritos in position (50,100)
- addObject lays in position (200,400)
- addObject redAnt in position (300,500)
- addObject blackAnt in position (25,100)
4. MOVE Objects around
set Location of redAnt to be right below doritos
set Location of lays to be to the right of blackAnt
5. QUESTIONS
doritos, lays are objects of the class Chips.
redAnt and blackAnt are objects of the class Ant
will doritos and lays look the same ? will redAnt and blackAnt look the same ?
can i say Chips.setLocation();
can i say doritos.setLocation();
Sometimes you will not remember the syntax for some method. You can go to the Greenfoot Actor or World class, and click on the upper right drop down menu to display Documentation. Here you can see all the methods that the class has and an explanation about what they do.
6. IMPORTANT : Blog Question :
go to : http://www.p4games.org/node/392
and answer the blogging question. please make your blog private !
7. Extra :
in the Chips class :
make the ants follow the chips.
Follow the instructions in gray, these are comments.
You need to code these instructions so that greenfoot understands it.