473,499 Members | 1,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2D array in Java

2 New Member
Hi guys I question, as I am new to Java I have some problem to create relatonship between classes can you help me please, I have coursework from my module so I need to solve the problem. I dont ask you to do it for me I just ask if someone can guide to me like explain what kind of relationship need to be between Classes, here is question:

************************************************** **************************Hi guys , I have the same kind of coursework, i need some help how design it,
sorry guys i am not asking you to do for me i need just the right direction how to do it, i have drawn relationship diagram but i dunno where to put right methods and how create relationship ************************************************** **************************


You are required to write a 'level' editor for a simple game called CharWorld. A level in CharWorld is a room made up from 10 x 10 squares. Each square in the room is referred to by an X and a Y coordinate. Hence the '@' in the room shown below is placed at square (1,3):

0 1 2 3 4 5 6 7 8 9
0 . . . . . . . . . . . .
1 . . . . . . . . . . . .
2 . . . . . . . . . . . .
3 . @ . . . . . . . . .
4 . . . . . . . . . . . .
5 . . . . . . . . . . . .
6 . . . . . . . . . . . .
7 . . . . . . . . . . . .
8 . . . . . . . . . . . .
9 . . . . . . . . . . . .

A room in CharWorld can be populated by two types of entities: inanimate objects and living things. There are two kinds of inanimate objects: obstacles which are represented by 'O' (capital 'o') and treasure chests, which are represented by a '*'. Treasure chests can contain up to 100 gold coins.

Each living thing in CharWorld has a measure of its health, represented using an integer in the range 0 to 100. Living things are divided in to monsters and humans. Monsters are represented in the display by a '#' character whilst humans are depicted by an '@' character. The amount of damage that a particular monster can cause a human depends on its strength which is represented by a number from 1 to 20. Similarly, the amount of damage that a human can cause a monster depends on his or her strength, which is represented by a number in the range 1 – 10. Each human also has a name.

A typical level for a game would look like the following:

0 1 2 3 4 5 6 7 8 9
0 . . . . . . . . . . . .
1 . . . . . # . . . . .
2 . . . O . . . . . . .
3 . @ . O . . . * . .
4 . . . O . . . . . . .
5 . . O O . . . . . .
6 . . . . . . . @ . . .
7 # . . . . . . . . . . .
8 . . . # . . . . . . . .
9 . . . . . . . . . . . .

This shows 1 treasure chest, 2 humans, 3 monsters and 5 obstacles on this level. Note that a full stop is used to denote an unoccupied square in the level.

Write an object oriented program which will enable a level designer to add and delete entities to and from a given level. Initially, the level will have no entities in it. Your program should be controlled using a simple console based menu similar to the one shown below:

Menu:
1 Add a human
2 Add a monster
3 Add an obstacle
4 Add a treasure chest
5 Delete an entity
6 Display level
7 Display the properties of an entity
8 Print menu
9 Exit

When adding an entity to the level, the user should be prompted for the X and Y coordinates of the square on which to place the entity. Note that an entity can only be placed on an empty square. Note also that the user should be prompted for the relevant details to be entered depending on which entity is being added (e.g. to add a human, the user should be prompted to enter the human’s name, their health as an intiger in the range 0 to100 and their strength as an integer in the range of 1 to 10).

When deleting an entity, it is only necessary to identify the square the entity occupies using its X and Y coordinate.

The 'Display level' option should display the current contents of the room to the console output using a format similar to that shown above.

When item 7 on the menu is selected, the user should be prompted for the X and Y coordinates of the square on which the entity in question is located. Your program should then display all the details of the entity on that square. For example, if square (6,7) was selected from the display shown at the top of this page, then the output might be as follows:

Entity properties:
Type: human
Name: Harold
Health: 47
Strength 5

If there is no entity on that square then your program should output a suitable message

************************************************** ****************************
anyone can help me please?

Thanx in advance

Charlie
Oct 24 '08 #1
1 3192
JosAH
11,448 Recognized Expert MVP
Design a little class hierarchy that models living and dead things; humans, monsters,
treasures and obstacles. All of them are 'Things' which makes up a nice interface.

Your rooms are simply two dimensional arrays of Things. You end up with something
like this:

Expand|Select|Wrap|Line Numbers
  1. public interface Thing {
  2.    public int getStrength();
  3.    public void setStrength(int strengh);
  4.    public int getHealth();
  5.    public void setHealth(int health);
  6.    public String getName();
  7. }
  8. public abstract class AbstractThing implements Thing {
  9.    private String name;
  10.    public AbstractThing(String name) { this.name= name; }
  11.    public String getName() { return name; }
  12. }
  13. public abstract class DeadThing extends AbstractThing {
  14.    public DeadThing(String name) { super(name); }
  15.    public int getStrenght() { return 0; }
  16.    public int getHealth() { return 0; }
  17.  
  18.    // dead things don't have a health nor a strength
  19.    public void setStrength(int strength) { }
  20.    public void setHealth(int health) { }
  21. }
  22. public class Obstacle extends DeadThing {
  23.    public Obstacle() { super("obstacle"); }
  24. }
  25. // etc. etc.
  26.  
I'm sure you can handle it from here.

kind regards,

Jos
Oct 24 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
6829
by: susa | last post by:
hallo, ich hoffe es kann mir jemand von euch helfen. ich hab noch ziemlich grosse probleme mit java;(. sicherlich,sollte ich versuchen,das alleine hin zu bekommen,aber im moment weiß ich noch gar...
7
26109
by: Jamil Anwar Zaman | last post by:
If I dynamically allocate memory to a pointer, then is it possible to see afterwards what is the memory size the pointer is looking at. e.g int SIZE = 10; int *a = malloc(SIZE*sizeof(int));...
24
4343
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
1
6825
by: phjones | last post by:
This is not a class project.The program below is to display mortgage interest paid for each payment over the term of the loan and loan balance.It is program using array. However, I am receiving the...
5
2489
by: Stephen3776 | last post by:
I am doing an inventory control progam and trying to output a multiple array, I am getting an illegal conversion error java.lang.double !d. Can somebody tell me what I am doing wrong or if there is...
11
2433
by: AZRebelCowgirl73 | last post by:
here is the instructiions I am to use Ask the user to input the number of effective cars in the shop (this number should be between 1 and 100, inclusively). In a loop, controlled by the inputted...
6
2513
by: AZRebelCowgirl73 | last post by:
Here is my problem: I have two java files: One named Car.java and the other named CarDealerApp.java: In the CarDealerApp program, I read in through user input the make, model, year and price of...
0
4074
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
1
2899
by: stevedub | last post by:
I am having some trouble configuring my array to read from a sequential file, and then calling on that to fill an array of interests. I think I have the class set up to read the file, but when I run...
2
3731
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.