diff --git a/logic/Client/MainWindow.xaml.cs b/logic/Client/MainWindow.xaml.cs index bdb1b4b..a676f8f 100644 --- a/logic/Client/MainWindow.xaml.cs +++ b/logic/Client/MainWindow.xaml.cs @@ -58,6 +58,7 @@ namespace Client listOfDoor = new List(); listOfGate = new List(); listOfHiddenGate = new List(); + countList = new List(); WindowStartupLocation = WindowStartupLocation.CenterScreen; unit = Math.Sqrt(UpperLayerOfMap.ActualHeight * UpperLayerOfMap.ActualWidth) / 50; unitFontsize = unit / 13; @@ -112,7 +113,7 @@ namespace Client return; } _ = Parser.Default.ParseArguments(args).WithParsed(o => - { options = o; }); + { options = o; }); if (options != null && Convert.ToInt64(options.PlayerID) > 2023) { isSpectatorMode = true; @@ -159,7 +160,7 @@ namespace Client { var pbClient = new PlaybackClient(fileName, pbSpeed); int[,]? map; - if ((map = pbClient.ReadDataFromFile(listOfProp, listOfHuman, listOfButcher, listOfBullet, listOfBombedBullet, listOfAll, listOfChest, listOfClassroom, listOfDoor, listOfHiddenGate, listOfGate, drawPicLock)) != null) + if ((map = pbClient.ReadDataFromFile(listOfProp, listOfHuman, listOfButcher, listOfBullet, listOfBombedBullet, listOfAll, listOfChest, listOfClassroom, listOfDoor, listOfHiddenGate, listOfGate, drawPicLock, countList)) != null) { isClientStocked = false; PorC.Content = "⏸"; @@ -311,6 +312,15 @@ namespace Client private void DrawMap() { + classroomArray = new TextBlock[countList[0]]; + doorArray = new TextBlock[countList[1]]; + chestArray = new TextBlock[countList[2]]; + gateArray = new TextBlock[countList[3]]; + classroomPositionIndex = new int[countList[0]]; + doorPositionIndex = new int[countList[1]]; + chestPositionIndex = new int[countList[2]]; + gatePositionIndex = new int[countList[3]]; + int cntOfClassroom = 0, cntOfDoor = 0, cntOfGate = 0, cntOfChest = 0; for (int i = 0; i < defaultMap.GetLength(0); i++) { for (int j = 0; j < defaultMap.GetLength(1); j++) @@ -336,10 +346,38 @@ namespace Client case 8: mapPatches[i, j].Fill = Brushes.LightPink; mapPatches[i, j].Stroke = Brushes.LightPink; - break;//machine + classroomPositionIndex[cntOfClassroom] = 50 * i + j; + classroomArray[cntOfClassroom] = new TextBlock() + { + FontSize = 8 * unitFontsize,// + Width = unitWidth,// + Height = unitHeight,// + Text = Convert.ToString(-1),// + TextAlignment = TextAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top, + Margin = new Thickness(j * unitWidth / 1000.0 - unitWidth / 2, i * unitHeight / 1000.0 - unitHeight / 2, 0, 0),// + Background = Brushes.Transparent, + }; + ++cntOfClassroom; + break;//classroom case 9: mapPatches[i, j].Fill = Brushes.LightSkyBlue; mapPatches[i, j].Stroke = Brushes.LightSkyBlue; + gatePositionIndex[cntOfGate] = 50 * i + j; + gateArray[cntOfGate] = new TextBlock() + { + FontSize = 8 * unitFontsize, + Width = unitWidth, + Height = unitHeight, + Text = Convert.ToString(-1), + TextAlignment = TextAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top, + Margin = new Thickness(j * unitWidth / 1000.0 - unitWidth / 2, i * unitHeight / 1000.0 - unitHeight / 2, 0, 0), + Background = Brushes.Transparent, + }; + ++cntOfGate; break;//gate case 10: break;//emergency @@ -352,10 +390,38 @@ namespace Client case 14: mapPatches[i, j].Fill = Brushes.Khaki; mapPatches[i, j].Stroke = Brushes.Khaki; + doorPositionIndex[cntOfDoor] = 50 * i + j; + doorArray[cntOfDoor] = new TextBlock() + { + FontSize = 9 * unitFontsize, + Width = unitWidth, + Height = unitHeight, + Text = Convert.ToString(-1), + TextAlignment = TextAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top, + Margin = new Thickness(j * unitWidth / 1000.0 - unitWidth / 2, i * unitHeight / 1000.0 - unitHeight / 2, 0, 0), + Background = Brushes.Transparent, + }; + ++cntOfDoor; break;//door case 15: mapPatches[i, j].Fill = Brushes.Orange; mapPatches[i, j].Stroke = Brushes.Orange; + chestPositionIndex[cntOfChest] = 50 * i + j; + chestArray[cntOfChest] = new TextBlock() + { + FontSize = 8 * unitFontsize, + Width = unitWidth, + Height = unitHeight, + Text = Convert.ToString(-1), + TextAlignment = TextAlignment.Center, + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top, + Margin = new Thickness(j * unitWidth / 1000.0 - unitWidth / 2, i * unitHeight / 1000.0 - unitHeight / 2, 0, 0), + Background = Brushes.Transparent, + }; + ++cntOfChest; break;//chest default: break; @@ -419,6 +485,7 @@ namespace Client switch (content.GameState) { case GameState.GameStart: + MessageOfMap mapMessage = new MessageOfMap(); foreach (var obj in content.ObjMessage) { switch (obj.MessageOfObjCase) @@ -459,11 +526,16 @@ namespace Client listOfGate.Add(obj.GateMessage); break; case MessageOfObj.MessageOfObjOneofCase.MapMessage: - GetMap(obj.MapMessage); + mapMessage = obj.MapMessage; break; } } + countList.Add(listOfClassroom.Count); + countList.Add(listOfDoor.Count); + countList.Add(listOfChest.Count); + countList.Add(listOfGate.Count); listOfAll.Add(content.AllMessage); + GetMap(mapMessage); break; case GameState.GameRunning: foreach (var obj in content.ObjMessage) @@ -522,9 +594,17 @@ namespace Client switch (obj.MessageOfObjCase) { case MessageOfObj.MessageOfObjOneofCase.StudentMessage: + if (humanOrButcher && obj.StudentMessage.PlayerId == playerID) + { + human = obj.StudentMessage; + } listOfHuman.Add(obj.StudentMessage); break; case MessageOfObj.MessageOfObjOneofCase.TrickerMessage: + if (!humanOrButcher && obj.TrickerMessage.PlayerId == playerID) + { + butcher = obj.TrickerMessage; + } listOfButcher.Add(obj.TrickerMessage); break; case MessageOfObj.MessageOfObjOneofCase.PropMessage: @@ -572,8 +652,8 @@ namespace Client private bool CanSee(MessageOfStudent msg) { - //if (msg.PlayerState == PlayerState.Quit || msg.PlayerState == PlayerState.Graduated) - // return false; + if (msg.PlayerState == PlayerState.Quit || msg.PlayerState == PlayerState.Graduated) + return false; //if (isSpectatorMode || isPlaybackMode) // return true; //if (humanOrButcher && human != null) @@ -677,6 +757,50 @@ namespace Client return true; } + private int FindIndexOfClassroom(MessageOfClassroom msg) + { + for (int i = 0; i < classroomPositionIndex.Length; ++i) + { + int k = msg.X / 1000 * 50 + msg.Y / 1000; + if (k == classroomPositionIndex[i]) + return i; + } + return -1; + } + + private int FindIndexOfGate(MessageOfGate msg) + { + for (int i = 0; i < gatePositionIndex.Length; ++i) + { + int k = msg.X / 1000 * 50 + msg.Y / 1000; + if (k == gatePositionIndex[i]) + return i; + } + return -1; + } + + private int FindIndexOfDoor(MessageOfDoor msg) + { + for (int i = 0; i < doorPositionIndex.Length; ++i) + { + int k = msg.X / 1000 * 50 + msg.Y / 1000; + if (k == doorPositionIndex[i]) + return i; + } + return -1; + } + + private int FindIndexOfChest(MessageOfChest msg) + { + for (int i = 0; i < chestPositionIndex.Length; ++i) + { + int k = msg.X / 1000 * 50 + msg.Y / 1000; + if (k == chestPositionIndex[i]) + return i; + } + return -1; + } + private void Refresh(object? sender, EventArgs e) //log未更新 { lock (drawPicLock) // 加锁是必要的,画图操作和接收信息操作不能同时进行 @@ -763,22 +887,21 @@ namespace Client }; if (data.StudentType == StudentType.Robot) icon.Fill = Brushes.Gray; - TextBox num = new() + TextBlock num = new() { FontSize = 7 * unitFontsize, Width = 2 * radiusTimes * unitWidth, Height = 2 * radiusTimes * unitHeight, Text = Convert.ToString(data.PlayerId), + TextAlignment = TextAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth * radiusTimes, data.X * unitHeight / 1000.0 - unitHeight * radiusTimes, 0, 0), Background = Brushes.Transparent, - BorderBrush = Brushes.Transparent, - IsReadOnly = true, Foreground = Brushes.White, }; - if (data.StudentType == StudentType.Robot) - num.Text = Convert.ToString(data.PlayerId - Preparation.Utility.GameData.numOfPeople); + //if (data.StudentType == StudentType.Robot) + // num.Text = Convert.ToString(data.PlayerId - Preparation.Utility.GameData.numOfPeople); UpperLayerOfMap.Children.Add(icon); UpperLayerOfMap.Children.Add(num); } @@ -830,6 +953,9 @@ namespace Client case Protobuf.PropType.RecoveryFromDizziness: DrawProp(data, "🕶"); break; + case Protobuf.PropType.CraftingBench: + DrawProp(data, "🎰"); + break; default: DrawProp(data, ""); break; @@ -857,6 +983,7 @@ namespace Client case Protobuf.BulletType.CommonAttackOfTricker: case Protobuf.BulletType.BombBomb: case Protobuf.BulletType.JumpyDumpty: + case Protobuf.BulletType.Strike: icon.Fill = Brushes.Red; break; default: @@ -901,12 +1028,6 @@ namespace Client UpperLayerOfMap.Children.Add(icon); break; } - //case Protobuf.BulletType.LineBullet: - // { - // double bombRange = data.BombRange / 1000; - // DrawLaser(new Point(data.Y * unitWidth / 1000.0, data.X * unitHeight / 1000.0), -data.FacingDirection + Math.PI / 2, bombRange * unitHeight, 0.5 * unitWidth); - // break; - // } default: break; } @@ -915,93 +1036,65 @@ namespace Client foreach (var data in listOfClassroom) { int deg = (int)(100.0 * data.Progress / Preparation.Utility.GameData.degreeOfFixedGenerator); - TextBox icon = new() - { - FontSize = 8 * unitFontsize, - Width = unitWidth, - Height = unitHeight, - Text = Convert.ToString(deg), - HorizontalAlignment = HorizontalAlignment.Left, - VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0), - Background = Brushes.Transparent, - BorderBrush = Brushes.Transparent, - IsReadOnly = true - }; + int idx = FindIndexOfClassroom(data); + classroomArray[idx].FontSize = 8 * unitFontsize; + classroomArray[idx].Width = unitWidth; + classroomArray[idx].Height = unitHeight; + classroomArray[idx].Text = Convert.ToString(deg); + classroomArray[idx].Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0); if (deg == 100) { - icon.Text = "A+"; + classroomArray[idx].Text = "A+"; } - UpperLayerOfMap.Children.Add(icon); + UpperLayerOfMap.Children.Add(classroomArray[idx]); } foreach (var data in listOfChest) { int deg = (int)(100.0 * data.Progress / Preparation.Utility.GameData.degreeOfOpenedChest); - TextBox icon = new() - { - FontSize = 8 * unitFontsize, - Width = unitWidth, - Height = unitHeight, - Text = Convert.ToString(deg), - HorizontalAlignment = HorizontalAlignment.Left, - VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0), - Background = Brushes.Transparent, - BorderBrush = Brushes.Transparent, - IsReadOnly = true - }; + int idx = FindIndexOfChest(data); + chestArray[idx].FontSize = 8 * unitFontsize; + chestArray[idx].Width = unitWidth; + chestArray[idx].Height = unitHeight; + chestArray[idx].Text = Convert.ToString(deg); + chestArray[idx].Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0); if (deg == 100) { - icon.Text = "Ø"; + chestArray[idx].Text = "Ø"; } - UpperLayerOfMap.Children.Add(icon); + UpperLayerOfMap.Children.Add(chestArray[idx]); } foreach (var data in listOfGate) { int deg = (int)(100.0 * data.Progress / Preparation.Utility.GameData.degreeOfOpenedDoorway); - TextBox icon = new() - { - FontSize = 8 * unitFontsize, - Width = unitWidth, - Height = unitHeight, - Text = Convert.ToString(deg), - HorizontalAlignment = HorizontalAlignment.Left, - VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0), - Background = Brushes.Transparent, - BorderBrush = Brushes.Transparent, - IsReadOnly = true - }; + int idx = FindIndexOfGate(data); + gateArray[idx].FontSize = 8 * unitFontsize; + gateArray[idx].Width = unitWidth; + gateArray[idx].Height = unitHeight; + gateArray[idx].Text = Convert.ToString(deg); + gateArray[idx].Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0); if (deg == 100) { gateOpened = true; - icon.Text = "🔓"; + gateArray[idx].Text = "🔓"; } - UpperLayerOfMap.Children.Add(icon); + UpperLayerOfMap.Children.Add(gateArray[idx]); } foreach (var data in listOfDoor) { - TextBox icon = new() - { - FontSize = 9 * unitFontsize, - Width = unitWidth, - Height = unitHeight, - HorizontalAlignment = HorizontalAlignment.Left, - VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0), - Background = Brushes.Transparent, - BorderBrush = Brushes.Transparent, - IsReadOnly = true - }; + int idx = FindIndexOfDoor(data); + doorArray[idx].FontSize = 9 * unitFontsize; + doorArray[idx].Width = unitWidth; + doorArray[idx].Height = unitHeight; + doorArray[idx].Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0); if (data.IsOpen) { - icon.Text = Convert.ToString("🔓"); + doorArray[idx].Text = Convert.ToString("🔓"); } else { - icon.Text = Convert.ToString("🔒"); + doorArray[idx].Text = Convert.ToString("🔒"); } - UpperLayerOfMap.Children.Add(icon); + UpperLayerOfMap.Children.Add(doorArray[idx]); } foreach (var data in listOfHiddenGate) { @@ -1014,20 +1107,19 @@ namespace Client if (data.Opened) { isEmergencyOpened = true; - TextBox icon = new() + hiddenGateArray = new TextBlock() { FontSize = 9 * unitFontsize, Width = unitWidth, Height = unitHeight, Text = Convert.ToString("🔓"), + TextAlignment = TextAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0), Background = Brushes.Transparent, - BorderBrush = Brushes.Transparent, - IsReadOnly = true }; - UpperLayerOfMap.Children.Add(icon); + UpperLayerOfMap.Children.Add(hiddenGateArray); } } } @@ -1416,6 +1508,18 @@ namespace Client private List listOfDoor; private List listOfGate; private List listOfHiddenGate; + + private TextBlock[] classroomArray; + private int[] classroomPositionIndex; + private TextBlock[] chestArray; + private int[] chestPositionIndex; + private TextBlock[] doorArray; + private int[] doorPositionIndex; + private TextBlock[] gateArray; + private int[] gatePositionIndex; + private TextBlock hiddenGateArray;//make a map from the position of icons to the index + private List countList; + private object drawPicLock = new object(); private MessageOfStudent? human = null; private MessageOfTricker? butcher = null; @@ -1489,4 +1593,4 @@ namespace Client private int[] totalLife = new int[4] { 100, 100, 100, 100 }, totalDeath = new int[4] { 100, 100, 100, 100 }; private int[,] coolTime = new int[3, 5] { { 100, 100, 100, 100, 100 }, { 100, 100, 100, 100, 100 }, { 100, 100, 100, 100, 100 } }; } -} +} \ No newline at end of file diff --git a/logic/Client/PlaybackClient.cs b/logic/Client/PlaybackClient.cs index 11acdc5..ad383d8 100644 --- a/logic/Client/PlaybackClient.cs +++ b/logic/Client/PlaybackClient.cs @@ -39,7 +39,7 @@ namespace Client public int[,]? ReadDataFromFile(List listOfProp, List listOfHuman, List listOfButcher, List listOfBullet, List listOfBombedBullet, List listOfAll, List listOfChest, List listOfClassroom, - List listOfDoor, List listOfHiddenGate, List listOfGate, object dataLock) + List listOfDoor, List listOfHiddenGate, List listOfGate, object? dataLock, List countList) { if (Reader == null) return null; @@ -158,6 +158,10 @@ namespace Client break; } } + countList.Add(listOfClassroom.Count); + countList.Add(listOfDoor.Count); + countList.Add(listOfChest.Count); + countList.Add(listOfGate.Count); listOfAll.Add(content.AllMessage); break; case GameState.GameRunning: @@ -270,4 +274,4 @@ namespace Client return map; } } -} +} \ No newline at end of file diff --git a/logic/Client/Properties/launchSettings.json b/logic/Client/Properties/launchSettings.json index 59aa8f1..65ab520 100644 --- a/logic/Client/Properties/launchSettings.json +++ b/logic/Client/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Client": { "commandName": "Project", - "commandLineArgs": "--port 8892 --characterID 8880 --type 1 --occupation 1 --ip thuai6.eesast.com --cl" + "commandLineArgs": "--port 8888 --characterID 1 --type 1 --occupation 3" } } } \ No newline at end of file diff --git a/logic/Client/StatusBarOfHunter.xaml.cs b/logic/Client/StatusBarOfHunter.xaml.cs index d8ab43e..8f45351 100644 --- a/logic/Client/StatusBarOfHunter.xaml.cs +++ b/logic/Client/StatusBarOfHunter.xaml.cs @@ -169,6 +169,9 @@ namespace Client case Protobuf.PropType.RecoveryFromDizziness: prop0.Text = "🕶"; break; + case Protobuf.PropType.CraftingBench: + prop0.Text = "🎰"; + break; default: prop0.Text = ""; break; @@ -202,6 +205,9 @@ namespace Client case Protobuf.PropType.RecoveryFromDizziness: prop1.Text = "🕶"; break; + case Protobuf.PropType.CraftingBench: + prop1.Text = "🎰"; + break; default: prop1.Text = ""; break; @@ -235,6 +241,9 @@ namespace Client case Protobuf.PropType.RecoveryFromDizziness: prop2.Text = "🕶"; break; + case Protobuf.PropType.CraftingBench: + prop2.Text = "🎰"; + break; default: prop2.Text = ""; break; diff --git a/logic/Client/StatusBarOfSurvivor.xaml.cs b/logic/Client/StatusBarOfSurvivor.xaml.cs index 1830c7e..00141db 100644 --- a/logic/Client/StatusBarOfSurvivor.xaml.cs +++ b/logic/Client/StatusBarOfSurvivor.xaml.cs @@ -174,6 +174,9 @@ namespace Client case Protobuf.PropType.RecoveryFromDizziness: prop0.Text = "🕶"; break; + case Protobuf.PropType.CraftingBench: + prop0.Text = "🎰"; + break; default: prop0.Text = ""; break; @@ -207,6 +210,9 @@ namespace Client case Protobuf.PropType.RecoveryFromDizziness: prop1.Text = "🕶"; break; + case Protobuf.PropType.CraftingBench: + prop1.Text = "🎰"; + break; default: prop1.Text = ""; break; @@ -240,6 +246,9 @@ namespace Client case Protobuf.PropType.RecoveryFromDizziness: prop2.Text = "🕶"; break; + case Protobuf.PropType.CraftingBench: + prop2.Text = "🎰"; + break; default: prop2.Text = ""; break; diff --git a/logic/cmd/gameServer.cmd b/logic/cmd/gameServer.cmd index 68d9935..6cb6008 100644 --- a/logic/cmd/gameServer.cmd +++ b/logic/cmd/gameServer.cmd @@ -1,17 +1,17 @@ @echo off -start cmd /k ..\Server\bin\Debug\net6.0\Server.exe --ip 0.0.0.0 --port 8888 --studentCount 2 --trickerCount 1 --gameTimeInSecond 600 --fileName video --mapResource ".\map\map1_final.txt" +start cmd /k ..\Server\bin\Debug\net6.0\Server.exe --ip 0.0.0.0 --port 8888 --studentCount 4 --trickerCount 1 --gameTimeInSecond 600 --fileName video --mapResource ".\map\map2_final.txt" ping -n 2 127.0.0.1 > NUL start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 4 --type 2 --occupation 1 -start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 0 --type 1 --occupation 1 +start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 0 --type 1 --occupation 0 -start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 1 --type 1 --occupation 2 +start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 1 --type 1 --occupation 0 -::start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 2 --type 1 --occupation 5 +start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 2 --type 1 --occupation 0 -::start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 3 --type 1 --occupation 5 +start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 3 --type 1 --occupation 0 ::start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --port 8888 --characterID 2030 \ No newline at end of file