Results 1 to 2 of 2
  1. #1
    Samirjthe2nd is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Default help with gridworld?

    I'm trying to make a "Pawn" in gridworld ... i have some ways to go but for now I just want it to show up on the grid... whenever i run the file it says

    C:\Users\Samir\javaprograms\chess\GameRunner.java: 13: cannot access Pawn
    bad class file: C:\Users\Samir\javaprograms\chess\Pawn.java
    file does not contain class Pawn
    Please remove or make sure it appears in the correct subdirectory of the classpath.
    world.add(new Location(1, 1), new Pawn());

    the code for the Pawn is this:
    Java Code:
    package info.gridworld.actor;
    import info.gridworld.grid.Location;
    import java.util.ArrayList;
    import info.gridworld.grid.Grid;
    import java.awt.Color;
    
    
    public class Pawn extends Critter
    {
    	public Grid<Pawn> grid;
        public Location location;
        public int direction;
        public Color color;
    
    	public Pawn()
    	{
    		color = Color.WHITE;
    		direction = Location.NORTH;
    		grid = null;
            location = null;
    	}
    	 public void act()
        {
            if (getGrid() == null)
                return;
            ArrayList<Actor> actors = getActors();
            processActors(actors);
            ArrayList<Location> moveLocs = getMoveLocations();
            Location loc = selectMoveLocation(moveLocs);
            makeMove(loc);
        }
     public ArrayList<Location> getMoveLocations()
        {
        	ArrayList<Location> locs = new ArrayList();
        	locs.add(getLocation().getAdjacentLocation(direction));
            return locs;
        }
        
        public Location selectMoveLocation(ArrayList<Location> locs)
        {
            int n = locs.size();
            if (n == 0)
                return getLocation();
            for(Location a: locs)
          		if ((a.compareTo(getLocation())<2))
          			return a;
          		return getLocation();
        }
        public void makeMove(Location loc)
        {
            if (loc == null)
                removeSelfFromGrid();
            else
                moveTo(loc);
        }
    	
    }
    Idk if this matters or not... but java is not making a .class for this prog whenever i run it for some reason... help please.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    You declare Pawn to be part of the info.gridworld.actor package. But you the have the source file in C:\Users\Samir\javaprograms\chess\ next to GameRunner.java. The two things - package and directory location - have to match.

    Put Pawn.java at the same place as Critter.java (next to GameRunner.java?) and see what happens, and make the package declarations the same for both classes. If you continue to hit problems describe the exact layout of the files involved in this program. And the commands you are using to compile and run the program.

Similar Threads

  1. Object Construction ends Program in GridWorld
    By BJ1110 in forum Advanced Java
    Replies: 9
    Last Post: 02-04-2011, 04:02 PM
  2. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  3. Need gridworld help
    By robertbob in forum New To Java
    Replies: 2
    Last Post: 05-03-2010, 05:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •