#include<iostream>
using namespace std;
int main(){
int length, width;
cout << "输入房间长度和宽度(以空格分隔,下同):";
cin >> length >> width;
char room[100][100];
for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++) {
if (i == 0 || i == width - 1 || j == 0 || j == length - 1)
room[i][j] = '#';
else
room[i][j] = ' ';
}
}
int x, y;
cout << "输入门的坐标:";
cin >> x >> y;
while (room[y][x]!='#' || ((x == 0 || x == length - 1) && (y == 0 || y == width - 1))) {
cout << "门必须在墙上且不能再拐角,请重新输入:";
cin >> x >> y;
}
int doorx = x, doory = y;
room[y][x] = ' ';
cout << "输入窗户的坐标:";
cin >> x >> y;
while (room[y][x] != '#' || ((x == 0 || x == length - 1) && (y == 0 || y == width - 1)) ||((x==0||x==length-1)&&(room[y-1][x]==' '||room[y+1][x]==' '))|| (y == 0 || y == width - 1) && (room[y][x+1] == ' ' || room[y][x-1] == ' ')) {
cout << "窗户必须在墙上且不能再拐角,且不能紧靠门,请重新输入:";
cin >> x >> y;
}
if (x == 0 || length == length - 1)
room[y][x] = '|';
else
room[y][x] = '-';
cout << "输入家具的坐标:";
cin >> x >> y;
while (!(0<x&&x<length&&0<y&&y<width)||(y==doory&&abs(x-doorx)==1)||(x==doorx&&abs(y-doory)==1)) {
cout << "家具必须在室内,且不能堵门,请重新输入:";
cin >> x >> y;
}
room[y][x] = '*';
//显示房间
for (int i = 0; i < width; i++) {
for (int j = 0; j < length; j++)
cout << room[i][j];
cout << endl;
}
return 0;
}