4 Replies - 8144 Views - Last Post: 08 March 2012 - 05:56 PM Rate Topic: -----

#1 xmsk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 12

fifteen - grid world - how can i make the world to receive my click?

Posted 07 March 2012 - 04:27 AM

these are the codes that i came up with
basically, the first one is the tile
the second one is the grid with the tiles filled in
the third one is the world that is designed to receive my click
and the last one is the main which i add the grid to the world and run the world

my problem is that i can not get the Locationclicked method to work

i believe that making it to return true should make it receive my click, but nope :(
i still just get the list of the methods of the tile


import info.gridworld.grid.Location;


public class Tile{
	private int k;
	private Location q;
	
	public Tile(int num, Location loc){
		k = num;
		q = loc;
	}
	
	public int getInt(){
		return k;
	}
	
	public Location getLocation(){
		return q;
	}
	
	public String toString(){
		String sk = String.valueOf(k);
		return sk;
	}
}



import info.gridworld.grid.BoundedGrid;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

import java.util.ArrayList;
import java.util.Random;

public class Fifteen{
	private BoundedGrid t;
	private ArrayList<Tile> tile = new ArrayList<Tile>();
	private int count = 1, select, a = 0, b = 0;
	private Random generator = new Random();
	
	public Fifteen(int k){
		t = new BoundedGrid(k, k);
		for(int q = 0;q < k;q ++){
			for(int w = 0;w < k;w ++){
				tile.add(new Tile(count, new Location(q, w)));
				count ++;
			}
		}
		tile.remove(15);
		for(int q = 0;q < k * k - 1;q ++){
			select = generator.nextInt(tile.size());
			t.put(new Location(a, B)/>, tile.get(select));
			tile.remove(select);
			b ++;
			if(b == 4){
				b = 0;
				a ++;
			}
		}
	}
	
	public Grid getGrid(){
		return t;
	}
}




import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;
import info.gridworld.world.World;

import java.util.ArrayList;


public class TileWorld extends World<Tile>{
	
	public TileWorld(Grid<Tile> gr){
		super(gr);
	}
	
	public boolean locationclicked(Location loc)
    {
    	Grid<Tile> t = getGrid();
    	
    	ArrayList<Location> a = t.getEmptyAdjacentLocations(loc);
		
    	t.put(a.get(0), t.remove(loc));
    	
        return true;
    }
}




import info.gridworld.actor.Actor;
import info.gridworld.actor.Bug;
import info.gridworld.grid.Location;
import info.gridworld.world.World;

 


public abstract class AP {
	public static void main(String[] args){
		Fifteen board = new Fifteen(4);
		
		TileWorld game = new TileWorld(board.getGrid());
		
		
		game.show();
		
	}
}




Is This A Good Question/Topic? 0
  • +

Replies To: fifteen - grid world - how can i make the world to receive my click?

#2 wrightm96  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 51
  • Joined: 06-March 12

Re: fifteen - grid world - how can i make the world to receive my click?

Posted 07 March 2012 - 11:30 AM

Your error is in the TileWorld class, the locationclicked method. It should say

public boolean locationclicked(Location loc)



instead of
public boolean locationclicked(Location loc)



You forgot to capitalize "Clicked"

Opps. I meant
public boolean locationclicked(Location loc)



Sorry about so many posts, but you just need to capitalize "Clicked" in the method.
Was This Post Helpful? 0
  • +
  • -

#3 xmsk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 12

Re: fifteen - grid world - how can i make the world to receive my click?

Posted 07 March 2012 - 07:50 PM

View Postwrightm96, on 07 March 2012 - 11:30 AM, said:

Your error is in the TileWorld class, the locationclicked method. It should say

public boolean locationclicked(Location loc)



instead of
public boolean locationclicked(Location loc)



You forgot to capitalize "Clicked"

Opps. I meant
public boolean locationclicked(Location loc)



Sorry about so many posts, but you just need to capitalize "Clicked" in the method.

Was This Post Helpful? 0
  • +
  • -

#4 xmsk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 12

Re: fifteen - grid world - how can i make the world to receive my click?

Posted 07 March 2012 - 07:54 PM

View Postwrightm96, on 07 March 2012 - 11:30 AM, said:

Your error is in the TileWorld class, the locationclicked method. It should say

public boolean locationclicked(Location loc)



instead of
public boolean locationclicked(Location loc)



You forgot to capitalize "Clicked"

Opps. I meant
public boolean locationclicked(Location loc)



Sorry about so many posts, but you just need to capitalize "Clicked" in the method.


sorry for the other two replys... it was my first time using this site so i didnt' really know what i was doing
anyways i'll try that as soon as i get home(which i think would work...)
thanks
Was This Post Helpful? 0
  • +
  • -

#5 wrightm96  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 51
  • Joined: 06-March 12

Re: fifteen - grid world - how can i make the world to receive my click?

Posted 08 March 2012 - 05:55 PM

No problem. I'm in the same boat (I think) as you. I'm in APCS this year.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1