4 Replies Latest reply: Nov 28, 2006 1:33 AM by JosAH

# One Dimensional Array.

HARRY POTTER & THE AMAZING WIZARD.

Declare and initialize a 20-element array. In each element place one of the following characters:
�W� � Wizard
�S� -- Sword
�D� -- Demon
�B� -- Blank � Save spot.

Example an array can look like this:
W S S D B D W B B D W S W D B D S W B S

You ask the player to select a location in Hogarth Tower. (Choose a number from 0 � 19) That places the player at a position in the array. In the example if the user enters a 5 as a starting position (starting at 0). So, the entry at that position is a B (Blank).

Based on the rules below the player can then move North (add 1 to the array index) or South (subtract 1 from the array index). Here are the rules:

(1)     For each Blank (B) spot output the message �Safe Place�; 2 points is awarded.
(2)     For each Wizard (W) spot output the message �You picked up a Wizard�; 3 Points is Awarded.
(3)     For each Sword (S) spot output the message �You picked up a Sword�; 4 Points is awarded.
(4)     For each Demon (D) encountered display the message �A demon has attacked�; subtract 5 points.

The game is over when (a) the player types in 99 this ends the game. Print out the accumulated points. Or (b) when the points are below 0 � the player is killed. Display �You are killed� if the points garnered by the player is below zero.

Make sure the player does not go beyond the array boundary. The boundary has is limited by the size of the array 19 elements.

phew... so guyz can you answer this one? it's a little bit hard making this.. lol . hmm.. just use One dimensional array. Good Luck!

Message was edited by:
Wilbert
• ###### 1. Re: One Dimensional Array.
phew... so guyz can you answer this one? it's a
little bit hard making this.. lol . hmm.. just use
One dimensional array. Good Luck!
Well good luck to you. Its your homework and you are suppose to do it. Nobody here is going to do it.
Here's how you declare a array just to get you started.
``String[] arr = new String[20];``
• ###### 2. Re: One Dimensional Array.
One dimensional array. Good Luck!
Good question for doing the homework. all the best
• ###### 3. Re: One Dimensional Array.
HARRY POTTER & THE AMAZING WIZARD.

Perhaps you could get Harry to wave his magic wand and your code will appear.
• ###### 4. Re: One Dimensional Array.
phew...
Instead of typing in that entire assignment text you should've started implementing
a solution for this nice little problem. My estimation is that it takes less typing.

kind regards,

Jos