Need help implementing this in Java Walls shall be white, they shall not move or
ID: 3825766 • Letter: N
Question
Need help implementing this in Java
Walls shall be white, they shall not move or do anything with their cell, and they shall not be passable. We shall represent walls in text files with a '#'.
An impassable state with the color White. Doesn't do anything. A "#" in the map file.
Constructor Summary
Method Summary
Get the current color of the state (can be used for drawing).
Updates the cell based off of the state.
Get whether or not the cell is passable.
Get the character representation for this State.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
Wall
Method Detail
handle
Description copied from interface: State
Updates the cell based off of the state. This method can update the cell's state, or potentially another cell's state depending on the implementation.
Specified by:
handle in interface State
Parameters:
cell - The cell that this state belongs to
getColor
Description copied from interface: State
Get the current color of the state (can be used for drawing).
Specified by:
getColor in interface State
Returns:
The color of the state
isPassable
Description copied from interface: State
Get whether or not the cell is passable. Affects whether or not a state can move through another state via random movement or moving closer to the mouse.
Specified by:
isPassable in interface State
Returns:
true iff the state is passable
See Also:
Cell.getRandomOpen(), Cell.getRandomCloser()
toChar
Description copied from interface: State
Get the character representation for this State. Used for loading map text files.
Specified by:
toChar in interface State
Returns:
character representation for this State
Constructors Constructor and Description Wall()Explanation / Answer
Implemented based on given inputs:
Interface State.java
import java.awt.Color;
/*
* State Interface
*/
public interface State {
public Color getColor();
public boolean isPassable();
public char toChar();
}
Class Wall.java
import java.awt.Color;
/*
* Wall class that extends Object and implements state
*/
import javafx.scene.control.Cell;
public class Wall extends Object implements State {
private Color color;
private boolean passable;
public Wall(){
color=Color.WHITE;//Walls shall be white
passable=false;//they shall not be passable.
}
@Override
public Color getColor() {
return color;
}
@Override
public boolean isPassable() {
return passable;
}
@Override
public char toChar() {
return '#';//We shall represent walls in text files with a '#'
}
public void handle(Cell cell){
}
}
Test class with main method:
WallTest.java
public class WallTest {
public static void main(String[] args) {
Wall wall=new Wall();
System.out.println("Wall color...."+wall.getColor());
System.out.println("Is Wall Passable....."+wall.isPassable());
System.out.println("Wall char..."+wall.toChar());
}
}
sample output:
Wall color....java.awt.Color[r=255,g=255,b=255]
Is Wall Passable.....false
Wall char...#
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.