Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ONLY part 1 by algorithms Algorithm 1: Write an algorithm for a function that has the properties described below 1) Accepts at least 2 parameters

ONLY part 1 by algorithms

Algorithm 1: Write an algorithm for a function that has the properties described below

1) Accepts at least 2 parameters

a. A size for the maze (maze should be square or NxN)

b. A value that will be used to determine whether or not to include monsters AND how many

2) Returns a complete maze (NxN string array) populated with at least 1 string P, E, 0 3 strings M, and the rest of the elements of the array should contain the string 0

3) The string P inserted into a random position in the maze array

4) The string E should be inserted into a random position in the maze array.

a. You MUST use some type of iterative construct to ensure that E is placed randomly (no offsets this week). That means that if your first random number lands on P, you HAVE TO randomly choose another position.

5) The string(s) M for monsters should be inserted into random positions in the maze array.

a. You MUST use some type of iterative construct to ensure that M is placed randomly (no offsets this week). That means that if your first random number lands on P or E OR M (another monster) you HAVE TO randomly choose another position.

b. You cant overwrite monsters this week.

c. If the monster parameter indicates that you should include 3 monsters, your maze MUST have 3 monsters in it.

Algorithm 2: Write an algorithm for a function that has the properties described below

1) Accepts at least 2 parameters

a. An NxN array of strings

b. A 1x2 array of numbers representing a players stats (health and damage)

i. The first element represents how much health the player has

ii. The second element represents how much damage the player can do with a

single attack

iii. You will potentially need to modify this in your algorithm if you fight a

monster

2) Returns at least 3 things

a. An NxN array of strings

i. Given a maze in state X (parameter 1), returns a maze in state Y.

Represents a SINGLE move.

b. A 1x2 array of numbers representing a players stats (health and damage)

c. A value used to represent whether or not the game is over (if the game has been

won OR lost, then it is over).

3) Your algorithm should move the player string P +-0,1 for both x and y coordinates of

current location of string P in the array.

a. If the new coordinates for P has the string E inside

i. Display winning message

ii. Set all array elements to W

iii. Set game_over variable accordingly

iv. Return 2d array (maze), game_over variable, and player

b. If the new coordinates for P has the string 0

i. Set new coordinates for P to P

ii. Set old coordinates for P to 0

iii. Display current coordinates

iv. Set game_over variable accordingly

v. Return 2d array (maze), game_over variable, and player

c. If the new coordinates for P has the string M inside

i. Generate a 1x2 array that will be used to represent the monsters health

and damage

1. The first element should represent how much health the monster

has

2. The second element should represent how much damage it can do

with a single attack

ii. Randomly roll some number

iii. Ask the player to guess the number

iv. If the player guesses the number correctly

1. The player and the monster will take turns attacking each other

until one of them has health <= 0. Player gets to attack first.

2. MUST use some iterative construct to simulate fight.

v. If the player guesses incorrectly

1. The player and the monster will take turns attacking each other

until one of them has health <=0. Monster gets to attack first.

2. MUST use some iterative construct to simulate fight.

vi. If player wins the fight

1. display message indicating monster was defeated

2. set element that previously contained M to P

3. set previous player element to 0

4. set game_over variable accordingly

5. display new coordinates of player

6. Return 2d array (maze), game_over variable, and player

vii. If player loses fight

1. Set all maze elements to L

2. Display losing message

3. Set game_over variable accordingly

4. Return 2d array (maze), game_over variable, and player

HW2

For this homework assignment, we will improve on the text-based game we started on in HW1.

Players now have health bars and do certain amount of damage (relative to health bars), as do monsters. For example, a player may have 5 health bars and do 2 health bars of damage each attack. (So, to kill another player given the EXAMPLE above, you would need 3 attacks).

NOTE: The algorithms (and functions for part 2) you are describing, UNLESS EXPLICITLY STATED, should NOT depend AT ALL on each other. They are separate entities that should always return what they say they will, if you provide the parameters you describe. They are dependent on input and ouput (DATA), NOT other algorithms/functions.

Part 1 (Due Friday, November 16)

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions