Reputation: 153
So i'm trying to make a maze with generic classes and interfaces and Im not quite sure where i've gone wrong. My main problem is how to complete my constructor because its the first time I have a class as a parameter.
This is my first post so I apologies if it's bad.
import java.awt.Color;
public class Labyrinth implements ILabyrinth {
private int height;
private int width;
**********************************************
public Labyrinth(IGrid<LabyrinthTile> tiles){
tiles.copy();
this.height=height;
this.width=width; <---Here?
**********************************************
}
@Override
public LabyrinthTile getCell(int x, int y) {
return getCell(x,y);
}
@Override
public Color getColor(int x, int y) {
return getCell(x,y).getColor();
}
@Override
public int getHeight() {
return height;
}
@Override
public int getPlayerGold() {
return 0;
}
@Override
public int getPlayerHitPoints() {
return 0;
}
@Override
public int getWidth() {
return width;
}
@Override
public boolean isPlaying() {
return true;
}
@Override
public void movePlayer(Direction dir) throws MovePlayerException {
if(dir.equals(Direction.EAST)){
width+=1;
}
if(dir.equals(Direction.NORTH)){
height+=1;
}
if(dir.equals(Direction.SOUTH)){
height-=1;
}
if(dir.equals(Direction.WEST)){
width-=1;
}
}
@Override
public boolean playerCanGo(Direction d) {
if(d.equals(LabyrinthTile.WALL))
return false;
return true;
}
}
Upvotes: 0
Views: 64
Reputation: 134
When you type the following:
this.height = height;
You are saying that you want to set the "height" field of the new object you're trying to create to a variable called "height." But your constructor doesn't have a variable named "height" anywhere in the constructor or as one of the constructor's arguments. You want something like the following:
// .height() might not be a real method, it's just an example
this.height = tiles.height();
That will work because you have a variable named "tiles" passed into the constructor.
Upvotes: 1