From 1b10e4f8cf8eb46cf1829e677225bbc5e9c23074 Mon Sep 17 00:00:00 2001 From: Shawqeem <1004837646@qq.com> Date: Sun, 26 Mar 2023 01:37:10 +0800 Subject: [PATCH] style: :art: improve the keyboard control to pick/throw/use props improve the keyboard control to pick/throw/use props --- logic/Client/MainWindow.xaml.cs | 499 +++++++++++++++++--------------- logic/Server/ArgumentOption.cs | 4 +- logic/Server/GameServer.cs | 4 +- logic/cmd/gameServer.cmd | 9 +- 4 files changed, 283 insertions(+), 233 deletions(-) diff --git a/logic/Client/MainWindow.xaml.cs b/logic/Client/MainWindow.xaml.cs index ea22f74..bbc8588 100644 --- a/logic/Client/MainWindow.xaml.cs +++ b/logic/Client/MainWindow.xaml.cs @@ -927,232 +927,230 @@ namespace Client { if (!isPlaybackMode) { - if(Keyboard.Modifiers == ModifierKeys.Control) - { - switch (e.Key) - { - case Key.D1: - PropMsg msgP1 = new() - { - PlayerId = playerID, - PropType = PropType.AddSpeed, - }; - client.PickProp(msgP1); - break; - case Key.D2: - PropMsg msgP2 = new() - { - PlayerId = playerID, - PropType = PropType.AddLifeOrAp, - }; - client.PickProp(msgP2); - break; - case Key.D3: - PropMsg msgP3 = new() - { - PlayerId = playerID, - PropType = PropType.AddHpOrAp, - }; - client.PickProp(msgP3); - break; - case Key.D4: - PropMsg msgP4 = new() - { - PlayerId = playerID, - PropType = PropType.ShieldOrSpear, - }; - client.PickProp(msgP4); - break; - case Key.D5: - PropMsg msgP5 = new() - { - PlayerId = playerID, - PropType = PropType.Key3, - }; - client.PickProp(msgP5); - break; - case Key.D6: - PropMsg msgP6 = new() - { - PlayerId = playerID, - PropType = PropType.Key5, - }; - client.PickProp(msgP6); - break; - case Key.D7: - PropMsg msgP7 = new() - { - PlayerId = playerID, - PropType = PropType.Key6, - }; - client.PickProp(msgP7); - break; - default: - break; - } - } - else if (Keyboard.Modifiers == ModifierKeys.Alt) - { - switch (e.Key) - { - case Key.D1: - PropMsg msgP1 = new() - { - PlayerId = playerID, - PropType = PropType.AddSpeed, - }; - client.UseProp(msgP1); - break; - case Key.D2: - PropMsg msgP2 = new() - { - PlayerId = playerID, - PropType = PropType.AddLifeOrAp, - }; - client.UseProp(msgP2); - break; - case Key.D3: - PropMsg msgP3 = new() - { - PlayerId = playerID, - PropType = PropType.AddHpOrAp, - }; - client.UseProp(msgP3); - break; - case Key.D4: - PropMsg msgP4 = new() - { - PlayerId = playerID, - PropType = PropType.ShieldOrSpear, - }; - client.UseProp(msgP4); - break; - case Key.D5: - PropMsg msgP5 = new() - { - PlayerId = playerID, - PropType = PropType.Key3, - }; - client.UseProp(msgP5); - break; - case Key.D6: - PropMsg msgP6 = new() - { - PlayerId = playerID, - PropType = PropType.Key5, - }; - client.UseProp(msgP6); - break; - case Key.D7: - PropMsg msgP7 = new() - { - PlayerId = playerID, - PropType = PropType.Key6, - }; - client.UseProp(msgP7); - break; - default: - break; - } - } - else if(Keyboard.Modifiers == ModifierKeys.Shift) - { - switch (e.Key) - { - case Key.D1: - PropMsg msgP1 = new() - { - PlayerId = playerID, - PropType = PropType.AddSpeed, - }; - client.ThrowProp(msgP1); - break; - case Key.D2: - PropMsg msgP2 = new() - { - PlayerId = playerID, - PropType = PropType.AddLifeOrAp, - }; - client.ThrowProp(msgP2); - break; - case Key.D3: - PropMsg msgP3 = new() - { - PlayerId = playerID, - PropType = PropType.AddHpOrAp, - }; - client.ThrowProp(msgP3); - break; - case Key.D4: - PropMsg msgP4 = new() - { - PlayerId = playerID, - PropType = PropType.ShieldOrSpear, - }; - client.ThrowProp(msgP4); - break; - case Key.D5: - PropMsg msgP5 = new() - { - PlayerId = playerID, - PropType = PropType.Key3, - }; - client.ThrowProp(msgP5); - break; - case Key.D6: - PropMsg msgP6 = new() - { - PlayerId = playerID, - PropType = PropType.Key5, - }; - client.ThrowProp(msgP6); - break; - case Key.D7: - PropMsg msgP7 = new() - { - PlayerId = playerID, - PropType = PropType.Key6, - }; - client.ThrowProp(msgP7); - break; - default: - break; - } - } - else if (Keyboard.Modifiers == ModifierKeys.Windows) - { - switch (e.Key) - { - case Key.D0: - SkillMsg msgS0 = new() - { - PlayerId = playerID, - SkillId = 0, - }; - client.UseSkill(msgS0); - break; - case Key.D1: - SkillMsg msgS1 = new() - { - PlayerId = playerID, - SkillId = 1, - }; - client.UseSkill(msgS1); - break; - case Key.D2: - SkillMsg msgS2 = new() - { - PlayerId = playerID, - SkillId = 2, - }; - client.UseSkill(msgS2); - break; - default: - break; - } - } - else - { + //if(Keyboard.Modifiers == ModifierKeys.Control) + //{ + // switch (e.Key) + // { + // case Key.D1: + // PropMsg msgP1 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddSpeed, + // }; + // client.PickProp(msgP1); + // break; + // case Key.D2: + // PropMsg msgP2 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddLifeOrAp, + // }; + // client.PickProp(msgP2); + // break; + // case Key.D3: + // PropMsg msgP3 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddHpOrAp, + // }; + // client.PickProp(msgP3); + // break; + // case Key.D4: + // PropMsg msgP4 = new() + // { + // PlayerId = playerID, + // PropType = PropType.ShieldOrSpear, + // }; + // client.PickProp(msgP4); + // break; + // case Key.D5: + // PropMsg msgP5 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key3, + // }; + // client.PickProp(msgP5); + // break; + // case Key.D6: + // PropMsg msgP6 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key5, + // }; + // client.PickProp(msgP6); + // break; + // case Key.D7: + // PropMsg msgP7 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key6, + // }; + // client.PickProp(msgP7); + // break; + // default: + // break; + // } + //} + //else if (Keyboard.Modifiers == ModifierKeys.Alt) + //{ + // switch (e.Key) + // { + // case Key.D1: + // PropMsg msgP1 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddSpeed, + // }; + // client.UseProp(msgP1); + // break; + // case Key.D2: + // PropMsg msgP2 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddLifeOrAp, + // }; + // client.UseProp(msgP2); + // break; + // case Key.D3: + // PropMsg msgP3 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddHpOrAp, + // }; + // client.UseProp(msgP3); + // break; + // case Key.D4: + // PropMsg msgP4 = new() + // { + // PlayerId = playerID, + // PropType = PropType.ShieldOrSpear, + // }; + // client.UseProp(msgP4); + // break; + // case Key.D5: + // PropMsg msgP5 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key3, + // }; + // client.UseProp(msgP5); + // break; + // case Key.D6: + // PropMsg msgP6 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key5, + // }; + // client.UseProp(msgP6); + // break; + // case Key.D7: + // PropMsg msgP7 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key6, + // }; + // client.UseProp(msgP7); + // break; + // default: + // break; + // } + //} + //else if(Keyboard.Modifiers == ModifierKeys.Shift) + //{ + // switch (e.Key) + // { + // case Key.D1: + // PropMsg msgP1 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddSpeed, + // }; + // client.ThrowProp(msgP1); + // break; + // case Key.D2: + // PropMsg msgP2 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddLifeOrAp, + // }; + // client.ThrowProp(msgP2); + // break; + // case Key.D3: + // PropMsg msgP3 = new() + // { + // PlayerId = playerID, + // PropType = PropType.AddHpOrAp, + // }; + // client.ThrowProp(msgP3); + // break; + // case Key.D4: + // PropMsg msgP4 = new() + // { + // PlayerId = playerID, + // PropType = PropType.ShieldOrSpear, + // }; + // client.ThrowProp(msgP4); + // break; + // case Key.D5: + // PropMsg msgP5 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key3, + // }; + // client.ThrowProp(msgP5); + // break; + // case Key.D6: + // PropMsg msgP6 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key5, + // }; + // client.ThrowProp(msgP6); + // break; + // case Key.D7: + // PropMsg msgP7 = new() + // { + // PlayerId = playerID, + // PropType = PropType.Key6, + // }; + // client.ThrowProp(msgP7); + // break; + // default: + // break; + // } + //} + //else if (Keyboard.Modifiers == ModifierKeys.Windows) + //{ + // switch (e.Key) + // { + // case Key.D0: + // SkillMsg msgS0 = new() + // { + // PlayerId = playerID, + // SkillId = 0, + // }; + // client.UseSkill(msgS0); + // break; + // case Key.D1: + // SkillMsg msgS1 = new() + // { + // PlayerId = playerID, + // SkillId = 1, + // }; + // client.UseSkill(msgS1); + // break; + // case Key.D2: + // SkillMsg msgS2 = new() + // { + // PlayerId = playerID, + // SkillId = 2, + // }; + // client.UseSkill(msgS2); + // break; + // default: + // break; + // } + //} switch (e.Key) { case Key.W: @@ -1273,9 +1271,56 @@ namespace Client }; client.EndAllAction(msgE); break; + case Key.F: + PropMsg msgF = new() + { + PlayerId = playerID, + PropType= PropType.NullPropType, + }; + client.PickProp(msgF); + break; + case Key.C: + PropMsg msgC = new() + { + PlayerId = playerID, + PropType = PropType.NullPropType, + }; + client.ThrowProp(msgC); + break; + case Key.V: + PropMsg msgV = new() + { + PlayerId = playerID, + PropType = PropType.NullPropType, + }; + client.UseProp(msgV); + break; + case Key.B: + SkillMsg msgB = new() + { + PlayerId = playerID, + SkillId = 0, + }; + client.UseSkill(msgB); + break; + case Key.N: + SkillMsg msgN = new() + { + PlayerId = playerID, + SkillId = 1, + }; + client.UseSkill(msgN); + break; + case Key.M: + SkillMsg msgM = new() + { + PlayerId = playerID, + SkillId = 2, + }; + client.UseSkill(msgM); + break; default: break; - } } } } diff --git a/logic/Server/ArgumentOption.cs b/logic/Server/ArgumentOption.cs index 384635f..b931917 100644 --- a/logic/Server/ArgumentOption.cs +++ b/logic/Server/ArgumentOption.cs @@ -15,14 +15,14 @@ namespace Server [Option('p', "port", Required = true, HelpText = "Server listening port")] public ushort ServerPort { get; set; } = 10086; - [Option('n', "playerNum", Required = false, HelpText = "The number of teams, 1 by defualt")] + [Option('n', "playerNum", Required = false, HelpText = "The number of players, 1 by defualt")] public ushort playerNum { get; set; } = 1; [Option('t', "teamCount", Required = false, HelpText = "The number of teams, 1 by defualt")] public ushort TeamCount { get; set; } = 1; [Option('c', "playerCount", Required = false, HelpText = "The number of players per team, 1 by default")] - public ushort PlayerCountPerTeam { get; set; } = 1; + public ushort PlayerCountPerTeam { get; set; } = 4; [Option('g', "gameTimeInSecond", Required = false, HelpText = "The time of the game in second, 10 minutes by default")] public uint GameTimeInSecond { get; set; } = 10 * 60; diff --git a/logic/Server/GameServer.cs b/logic/Server/GameServer.cs index 83b6671..4fad72f 100644 --- a/logic/Server/GameServer.cs +++ b/logic/Server/GameServer.cs @@ -20,7 +20,8 @@ namespace Server protected readonly ArgumentOptions options; private HttpSender? httpSender; private object gameLock = new(); - private int playerNum => options.playerNum; // 注意修改 + private int playerNum = 0; + private int PlayerNum => playerNum; // 注意修改 private MessageToClient currentGameInfo = new(); private MessageOfObj currentMapMsg = new(); private object newsLock = new(); @@ -560,6 +561,7 @@ namespace Server public GameServer(ArgumentOptions options) { this.options = options; + this.playerNum = options.playerNum; //if (options.mapResource == DefaultArgumentOptions.MapResource) // this.game = new Game(MapInfo.defaultMap, options.TeamCount); //else diff --git a/logic/cmd/gameServer.cmd b/logic/cmd/gameServer.cmd index 7ccd625..2ba3de6 100644 --- a/logic/cmd/gameServer.cmd +++ b/logic/cmd/gameServer.cmd @@ -1,8 +1,11 @@ @echo off -start cmd /k ..\Server\bin\Debug\net6.0\Server.exe --port 8888 --teamCount 2 --playerCount 2 --gameTimeInSecond 600 --fileName test +start cmd /k ..\Server\bin\Debug\net6.0\Server.exe --port 8888 --teamCount 2 --playerNum 2 --gameTimeInSecond 600 --fileName test -ping -n 4 127.0.0.1 > NUL +ping -n 2 127.0.0.1 > NUL -start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port=8888 --characterID=4 --type=2 --occupation=1 +start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port=8888 --characterID=0 --type=1 --occupation=1 +ping -n 2 127.0.0.1 > NUL + +start cmd /k ..\Client\bin\Debug\net6.0-windows\Client.exe --cl --port=8888 --characterID=1 --type=1 --occupation=1