Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are developing a new game similar to the arcade classic Pacman. Each level in the game consists of a maze that the main character

image text in transcribed
You are developing a new game similar to the arcade classic Pacman. Each level in the game consists of a maze that the main character must navigate, while avoiding various enemies. Each level will be stored as a rectangular grid of integers, where certain integers represent certain components: Problem 2 - Name your class Totally NotPacman Open space Wall 0 2 Enemy 3 Main character An example level is shown below Columns 0 (6 pts) Let's define the "difficulty" of a level as the proportion of non-wall cells that are occupied by an enemy. For example, in the data above, there are 19 non-wall cells. Of those 19, 3 are occupied by arn enemy. Thus, the difficulty would be 3/19 or about 0.158. 1. The method should Write a method difficulty that takes a 2D array in the above format as a parameter. return the difficulty of that level. (10 pts) Let's say that the main character is considered "under threat" if there are at least two enemies within the eight cells immediately surrounding the main character (all four cardinal directions, and all four diagonal directions). For example, in the level above the main character is not under threat since there are no enemies in the immediately surrounding cells. Note that there may be fewer than eight surrounding cells if the main character is on the edge of the level. 2. Write a method isUnderThreat that takes a 2D array in the above format as a parameter. The method should return whether the main character is under threat according to the definition above. You may assume that the main character shows up exactly once in the 2D array. Be careful not to go beyond th bounds of the array! (4 pts) Write a main method that creates a 2D array with the data from the example above, then calls both of your methods and shows the results. You do not need to read any user input 3

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

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions