From 4ecaefd567879455a5274367008652876040b5fa Mon Sep 17 00:00:00 2001 From: Shawqeem <1004837646@qq.com> Date: Thu, 27 Apr 2023 22:14:19 +0800 Subject: [PATCH] fix: :bug: fix the bug that map is not refreshed at the start and that map is always flickering fix the bug that map is not refreshed at the start and that map is always flickering --- logic/Client/MainWindow.xaml | 3 +- logic/Client/MainWindow.xaml.cs | 118 +++++++++++++------------------- logic/cmd/PlaybackServer.cmd | 6 +- 3 files changed, 51 insertions(+), 76 deletions(-) diff --git a/logic/Client/MainWindow.xaml b/logic/Client/MainWindow.xaml index beacab5..e1326a7 100644 --- a/logic/Client/MainWindow.xaml +++ b/logic/Client/MainWindow.xaml @@ -5,7 +5,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Client" mc:Ignorable="d" - Title="ClientVI" Height="738" Width="850" KeyDown="KeyBoardControl" Background="White" ResizeMode="CanResizeWithGrip" WindowStyle="None" MouseLeftButtonDown="DragWindow" MouseDoubleClick="Attack" MinHeight="738" MinWidth="1100"> + Title="ClientVI" Height="738" Width="850" KeyDown="KeyBoardControl" Background="White" ResizeMode="CanResizeWithGrip" WindowStyle="None" MouseLeftButtonDown="DragWindow" MouseDoubleClick="Attack" MinHeight="738" MinWidth="1100" + SizeChanged="ZoomMap"> diff --git a/logic/Client/MainWindow.xaml.cs b/logic/Client/MainWindow.xaml.cs index 4ab6665..340fbd4 100644 --- a/logic/Client/MainWindow.xaml.cs +++ b/logic/Client/MainWindow.xaml.cs @@ -34,8 +34,6 @@ namespace Client { public MainWindow() { - unitHeight = unitWidth = unit = 13; - bonusflag = true; timer = new DispatcherTimer { Interval = new TimeSpan(50000) // 每50ms刷新一次 @@ -60,6 +58,10 @@ namespace Client listOfGate = new List(); listOfHiddenGate = new List(); WindowStartupLocation = WindowStartupLocation.CenterScreen; + unit = Math.Sqrt(UpperLayerOfMap.ActualHeight * UpperLayerOfMap.ActualWidth) / 50; + unitFontsize = unit / 13; + unitHeight = UpperLayerOfMap.ActualHeight / 50; + unitWidth = UpperLayerOfMap.ActualWidth / 50; ReactToCommandline(); } @@ -194,6 +196,7 @@ namespace Client 0 => PlayerType.NullPlayerType, 1 => PlayerType.StudentPlayer, 2 => PlayerType.TrickerPlayer, + _ => PlayerType.NullPlayerType }; playerMsg.PlayerType = playerType; if (Convert.ToInt64(comInfo[3]) == 1) @@ -268,9 +271,9 @@ namespace Client { TextBox icon = new() { - FontSize = 10, - Width = 20, - Height = 20, + FontSize = 7 * unitFontsize, + Width = unitWidth, + Height = unitHeight, Text = text, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, @@ -282,37 +285,23 @@ namespace Client UpperLayerOfMap.Children.Add(icon); } - private void ZoomMap() - { - for (int i = 0; i < 50; i++) - { - for (int j = 0; j < 50; j++) - { - if (mapPatches[i, j] != null && (mapPatches[i, j].Width != UpperLayerOfMap.ActualWidth / 50 || mapPatches[i, j].Height != UpperLayerOfMap.ActualHeight / 50)) - { - mapPatches[i, j].Width = UpperLayerOfMap.ActualWidth / 50; - mapPatches[i, j].Height = UpperLayerOfMap.ActualHeight / 50; - mapPatches[i, j].HorizontalAlignment = HorizontalAlignment.Left; - mapPatches[i, j].VerticalAlignment = VerticalAlignment.Top; - mapPatches[i, j].Margin = new Thickness(UpperLayerOfMap.ActualWidth / 50 * j, UpperLayerOfMap.ActualHeight / 50 * i, 0, 0); - } - } - } - } - - private void ZoomMapAtFirst() + private void ZoomMap(object sender, SizeChangedEventArgs e) { + unit = Math.Sqrt(UpperLayerOfMap.ActualHeight * UpperLayerOfMap.ActualWidth) / 50; + unitFontsize = unit / 13; + unitHeight = UpperLayerOfMap.ActualHeight / 50; + unitWidth = UpperLayerOfMap.ActualWidth / 50; for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { if (mapPatches[i, j] != null) { - mapPatches[i, j].Width = UpperLayerOfMap.ActualWidth / 50; - mapPatches[i, j].Height = UpperLayerOfMap.ActualHeight / 50; + mapPatches[i, j].Width = unitWidth; + mapPatches[i, j].Height = unitHeight; mapPatches[i, j].HorizontalAlignment = HorizontalAlignment.Left; mapPatches[i, j].VerticalAlignment = VerticalAlignment.Top; - mapPatches[i, j].Margin = new Thickness(UpperLayerOfMap.ActualWidth / 50 * j, UpperLayerOfMap.ActualHeight / 50 * i, 0, 0); + mapPatches[i, j].Margin = new Thickness(unitWidth * j, unitHeight * i, 0, 0); } } } @@ -330,7 +319,7 @@ namespace Client Height = unitHeight, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, - Margin = new Thickness(Width * (j), Height * (i), 0, 0) + Margin = new Thickness(unitWidth * j, unitHeight * i, 0, 0)//unitWidth cannot be replaced by Width }; switch (defaultMap[i, j]) { @@ -697,7 +686,7 @@ namespace Client MaxButton.Content = "🗖"; foreach (var obj in listOfHuman) { - if (obj.PlayerId < GameData.numOfStudent && obj.StudentType != StudentType.Robot) + if (!isDataFixed[obj.PlayerId] && obj.PlayerId < GameData.numOfStudent && obj.StudentType != StudentType.Robot) { IStudentType occupation = (IStudentType)OccupationFactory.FindIOccupation(Transformation.ToStudentType(obj.StudentType)); totalLife[obj.PlayerId] = occupation.MaxHp; @@ -709,60 +698,52 @@ namespace Client coolTime[i, obj.PlayerId] = iActiveSkill.SkillCD; ++i; } + isDataFixed[obj.PlayerId] = true; } } foreach (var obj in listOfButcher) { - IGhostType occupation1 = (IGhostType)OccupationFactory.FindIOccupation(Transformation.ToTrickerType(obj.TrickerType)); - int j = 0; - foreach (var skill in occupation1.ListOfIActiveSkill) + if (!isDataFixed[obj.PlayerId]) { - var iActiveSkill = SkillFactory.FindIActiveSkill(skill); - coolTime[j, GameData.numOfStudent] = iActiveSkill.SkillCD; - ++j; + IGhostType occupation1 = (IGhostType)OccupationFactory.FindIOccupation(Transformation.ToTrickerType(obj.TrickerType)); + int j = 0; + foreach (var skill in occupation1.ListOfIActiveSkill) + { + var iActiveSkill = SkillFactory.FindIActiveSkill(skill); + coolTime[j, GameData.numOfStudent] = iActiveSkill.SkillCD; + ++j; + } + isDataFixed[obj.PlayerId] = true; } } if (StatusBarsOfSurvivor != null) { for (int i = 0; i < GameData.numOfStudent; i++) { - StatusBarsOfSurvivor[i].SetFontSize(12 * UpperLayerOfMap.ActualHeight / 650); StatusBarsOfSurvivor[i].NewData(totalLife, totalDeath, coolTime); } } if (StatusBarsOfHunter != null) { - StatusBarsOfHunter.SetFontSize(12 * UpperLayerOfMap.ActualHeight / 650); StatusBarsOfHunter.NewData(totalLife, totalDeath, coolTime); } - if (StatusBarsOfCircumstance != null) - StatusBarsOfCircumstance.SetFontSize(12 * UpperLayerOfMap.ActualHeight / 650); // 完成窗口信息更新 + if (StatusBarsOfSurvivor != null) + { + for (int i = 0; i < GameData.numOfStudent; i++) + { + StatusBarsOfSurvivor[i].SetFontSize(12 * unitFontsize); + } + } + if (StatusBarsOfHunter != null) + StatusBarsOfHunter.SetFontSize(12 * unitFontsize); + if (StatusBarsOfCircumstance != null) + StatusBarsOfCircumstance.SetFontSize(12 * unitFontsize); if (!isClientStocked) { - unit = Math.Sqrt(UpperLayerOfMap.ActualHeight * UpperLayerOfMap.ActualWidth) / 50; - unitHeight = UpperLayerOfMap.ActualHeight / 50; - unitWidth = UpperLayerOfMap.ActualWidth / 50; try { - // if (log != null) - //{ - // string temp = ""; - // for (int i = 0; i < dataDict[GameObjType.Character].Count; i++) - // { - // temp += Convert.ToString(dataDict[GameObjType.Character][i].MessageOfCharacter.TeamID) + "\n"; - // } - // log.Content = temp; - // } UpperLayerOfMap.Children.Clear(); - // if ((communicator == null || !communicator.Client.IsConnected) && !isPlaybackMode) - //{ - // UnderLayerOfMap.Children.Clear(); - // throw new Exception("Client is unconnected."); - // } - // else - //{ - foreach (var data in listOfAll) { StatusBarsOfCircumstance.SetValue(data, gateOpened, isEmergencyDrawed, isEmergencyOpened, playerID, isPlaybackMode); @@ -770,7 +751,6 @@ namespace Client if (!hasDrawed && mapFlag) { DrawMap(); - ZoomMapAtFirst(); } foreach (var data in listOfHuman) { @@ -791,7 +771,7 @@ namespace Client icon.Fill = Brushes.Gray; TextBox num = new() { - FontSize = 7 * UpperLayerOfMap.ActualHeight / 650, + FontSize = 7 * unitFontsize, Width = 2 * radiusTimes * unitWidth, Height = 2 * radiusTimes * unitHeight, Text = Convert.ToString(data.PlayerId), @@ -943,7 +923,7 @@ namespace Client int deg = (int)(100.0 * data.Progress / Preparation.Utility.GameData.degreeOfFixedGenerator); TextBox icon = new() { - FontSize = 8 * UpperLayerOfMap.ActualHeight / 650, + FontSize = 8 * unitFontsize, Width = unitWidth, Height = unitHeight, Text = Convert.ToString(deg), @@ -965,7 +945,7 @@ namespace Client int deg = (int)(100.0 * data.Progress / Preparation.Utility.GameData.degreeOfOpenedChest); TextBox icon = new() { - FontSize = 8 * UpperLayerOfMap.ActualHeight / 650, + FontSize = 8 * unitFontsize, Width = unitWidth, Height = unitHeight, Text = Convert.ToString(deg), @@ -987,7 +967,7 @@ namespace Client int deg = (int)(100.0 * data.Progress / Preparation.Utility.GameData.degreeOfOpenedDoorway); TextBox icon = new() { - FontSize = 8 * UpperLayerOfMap.ActualHeight / 650, + FontSize = 8 * unitFontsize, Width = unitWidth, Height = unitHeight, Text = Convert.ToString(deg), @@ -1009,7 +989,7 @@ namespace Client { TextBox icon = new() { - FontSize = 9 * UpperLayerOfMap.ActualHeight / 650, + FontSize = 9 * unitFontsize, Width = unitWidth, Height = unitHeight, HorizontalAlignment = HorizontalAlignment.Left, @@ -1042,7 +1022,7 @@ namespace Client isEmergencyOpened = true; TextBox icon = new() { - FontSize = 9 * UpperLayerOfMap.ActualHeight / 650, + FontSize = 9 * unitFontsize, Width = unitWidth, Height = unitHeight, Text = Convert.ToString("🔓"), @@ -1056,8 +1036,6 @@ namespace Client UpperLayerOfMap.Children.Add(icon); } } - //} - ZoomMap(); } catch (Exception exc) { @@ -1440,7 +1418,6 @@ namespace Client private MessageOfTricker? butcher = null; private bool humanOrButcher;//true for human - private bool bonusflag; private bool mapFlag = false; private bool hasDrawed = false; public int[,] defaultMap = new int[,] { @@ -1502,7 +1479,8 @@ namespace Client bool isSpectatorMode = false; bool isEmergencyOpened = false; bool isEmergencyDrawed = false; - bool isDataFixed = false; + bool[] isDataFixed = new bool[5] { false, false, false, false, false }; + double unitFontsize = 10; const double radiusTimes = 1.0 * Preparation.Utility.GameData.characterRadius / Preparation.Utility.GameData.numOfPosGridPerCell; const double bulletRadiusTimes = 1.0 * GameData.bulletRadius / Preparation.Utility.GameData.numOfPosGridPerCell; private int[] totalLife = new int[4] { 100, 100, 100, 100 }, totalDeath = new int[4] { 100, 100, 100, 100 }; diff --git a/logic/cmd/PlaybackServer.cmd b/logic/cmd/PlaybackServer.cmd index c3dd0bb..916c9ea 100644 --- a/logic/cmd/PlaybackServer.cmd +++ b/logic/cmd/PlaybackServer.cmd @@ -1,6 +1,2 @@ @echo off -::start cmd /k ..\Server\bin\Debug\net6.0\Server.exe --ip 0.0.0.0 --port 8888 --studentCount 4 --trickerCount 1 --gameTimeInSecond 600 --fileName test --playback true - -ping -n 2 127.0.0.1 > NUL - -start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port 8888 --characterID 2030 \ No newline at end of file +start cmd /k ..\Server\bin\Debug\net6.0\Server.exe --port 8888 --fileName .\ladder1.thuaipb --playback --playbackSpeed 4.0