472,139 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

2D array in C++

Hi guys I question, as I am new to C++ 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

************************************************** ****************************
Aug 29 '21 #1
2 4935
dev7060
624 Expert 512MB
Hi guys I question, as I am new to C++ 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
What module? What classes?
Aug 30 '21 #2
Banfa
9,065 Expert Mod 8TB
I think you might find this article Arrays Revealed useful.

Looks to be like you need a simple class hierarchy with a base Entity class which is inherited by the classes representing the entity types, human, monster, obstacle and chest. You may want to look at the similarities between human and monster and create an additional intermediate class, LivingEntity containing common characteristics (health, strength) as it looks like the difference between monsters and humans may only be the maximum allowed for the characteristics not which characteristics they have.
Aug 31 '21 #3

Post your reply

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

Similar topics

2 posts views Thread by Brian | last post: by
2 posts views Thread by Stormkid | last post: by
8 posts views Thread by vcardillo | last post: by
104 posts views Thread by Leszek | last post: by
7 posts views Thread by Jim Carlock | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
5 posts views Thread by LittleCake | last post: by

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.