473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 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 5158
dev7060
633 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

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

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
5
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.