Console.WriteLine ("请输入电影院规模(整数):");
int n = int.Parse (Console.ReadLine ());
int[,] seatArray = new int[n, n];
bool isBegin = true;
while (isBegin) {
Console.WriteLine ("*************************");
Console.WriteLine ("*\t1.选座 \t*");
Console.WriteLine ("*\t2.退座 \t*");
Console.WriteLine ("*\t3.查看 \t*");
Console.WriteLine ("*\t0.退出 \t*");
Console.WriteLine ("*************************");
Console.WriteLine ("请输入");
string numStr = Console.ReadLine ();
// 补充
switch (numStr) {
case "1":
Console.WriteLine ("执行选座功能");
Console.Write ("请选择行:");
int row = int.Parse (Console.ReadLine ());
row--;
Console.Write ("请选择列:");
int column = int.Parse (Console.ReadLine ());
column--;
// 用户输入
if (row <= n && column <= n) {
if (seatArray [row, column] == 0) {
seatArray [row, column] = 1;
for (int i = 0; i < seatArray.GetLength (0); i++) {
for (int j = 0; j < seatArray.GetLength (1); j++) {
Console.Write (seatArray [i, j]);
}
Console.WriteLine ();
}
} else {
Console.WriteLine ("该座位已经有人,请重新选择!");
}
} else {
Console.WriteLine ("输入数值过大!");
}
// 检测1.是否越界 2.查重
// 设置数组
break;
case "2":
Console.WriteLine ("执行退座功能");
Console.Write ("请选择行:");
int row1 = int.Parse (Console.ReadLine ());
row1--;
Console.Write ("请选择列:");
int column1 = int.Parse (Console.ReadLine ());
column1--;
// 用户输入
if (row1 <= n && column1 <= n) {
if (seatArray [row1, column1] != 0) {
seatArray [row1, column1] = 0;
for (int i = 0; i < seatArray.GetLength (0); i++) {
for (int j = 0; j < seatArray.GetLength (1); j++) {
Console.Write (seatArray [i, j]);
}
Console.WriteLine ();
}
} else {
Console.WriteLine ("该座位没有人,无法退票!");
}
} else {
Console.WriteLine ("输入数值过大!");
}
break;
case "3":
Console.WriteLine ("当前座位图");
for (int i = 0; i < seatArray.GetLength (0); i++) {
for (int j = 0; j < seatArray.GetLength (1); j++) {
Console.Write (seatArray [i, j]);
}
Console.WriteLine ();
}
break;
case "0":
Console.WriteLine ("欢迎下次光临");
isBegin = false;
break;
default:
Console.WriteLine ("输入有误,请重新输入");
break;
}
}