Question: makeMove This method interprets input from the user and updates fields to represent the requested move. It returns true if the game is over after

makeMove
This method interprets input from the user and updates fields to represent the requested move.
It returns true if the game is over after the move is made, false if it is not.
The move is provided as a parameter to this method. This method does NOT ask for user input.
The first thing we want to do is take the first letter of the move as lowercase. This way as long as the user input starts with the correct letter, regardless of casing, we will perform the appropriate move. Use the toLowerCase and charAt methods to accomplish this.
Next, switch on that character. There are five different options: q for quit, d for down, u for up, l for left, and r for right. Each case will be a bit different.
For q, you want to end the game so you can just return true.
For l, d, u, and r there are a couple things you always need to do.
Check if the move is valid.
If the move is valid, update the player location to the new cell and mark the cell as visited. Use the valid and visit helper methods.
Return true if the player is at the goal, meaning the game is over and false otherwise. Use the playerAtGoal method for this.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!