Question: Need help on program homework, java only please...... Create a BattleBug class that extends the AbstractBattleBug class provided. Your class should override the setBattleBugDirection() method.
Need help on program homework, java only please......
Create a BattleBug class that extends the AbstractBattleBug class provided. Your class should override the setBattleBugDirection() method. In this method, your job is to set the direction of your BattleBug (i.e., which direction it is facing). Your bug will be automatically moved to the adjacent square in the direction it is pointing only of this is a legal move (i.e., there is an empty cell there). If your bug cannot move, it will be removed from the grid. Your BattleBug will be pitted against another BattleBug. You will start in a random location in the grid. As your bug moves, it leaves a rock in its wake. The object of the battle is for your BattleBug to outlast your opponent's BattleBug, Since you only drop rocks when you have a legal move, the bug with the most rocks dropped wins. All battles will be best 2 out of 3. For a winner to be declared in a battle, the winning bug must have at least 2 more rocks than the loser. ADDITIONAL RULES: No moving your bug from one location to another No dropping rocks or other objects (this is done automatically) No changing the state of your opponent's bug
___Abstract BattleBug.java___
package battle; import info.gridworld.actor.Actor; import info.gridworld.actor.Bug; import info.gridworld.actor.Flower; import info.gridworld.actor.Rock; import info.gridworld.grid.Grid; import info.gridworld.grid.Location;
public abstract class AbstractBattleBug extends Bug { private Rock aRock = null; private int rockCounter = 0; protected abstract String getName(); private int getRockCounter() { return rockCounter; } private void setRockCounter(int rockCounter) { this.rockCounter = rockCounter; } @Override public void act() { setBattleBugDirection(); if(canMove()){ move(); }else{ removeSelfFromGrid(); StringBuffer buf = new StringBuffer(); buf.append("Final rock count for "); buf.append(getName()); buf.append(": "); buf.append(getRockCounter()); System.out.println(buf); } } @Override public void move() { Grid
protected abstract void setBattleBugDirection(); }
_
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
