Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The user starts at location (1, 2). Directly across the room from the user is a door. The door may be blocked by 0, 1,

The user starts at location (1, 2). Directly across the room from the user is a door. The door may be blocked by 0, 1, or 2 force fields. The frame of the door identifies which force field is currently blocking it: a red frame means that only the red force field is on, a yellow frame means that only the yellow force field is on, an orange frame means that both force fields are on, and a green frame means that both fields are off.

Depending where the user steps in the room one of the force fields will either turn on or off. The goal of the puzzle is to cross the room (i.e., reach position (1,0)) facing the door with both force fields off (i.e., a green frame).image text in transcribedimage text in transcribedimage text in transcribed

This class allows a user to walk around in a virtual 3x3 room and solve a puzzle. The room has nine locations with the following (x, y) coordinates (0, 0) (1, 0) (2, 0) (0, 1) (1, 1) (2, 1) (0, 2) (1, 2) (2, 2) The user starts at location (1, 2). Directly across the room from the user is a door. The door may be blocked by 0, 1, or 2 force fields. The frame of the door identifies which force field is currently blocking it: a red frame means that only the red force field is on, yellow frame means that only the yellow force field is on, an orange frame means that both force fields are on, and a green frame means that both fields are off. Depending where the user steps in the room one of the force fields will either turn on or off. The goal of the puzzle is to cross the room (i.e., * reach position (1,0)) facing the door with both force fields off (i.e., a green frame) The constructor and the methods of this class are incomplete. The comments tell you what is missing. You do not need to add any fields to this class. * You do not need to change any of the other classes in this project. */ public class Puzzle { V/Your current xy position in the room private int xPosition : private int yPosition; V/Boolean variables that tell you whether or not the red and yellow //force fields are currently turned on (true) or off (false). private boolean yellowField; private boolean redField; private View view; public Puzzle { * * Finish: Initialize xPosition and yPosition to reflect that your * initial position in the puzzle is (1,2) and that both force fields * are initially off. */ view = new View(); view.display(xPosition, yPosition, yellowField, redField); public void move forward() { * Finish: Implement this method that moves you forward in the room * if there is not a wall blocking you. Otherwise print a message * alerting the user that this move is not permitted now. * If the move is allowed then you should call toggleFields() and * view.display ( xPosition, yPosition, yellowField, redField) afterward. * } public void move Backward() { * * Finish: Implement this method that moves you backward in the room * if there is not a wall blocking you. Otherwise print a message * alerting the user that this move is not permitted now. * * If the move is allowed then you should call toggleFields() and * view.display(xPosition, yPosition, yellowField, redField) afterward. */ } public void moveLeft() { * * Finish: Implement this method that moves you to the left in the room * if there is not a wall blocking you. Otherwise print a message * alerting the user that this move is not permitted now. * * If the move is allowed then you should call toggleFields) and * view.display (xPosition, yPosition, yellowField, redField) afterward. * */ } public void moveRight() /* * Finish: Implement this method that moves you right in the room * if there is not a wall blocking you. Otherwise print a message * alerting the user that this move is not permitted now. * If the move is allowed then you should call toggleFields() and * view.display(xPosition, yPosition, yellowField, redField) afterward. * */ } private void toggleFields() { * * Finish: Implement this method that turns a field on or off depending * on where you step. The following table describes the coordinate system * and the effect of stepping in a particular location. * The x coordinate of a location is its row number, and the y coordinate * is its column number. * column numbers 0 1 2. * * r row numbers Or 1 1 r r stands for red force fielc y stands for yellow force field * r 21 y * * By stepping in a location labeled 'r' the red force field will turn 'on' if it is currently 'off' and 'off' if it is currently turned 'on'. * By stepping in a location labeled 'y' the yellow force field will turn 'on' if it is currently 'off' and 'off' if it is currently turned on'. * */ } public void walkthrough() * * Extra Credit: Provide a sequence of calls to move forward(), moveLeft(), * moveRight(), and moveBackward() that solves the puzzle. The puzzle is * solved if these moves take the user from location (1, 2) to location (1, 0) * facing a green door. * */ This class allows a user to walk around in a virtual 3x3 room and solve a puzzle. The room has nine locations with the following (x, y) coordinates (0, 0) (1, 0) (2, 0) (0, 1) (1, 1) (2, 1) (0, 2) (1, 2) (2, 2) The user starts at location (1, 2). Directly across the room from the user is a door. The door may be blocked by 0, 1, or 2 force fields. The frame of the door identifies which force field is currently blocking it: a red frame means that only the red force field is on, yellow frame means that only the yellow force field is on, an orange frame means that both force fields are on, and a green frame means that both fields are off. Depending where the user steps in the room one of the force fields will either turn on or off. The goal of the puzzle is to cross the room (i.e., * reach position (1,0)) facing the door with both force fields off (i.e., a green frame) The constructor and the methods of this class are incomplete. The comments tell you what is missing. You do not need to add any fields to this class. * You do not need to change any of the other classes in this project. */ public class Puzzle { V/Your current xy position in the room private int xPosition : private int yPosition; V/Boolean variables that tell you whether or not the red and yellow //force fields are currently turned on (true) or off (false). private boolean yellowField; private boolean redField; private View view; public Puzzle { * * Finish: Initialize xPosition and yPosition to reflect that your * initial position in the puzzle is (1,2) and that both force fields * are initially off. */ view = new View(); view.display(xPosition, yPosition, yellowField, redField); public void move forward() { * Finish: Implement this method that moves you forward in the room * if there is not a wall blocking you. Otherwise print a message * alerting the user that this move is not permitted now. * If the move is allowed then you should call toggleFields() and * view.display ( xPosition, yPosition, yellowField, redField) afterward. * } public void move Backward() { * * Finish: Implement this method that moves you backward in the room * if there is not a wall blocking you. Otherwise print a message * alerting the user that this move is not permitted now. * * If the move is allowed then you should call toggleFields() and * view.display(xPosition, yPosition, yellowField, redField) afterward. */ } public void moveLeft() { * * Finish: Implement this method that moves you to the left in the room * if there is not a wall blocking you. Otherwise print a message * alerting the user that this move is not permitted now. * * If the move is allowed then you should call toggleFields) and * view.display (xPosition, yPosition, yellowField, redField) afterward. * */ } public void moveRight() /* * Finish: Implement this method that moves you right in the room * if there is not a wall blocking you. Otherwise print a message * alerting the user that this move is not permitted now. * If the move is allowed then you should call toggleFields() and * view.display(xPosition, yPosition, yellowField, redField) afterward. * */ } private void toggleFields() { * * Finish: Implement this method that turns a field on or off depending * on where you step. The following table describes the coordinate system * and the effect of stepping in a particular location. * The x coordinate of a location is its row number, and the y coordinate * is its column number. * column numbers 0 1 2. * * r row numbers Or 1 1 r r stands for red force fielc y stands for yellow force field * r 21 y * * By stepping in a location labeled 'r' the red force field will turn 'on' if it is currently 'off' and 'off' if it is currently turned 'on'. * By stepping in a location labeled 'y' the yellow force field will turn 'on' if it is currently 'off' and 'off' if it is currently turned on'. * */ } public void walkthrough() * * Extra Credit: Provide a sequence of calls to move forward(), moveLeft(), * moveRight(), and moveBackward() that solves the puzzle. The puzzle is * solved if these moves take the user from location (1, 2) to location (1, 0) * facing a green door. * */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago