1 Replies - 1764 Views - Last Post: 12 December 2013 - 02:52 PM Rate Topic: -----

#1 Atdhe Bekteshi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-December 13

Java gridworld critter bug kamikaze teleport eat

Posted 12 December 2013 - 02:44 PM

Hello, I hope anybody can help me with this. I'm trying to make a critter called KamikazeCritter. Basically what this critter does it teleports randomly around the grid and when other bug get near it explodes. The explosion means eats them and eats himself. So I have my code so far, and it is working well but it explodes immediately and everything on gridworld disappears. I want the critter to have an explosion and eat bugs that are all around him within one space. So If my critter is in middle and surrounded by critters and bugs in all the poles: north , east , south and west it would eat all of them and remove itself from the grid. That would look like an explosion. If someone could help me I would appreciate it.
Here is my code so far:

import info.gridworld.actor.*;
import info.gridworld.grid.*;
import java.util.Random;
import java.awt.Color;
import java.util.ArrayList;
public class KamikazeCritter extends Critter
{
  Location nextTeleport;
  public KamikazeCritter()
  {
    super();
  }
  public ArrayList<Actor>getActors() {
      ArrayList<Actor> actors = new ArrayList<Actor>();  
      for (Location loc : getGrid().getOccupiedLocations()) { 
      if (!loc.equals(this.getLocation())) { 
      actors.add(getGrid().get(loc)); 
      } 
      } 
      
      return actors; 
  }
  public void processActors(ArrayList<Actor> toBeBurninated){
	       Grid<Actor> gr = this.getGrid();
	       for(int i=0;i<toBeBurninated.size();i++){
	           Actor current = toBeBurninated.get(i);
	           current.removeSelfFromGrid();
	       }
	       removeSelfFromGrid() ;
  }
  public Location selectMoveLocation(ArrayList<Location> locs) {
	Boolean currentState = false;
	Random ran = new Random();
	
	while (currentState == false)
	{
	  
	  int row = ran.nextInt(getGrid().getNumRows());
	  int col = ran.nextInt(getGrid().getNumCols());
	  
	  nextTeleport = new Location(row,col);
	  
	  if (!(getGrid().isValid(nextTeleport) == false))
		currentState = true;
	}
	
	return nextTeleport;
  }
  public void makeMove(Location loc)
  {
	if (getGrid().get(loc) != null)
	{
	  Actor occupant = getGrid().get(loc);
	  
	  Location originalLoc = getLocation();
	  
	  occupant.removeSelfFromGrid();
	  
	  moveTo(loc);
	  
	  occupant.putSelfInGrid(getGrid(), originalLoc);
	  
	  occupant.setColor(getColor());
	}
	else
	  moveTo(loc);
  }
}


if you get rid of the getActors and process actors methods, my critter would just teleport, so I have that done. But I don't know how to make the explosion.

This post has been edited by macosxnerd101: 12 December 2013 - 02:52 PM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Java gridworld critter bug kamikaze teleport eat

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10185
  • View blog
  • Posts: 37,603
  • Joined: 27-December 08

Re: Java gridworld critter bug kamikaze teleport eat

Posted 12 December 2013 - 02:52 PM

Moved to GridWorld. Also, please remember to use code tags: :code:.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1