Enter x Coordinate: 1 Enter Y Coordinate: 1 Enter Length: 5 *************** 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 Coordinate: 0 ***0**************** ******
in java please
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
int r, c;
int x,y,len;
int m=1,ch;
Scanner sc = new Scanner(System.in);
System.out.println("FYE Level Map Creater");
System.out.print("Enter a level map width: ");
c = sc.nextInt();
System.out.print("Enter a level map height: ");
r = sc.nextInt();
String arr[][] = new String[r][c];
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
arr[i][j] = "*";
//Printing array
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
System.out.print(arr[i][j]);
System.out.println();
}
do
{
System.out.println("\nOptions");
System.out.println("1. Clear Level");
System.out.println("2. Add Platform");
System.out.println("3. Add Item");
System.out.println("4. Quit");
System.out.print("Enter Choice: ");
ch = sc.nextInt();
switch(ch)
{
case 1:
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
arr[i][j] = "*";
break;
case 2:
System.out.println("\n[Add Platform]");
System.out.print("Enter X Coordinate: ");
x = sc.nextInt();
System.out.print("Enter Y Coordinate: ");
y = sc.nextInt();
System.out.print("Enter Length: ");
len = sc.nextInt();
if(len > c)
System.out.print("The platform is too long.\n");
else
{
for(int j=y; j<=len;j++)
arr[x][j] = "=";
}
break;
case 3:
System.out.println("\n[Add Item]");
System.out.print("Enter X Coordinate: ");
x = sc.nextInt();
System.out.print("Enter Y Coordinate: ");
y = sc.nextInt();
if(x>r || y>c)
System.out.print("This is not a valid location!\n");
else
arr[y][x] = "O";
break;
case 4:
m=0;
break;
}
//Printing array
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
System.out.print(arr[i][j]);
System.out.println();
}
}while(m==1);
}
}
Step by step
Solved in 2 steps with 4 images