Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) How is the program organized? What major data structures were used? How are commands processed? How is the PacMans state maintained? Etc. 2) What

1) How is the program organized? What major data structures were used? How are commands processed? How is the PacMans state maintained? Etc.

2) What alternative approaches were considered and why were they rejected?

3) What did you learn from doing this project and what would you do differently?

All Java source will be in a single text file which can be compiled and executed in a standard Java 8 or later SE environment. Multiple methods can be used but all user-created methods must be contained in the single Java text file.

1) Create a new Java program which implements a simple PacMan-type text game which contains the following functionality:

A) At program startup, constructs and displays a 2-dimensional grid with the size dynamically specified by the user (X and Y sizes can be different). Places the PacMan in the upper-left corner of the grid facing left All grid cells should have the empty cell character of . except for the start position of the PacMan which will have the appropriate PacMan symbol (see below). Also 10% of your grid should contain cookies randomly located on the grid except for the initial PacMan position. The grid must be displayed after each command.

B) Use these symbols for the grid:

Cookie symbol shows were cookies are in the grid ('O')

Empty symbol shows empty unvisited grid cells ('.') (dot)

Visited symbol shows grid cells where the PacMan has visited (' ') (space)

PacMan symbol depends on the current PacMan facing direction.

Left >

Up V

Right <

Down ^

C) A menu of commands must be provided and must be displayed when appropriate. At a minimum the menu should consists of the following commands (the command number is what the user should enter to execute the command):

Menu Display the menu of commands.

Turn Left turns the PacMan left (counter-clockwise) but the PacMan stays in its current location

Current: up, new: left

Current: right, new up

Current: down, new right

Current: left, new down

Turn Right turns the PacMan right (clockwise) but the PacMan stays in its current location

Current: up, new: right

Current: right, new down

Current: down, new left

Current: left, new up

Move Moves the PacMan one grid location in the facing direction if possible.

Exit exits the program displaying the game statistics of the number of total moves and the average number of moves per cookie obtained.

2)

The main processing cycle is the following:

The grid must be displayed after each command showing the effects of the command.

Optionally display the list of commands

Display the grid

Accept user input. Code will be provided for reading user input.

If an invalid command is entered, an appropriate error message should be displayed and the

menu of commands and grid gets redisplayed. An invalid command does not count as a command in the statistics.

E)

If the resulting move places the PacMan over a cookie, indicate the cookie was eaten and add one to the number of cookies eaten for the program statistics.

Process the command and add one to the number of commands entered if it is an action command (move or turn).

If the user enters the Exit command, the program will display the number of commands and the average number of commands per cookie.

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 Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions