Tuesday, October 25, 2011

Challenge 022

import info.gridworld.actor.ActorWorld; //First you need to import all the gridowrld files
import info.gridworld.grid.Grid;
import java.awt.Color;
import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;

public class GWTest {
public static void main(String[] args) {
ActorWorld Overgrown = new ActorWorld(); //This names and creates the world in which the bugs are a part of
Bug Yellow = new Bug(Color.YELLOW); // This creates a bug that is yellow
Yellow.setDirection(Location.SOUTHWEST); // This sets the bug to be pointed in the southwest direction
Location Y = new Location(5,4); // This sets the yellow bug to the grid coordinate (5,4)
Overgrown.add(Y, Yellow); // This adds the yellow bug to the grid
Bug Magenta = new Bug(Color.MAGENTA); // This creates a bug that is yellow
Magenta.setDirection(Location.SOUTHEAST); // This sets the bug to be pointed in the southeast direction
Location M = new Location(5,5); // This sets the magenta bug to the grid coordinate (5,5)
Overgrown.add(M, Magenta); // This adds the magenta bug to the grid
Bug Blue = new Bug(Color.BLUE); // This creates a bug that is blue
Blue.setDirection(Location.NORTHEAST); // This sets the bug to be pointed in the northeast direction
Location B = new Location(4,5); // This sets the blue bug to the grid coordinate (4,5)
Overgrown.add(B, Blue); // This adds the blue bug to the grid
Bug Green = new Bug(Color.GREEN); // This creates a bug that is green
Green.setDirection(Location.NORTHWEST); // This sets the bug to be pointed in the northwest direction
Location G = new Location(4,4); // This sets the freen bug to the frid coordinate (4,4)
Overgrown.add(G, Green); // This adds the green bug to the grid
Overgrown.show(); // THis allows you to view the world
}
}

4 comments:

  1. Hi Ryan, one item of follow-up regarding your code:

    Consider,

    Overgrown.add(Y, Yellow);

    How many parameters are required by the add method and what types of data are they?

    Thank you.

    ReplyDelete
  2. The overloaded add method is used to place bugs into the grid of the ActorWorld. The add method has an actor parameter and a location parameter that places the bug at the desired location. Two parameters are required because when the add method has an actor parameter, but no location parameter, it place the bug at any random location. Therefore, this specific add method requires 2 parameters, an Actor and location. there is a total of 8 parameters for add because there are 2 per bug and we have four bugs.

    And for the types of data, they are overloads???

    ReplyDelete
  3. Hi Ryan,

    I will selectively pull out this part of your analysis:

    "The add method has an actor parameter and a location parameter that places the bug at the desired location. Two parameters are required because when the add method has an actor parameter, but no location parameter, it places the bug at any random location. "

    Not only is this technically accurate, but it answers the challenge perfectly. Well done.

    In terms of method overloading, which is what other areas of your analysis touch on, and also the concept you're asking about, there will be challenges in the near future that delve into that concept.

    ReplyDelete
  4. Oh yes, not to forget, 60XPs awarded for this completion.

    ReplyDelete