Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I don't know where to start, can someone help me with this. Here is the text if you aren't able to read it clearly. SimpleBotView

image text in transcribed

I don't know where to start, can someone help me with this.

Here is the text if you aren't able to read it clearly.

SimpleBotView

In this part of the project you will write one class called SimpleBotView.

In SimpleBot, the user is shown a rectangular grid of C columns and R rows. Each position in the grid is a colored square S pixels per side and is one of four colors. The current location of the robot should be one color, walls should be another color, squares where the robot has been located in the past should be a third color, and all other grid positions should be a fourth color.

Since the view module doesn't need any smarts (the model will make all the decisions) it can have a very simple interface: a method to construct it to its initial state, and a method to move the robot.

public SimpleBotView(char[][] initial, Color robot, Color wall, Color trail, Color background, int size)

initial[r][c] will have one of four characters (r, w, t, b) indicating that the grid position at row r and column c should be drawn as a robot, wall, trail or background colored square. Column 0, Row 0 should be considered the top left grid position. The Color parameters are what color each type of grid position should be drawn as. Size is how many pixels each side of each grid square should be.

Note that the number of rows and columns is not explicitly given in the parameters. It is implicitly given as the size of the initial array. initial is an array of rows, so initial.length is how many rows are in the grid. And because initial[0] is an array holding the values for row 0, initial[0].length will tell you how many columns are in the grid.

The result of this method should be that a DrawingPanel of the appropriate size is created and filled with squares as indicated by the parameters.

public void move(char direction)

direction will contain one of four characters (u, d, l, r) indicating that the robot should be moved up, down, left, or right. The DrawingPanel should be updated: the old robot position should be redrawn in the trail color and the new robot position should be drawn in the robot color. Do not try to detect whether the robot is walking off the grid or into a wall. When you write the model in a later project, you will do that type of detection there. Simply draw the robot wherever requested.

Notes

~ Your class should be named exactly SimpleBotView and should contain only two public elements, namely the two methods detailed above. It may have as many private elements as are necessary (ie, private fields and/or private helper methods).

~ A well-written class would strive to be robust by error-checking parameter values and throwing an exception on bad input. To keep things simple for our first project, you may assume that all parameter values are legitimate and will not cause an error. This means initial and direction will contain only legal characters, initial will have exactly one 'r', size is greater than zero, etc. Also, move will never cause the robot to leave the grid.

~ You must download DrawingPanel.java and place it in the same folder as your code. (http://www.buildingjavaprograms.com/supplements4.shtml)

~ You need to import java.awt.Color and java.awt.Graphics for Color and Graphics to be defined.

~ You may find it useful to review Sections 3G.1 and 7.5 of your textbook to learn more about graphics and two-dimensional arrays.

In this part of the project you will write one class called SimpleBotView. In SimpleBot, the user is shown a rectangular grid of C columns and R rows. Each position in the grid is a colored square S pixels per side and is one located in the past should be a third color, and all other grid position should be a fourth color. Since the view modulo doesn't need any smarts (the modal will make all the decisional) it can have a very simple interface: a method to construct. public SimpleBotView(char initial, Color robot, Color wall, color trail. Color background, int size) initial[r][c] will have one of four characters (r, w, t, b) indicating that the grid position at row r and column c should be drawn as a robot, wall, trail or background colored square. Column 0, row 0 should be considered the top left grid position. The color parameters are what color each type of grid position should be drawn as. Size is how many pixels each type side of each grid square should be. Note that the number of rows and columns is not explicitly given in the parameters. It is implicitly given as the size of the initial array. initial is an array of rows, so initial.length is how many rows are in grid. And because initial [0] is an array holding the values for row 0, initial [0]. length will tell you how many columns are in the grid. The result of this method should be that a DrawingPanel of the appropriate size is created and filed with squares as indicated by the parameters. public void move (char direction) direction will contain one of four characters (u, d, l, r) indicating that the robot should be moved up, down, left, or right. The DrawingPanal should be updated: the old robot position should be redrawn in the trail color and the new robot position should be drawn in the robot color. Do not try to detect whether the robot is walking off the grid or into a wall. When you write the model in a later project, you will do that type of detection there. Simply draw the robot wherever requested. Example Below is a simple main that creative a view. The left picture is what you would expect to see immediately after construction. The right picture is what you would see if you then invoked view.move('d'). public static void main(String[] args) { char init = {{'w', 'w', 'w', 'w'}, {'w', 't', 'r', 'r', 'w'}, {'w', 't', 'b', 'w'}, {'w', 't', 'w', 'w'}}: SimpleBotView = new SimpleBotView(init, Color.RED, Color.BLACK, Color.BLUE, Color.WHITE, ): }

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_2

Step: 3

blur-text-image_step3

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

ISBN: 3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

Explain the steps involved in training programmes.

Answered: 1 week ago

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago