Console.WriteLine ("請(qǐng)輸入電影院規(guī)模(整數(shù)):");
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 ("請(qǐng)輸入");
string numStr = Console.ReadLine ();
// 補(bǔ)充
switch (numStr) {
case "1":
Console.WriteLine ("執(zhí)行選座功能");
Console.Write ("請(qǐng)選擇行:");
int row = int.Parse (Console.ReadLine ());
row--;
Console.Write ("請(qǐng)選擇列:");
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 ("該座位已經(jīng)有人剩燥,請(qǐng)重新選擇!");
}
} else {
Console.WriteLine ("輸入數(shù)值過大托启!");
}
// 檢測(cè)1.是否越界 2.查重
// 設(shè)置數(shù)組
break;
case "2":
Console.WriteLine ("執(zhí)行退座功能");
Console.Write ("請(qǐng)選擇行:");
int row1 = int.Parse (Console.ReadLine ());
row1--;
Console.Write ("請(qǐng)選擇列:");
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 ("輸入數(shù)值過大舰罚!");
}
break;
case "3":
Console.WriteLine ("當(dāng)前座位圖");
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 ("輸入有誤方援,請(qǐng)重新輸入");
break;
}
}