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
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
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;
}
Step by step
Solved in 2 steps with 1 images