0 Replies - 9703 Views - Last Post: 04 April 2012 - 11:44 PM Rate Topic: -----

#1 sjsharksboy95  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-April 12

gridworld help

Posted 04 April 2012 - 11:44 PM

FirstInitial Programming Assignment:
Create a BUG similar to the ZBug you are asked to create in Part2. Create a BUG that writes your firstname’s initial (B, in my case-BBug) .
Write a class that implements Bug to writes your first name’s initial. Your firstname’sinitial Bug should be a subclass of BUG. Therefore, use the inherited variables and methods of the Bug class. You may add some instance variables, only if absolutely necessary. Also, try to get as close as you can to making it look like the actual letter. SUBMIT, code and output

Save your class (firstnameInitialBug) in my case it would be: BBug
Save your runner class( firstnameIntialBugRunner) in my case it would be : BBugRunner

so i basically know how to do it for z, what do i do for j. like i need help on what i would do so that it goes in a direction of a backwards L.


import info.gridworld.actor.Bug; 
import info.gridworld.grid.Location; 

public class ZBug extends Bug 
{ 
  private int length; 
  private int amountSteps; 
  private int segment; 

  public ZBug(int length1) 
  { 
    setDirection(Location.EAST); 
    amountSteps = 0; 
    segment = 1; 
    length = length1; 
  } 
  public void act() 
  { 
    if (segment <= 3 && amountSteps <length) 
    { 
      if (canMove()) 
      { 
        move(); 
        amountSteps++; 
      } 
    } 
    else if (segment == 1) 
    { 
      setDirection(Location.SOUTHWEST); 
      amountSteps = 0; 
      segment++; 
    } 
    else if (segment == 2) 
    { 
      setDirection(Location.EAST); 
      amountSteps = 0; 
      segment++; 
    } 
  } 
}

This post has been edited by Atli: 05 April 2012 - 12:04 AM
Reason for edit:: Please use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1