Assignment 5C: Level Map Creator. There are a variety of ways that game developers store their level layouts. One simple method is to associate level elements with certain symbols, and then storing them in a 2D grid inside a text file. We will use our knowledge of 2D arrays to create a very simple Level Map Creator tool. The program should prompt the user to enter a width and height for the level. Then it should initialize a 2D array and fill every element with the “*" given the following options via a menu: symbol. Afterwards, the user should be

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

the language is c++ 

the bold is the user input , code asks the user what the width and height of the array should be 

 

using arrays and loops for this code 

Assignment 5C: Level Map Creator. There are a variety of ways that game developers store
their level layouts. One simple method is to associate level elements with certain symbols, and
then storing them in a 2D grid inside a text file. We will use our knowledge of 2D arrays to
create a very simple Level Map Creator tool.
The program should prompt the user to enter a width and height for the level. Then it should
initialize a 2D array and fill every element with the "*" symbol. Afterwards, the user should be
given the following options via a menu:
1. Clear Level
Re-initialize the 2D array and fill every element with the "*" symbol.
2. Add Platform
Prompt the user to enter a starting point and length for the
horizontal platform. Replace those elements in the 2D array with
the "=" symbol. If the length is longer than the number of columns
(or out of bounds), notify the user that this is not possible.
3. Add Item
Prompt the user to enter a column and row index. Replace that
element in the 2D array with the "O" symbol. If the column and row
index in outside the bounds of the array, notify the user that this is
not possible.
4. Quit:
End the program
After completing the task, print the modified 2D array, If anything other than Quit is
selected, display the menu again. Otherwise, tell the player "Good bye!" and stop.
Hints: Since we're using a 2D array to represent the level map, we'lIl use its indexes for
our level coordinates. 0,0 will be the top-left corner of the map, and will correspond to
array[0][0].
Transcribed Image Text:Assignment 5C: Level Map Creator. There are a variety of ways that game developers store their level layouts. One simple method is to associate level elements with certain symbols, and then storing them in a 2D grid inside a text file. We will use our knowledge of 2D arrays to create a very simple Level Map Creator tool. The program should prompt the user to enter a width and height for the level. Then it should initialize a 2D array and fill every element with the "*" symbol. Afterwards, the user should be given the following options via a menu: 1. Clear Level Re-initialize the 2D array and fill every element with the "*" symbol. 2. Add Platform Prompt the user to enter a starting point and length for the horizontal platform. Replace those elements in the 2D array with the "=" symbol. If the length is longer than the number of columns (or out of bounds), notify the user that this is not possible. 3. Add Item Prompt the user to enter a column and row index. Replace that element in the 2D array with the "O" symbol. If the column and row index in outside the bounds of the array, notify the user that this is not possible. 4. Quit: End the program After completing the task, print the modified 2D array, If anything other than Quit is selected, display the menu again. Otherwise, tell the player "Good bye!" and stop. Hints: Since we're using a 2D array to represent the level map, we'lIl use its indexes for our level coordinates. 0,0 will be the top-left corner of the map, and will correspond to array[0][0].
Options
1. Clear Level
2. Add Platform
3. Add Items
4. Quit
Enter a choice: 3
[Add Item]
Enter x Coordinate: 30
Enter Y Coordinate: 30
This is not a valid location!
*====
Options
1. Clear Level
2. Add Platform
3. Add Items
4. Quit
Enter a choice: 3
[Add Item]
Enter X Coordinate: 3
Enter Y Cordinate: 0
****
Options
1. Clear Level
2. Add Platform
3. Add Items
4. Quit
Enter a choice: 2
[Add Platform]
Enter x Coordinate: 3
Enter Y Coordinate: 1
Enter Length: 29
This platform won't fit in the level!
***0*
*=====**.......
........
Options
1. Clear Level
2. Add Platform
3. Add Items
4. Quit
Enter a choice: 1
Transcribed Image Text:Options 1. Clear Level 2. Add Platform 3. Add Items 4. Quit Enter a choice: 3 [Add Item] Enter x Coordinate: 30 Enter Y Coordinate: 30 This is not a valid location! *==== Options 1. Clear Level 2. Add Platform 3. Add Items 4. Quit Enter a choice: 3 [Add Item] Enter X Coordinate: 3 Enter Y Cordinate: 0 **** Options 1. Clear Level 2. Add Platform 3. Add Items 4. Quit Enter a choice: 2 [Add Platform] Enter x Coordinate: 3 Enter Y Coordinate: 1 Enter Length: 29 This platform won't fit in the level! ***0* *=====**....... ........ Options 1. Clear Level 2. Add Platform 3. Add Items 4. Quit Enter a choice: 1
Expert Solution
Step 1

Sample Response:

#include <iostream>
using namespace std;

int main()
{
    int width,height,ch,x,y,length,i,j;
    cout << "Enter the width and height for the level: ";
    cin>>width>>height;
    char arr[width][height];
    for(i=0;i<width;i++){
        for(j=0;j<height;j++)
            arr[i][j]='*';
    }
    while(true){
        cout<<"\nOptions\n1. Clear Level\n2. Add Platform\n3. Add Items\n4. Quit\nEnter a choice: ";
        cin>>ch;
        if(ch==1){
                for(i=0;i<width;i++){
                        for(j=0;j<height;j++)
                        arr[i][j]='*';
                }
                for(i=0;i<width;i++){
                    for(j=0;j<height;j++)
                    cout<<arr[i][j];
                    cout<<endl;
                }
        }
        else if(ch==2){
            cout<<"\n[Add Platform]\nEnter x Coordinate: ";
            cin>>x;
            cout<<"Enter y Coordinate: ";
            cin>>y;
            cout<<"Enter Length: ";
            cin>>length;
            if(((x+length)>width) || ((y+length)>height)){
                cout<<"This platform won't fit in the level!\n";
                for(i=0;i<width;i++){
                    for(j=0;j<height;j++)
                    cout<<arr[i][j];
                    cout<<endl;
                }
            }
            else{
                for(i=x;i<x+length-1;i++){
                        for(j=y;j<y+length;j++)
                    arr[i][j]='=';
                }
                for(i=0;i<width;i++){
                    for(j=0;j<height;j++)
                    cout<<arr[i][j];
                    cout<<endl;
                }
            }
        }
        else if(ch==3){
            cout<<"\n[Add Items]\nEnter x Coordinate: ";
            cin>>x;
            cout<<"Enter y Coordinate: ";
            cin>>y;
            if((x>width )|| (y>height)){
                cout<<"This location is not a valid location\n";
                for(i=0;i<width;i++){
                    for(j=0;j<height;j++)
                    cout<<arr[i][j];
                    cout<<endl;
                }
            }
            else{
                arr[x][y]='0';
                for(i=0;i<width;i++){
                    for(j=0;j<height;j++)
                    cout<<arr[i][j];
                    cout<<endl;
                }
            }
        }
        else if(ch==4){
            break;
        }
    }
    return 0;
}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education