From 86b12234919929e0272ab68d46efe65aefa6d3ea Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 12 Jul 2018 15:39:53 +0800 Subject: [PATCH] update to v1.0.5 add two new map --- api/CreateGame_CN.md | 5 ++ src/monitor/MagCore.Monitor/Modules/ApiReq.cs | 4 +- .../MagCore.Monitor/Modules/GameLoader.cs | 2 +- .../Modules/KeyboardHandler.cs | 6 +-- .../MagCore.Monitor/Modules/Map/IMapLoader.cs | 3 ++ .../Modules/Map/RectMapLoader.cs | 28 ++++++++-- .../MagCore.Monitor/Modules/ScreenHandler.cs | 4 +- src/sdk/JustRush/Program.cs | 23 ++++++-- src/sdk/MagCore.Sdk/Helper/GameHelper.cs | 9 ++-- .../MagCore.Server/MagCore.Server.csproj | 6 +++ src/server/MagCore.Server/Maps/RectLarge.map | 53 +++++++++++++++++++ src/server/MagCore.Server/Maps/RectMid.map | 33 ++++++++++++ 12 files changed, 153 insertions(+), 23 deletions(-) create mode 100644 src/server/MagCore.Server/Maps/RectLarge.map create mode 100644 src/server/MagCore.Server/Maps/RectMid.map diff --git a/api/CreateGame_CN.md b/api/CreateGame_CN.md index 1009636..fc24aa1 100644 --- a/api/CreateGame_CN.md +++ b/api/CreateGame_CN.md @@ -16,6 +16,11 @@ Content-Type: application/json } ``` +支持的地图列表: +- 小地图: RectSmall +- 中型地图: RectMid +- 大型地图: RectLarge + ### 返回结果 Status Code: 200 diff --git a/src/monitor/MagCore.Monitor/Modules/ApiReq.cs b/src/monitor/MagCore.Monitor/Modules/ApiReq.cs index 4f64d98..d17f585 100644 --- a/src/monitor/MagCore.Monitor/Modules/ApiReq.cs +++ b/src/monitor/MagCore.Monitor/Modules/ApiReq.cs @@ -10,8 +10,8 @@ namespace MagCore.Monitor.Modules { public static class ApiReq { - //private static string _url = "http://106.75.33.221:6000/"; - private static string _url = "http://localhost:6000/"; + private static string _url = "http://106.75.33.221:6000/"; + //private static string _url = "http://localhost:6000/"; public static HttpClient CreateReq() { diff --git a/src/monitor/MagCore.Monitor/Modules/GameLoader.cs b/src/monitor/MagCore.Monitor/Modules/GameLoader.cs index 2f9d371..111744d 100644 --- a/src/monitor/MagCore.Monitor/Modules/GameLoader.cs +++ b/src/monitor/MagCore.Monitor/Modules/GameLoader.cs @@ -21,7 +21,7 @@ public static class GameLoader internal static Dictionary Players = null; - private static IMapLoader _map = null; + internal static IMapLoader _map = null; public static void Update() { //init a new thread to refresh the game list diff --git a/src/monitor/MagCore.Monitor/Modules/KeyboardHandler.cs b/src/monitor/MagCore.Monitor/Modules/KeyboardHandler.cs index 66205bf..f9412e0 100644 --- a/src/monitor/MagCore.Monitor/Modules/KeyboardHandler.cs +++ b/src/monitor/MagCore.Monitor/Modules/KeyboardHandler.cs @@ -22,11 +22,11 @@ public static void Update() var key = keys[0]; if (key >= Keys.D1 && key < (Keys)(Keys.D1 + GameListLoader.Games.Count)) { - ScreenHandler.ChangeSize(10, 10); - var sel = key - Keys.D1; GameLoader.Load(sel); - } + + ScreenHandler.ChangeSize(GameLoader._map.Width, GameLoader._map.Height); + } } break; diff --git a/src/monitor/MagCore.Monitor/Modules/Map/IMapLoader.cs b/src/monitor/MagCore.Monitor/Modules/Map/IMapLoader.cs index 4da8e02..3613f04 100644 --- a/src/monitor/MagCore.Monitor/Modules/Map/IMapLoader.cs +++ b/src/monitor/MagCore.Monitor/Modules/Map/IMapLoader.cs @@ -16,5 +16,8 @@ public interface IMapLoader void Draw(SpriteBatch sb, GameTime gt); Cell Locate(int x, int y); + + int Height { get; } + int Width { get; } } } diff --git a/src/monitor/MagCore.Monitor/Modules/Map/RectMapLoader.cs b/src/monitor/MagCore.Monitor/Modules/Map/RectMapLoader.cs index 57f10aa..379f680 100644 --- a/src/monitor/MagCore.Monitor/Modules/Map/RectMapLoader.cs +++ b/src/monitor/MagCore.Monitor/Modules/Map/RectMapLoader.cs @@ -19,7 +19,26 @@ public class RectMapLoader : IMapLoader private Color _color = Color.White; - private Position _origin = new Position(0, 0); + //private Position _origin = new Position(0, 0); + + public int Height + { + get + { + return Rows.Count; + } + } + public int Width + { + get + { + if (Rows.Count > 0) + return Rows[0].Cells.Count; + else + return 0; + } + } + public RectMapLoader() { @@ -42,8 +61,8 @@ public void SetMapData(dynamic data) count++; } - _origin.X = (Global.Graphics.PreferredBackBufferWidth - (Rows[0].Count * 16)) / 2; - _origin.Y = (Global.Graphics.PreferredBackBufferHeight - (Rows.Count * 16)) / 2; + //_origin.X = (Global.Graphics.PreferredBackBufferWidth - (Rows[0].Count * 16)) / 2; + //_origin.Y = (Global.Graphics.PreferredBackBufferHeight - (Rows.Count * 16)) / 2; } public void LoadContent(ContentManager content) @@ -66,7 +85,8 @@ public void Draw(SpriteBatch sb, GameTime gt) for (int j = 0; j < row.Count; j++) { Cell cell = row.Cells[j]; - Rectangle rect = new Rectangle(j * 16 + _origin.X, i * 16 + _origin.Y, 16, 16); + //Rectangle rect = new Rectangle(j * 16 + _origin.X, i * 16 + _origin.Y, 16, 16); + Rectangle rect = new Rectangle(j * 16, i * 16, 16, 16); switch (cell.Type) { case 0: diff --git a/src/monitor/MagCore.Monitor/Modules/ScreenHandler.cs b/src/monitor/MagCore.Monitor/Modules/ScreenHandler.cs index dc10239..5af0aee 100644 --- a/src/monitor/MagCore.Monitor/Modules/ScreenHandler.cs +++ b/src/monitor/MagCore.Monitor/Modules/ScreenHandler.cs @@ -17,8 +17,8 @@ public static void Reset() public static void ChangeSize(int col, int row) { - Global.Graphics.PreferredBackBufferWidth = col * 16 + 2; - Global.Graphics.PreferredBackBufferHeight = row * 16 + 2; + Global.Graphics.PreferredBackBufferWidth = col * 16; + Global.Graphics.PreferredBackBufferHeight = row * 16; Global.Graphics.ApplyChanges(); } } diff --git a/src/sdk/JustRush/Program.cs b/src/sdk/JustRush/Program.cs index 05c0650..40edc22 100644 --- a/src/sdk/JustRush/Program.cs +++ b/src/sdk/JustRush/Program.cs @@ -18,9 +18,6 @@ static void Main(string[] args) ServerHelper.Initialize("http://106.75.33.221:6000/"); //ServerHelper.Initialize("http://localhost:6000/"); - map = MapHelper.GetMap("RectSmall"); - game = new Game(map.Rows.Count, map.Rows[0].Count); - Player: Console.WriteLine("Enter nickname:"); input = Console.ReadLine(); @@ -38,11 +35,17 @@ static void Main(string[] args) } string gameId = string.Empty; + string mapName = string.Empty; Console.WriteLine("1: Create a new game"); Console.WriteLine("2: Join a game"); input = Console.ReadLine(); if (input == "1") + { + map = MapHelper.GetMap("RectSmall"); + game = new Game(map.Rows.Count, map.Rows[0].Count); gameId = GameHelper.CreateGame("RectSmall"); + + } else { Console.WriteLine("Game list:"); @@ -57,7 +60,11 @@ static void Main(string[] args) { for (int i = 0; i < list.Length; i++) { - Console.WriteLine(i.ToString() + " : " + list[i]); + if (list[i].state == 0) + { + Console.WriteLine("{0} : {1} 地图:{2}", i, list[i].id.ToString(), list[i].map.ToString()); + } + } } Console.WriteLine("Select a game to join:"); @@ -65,7 +72,12 @@ static void Main(string[] args) if (Int32.TryParse(input.Trim(), out int sel) && sel >= 0 && sel < list.Length) { - gameId = list[sel]; + gameId = list[sel].id.ToString(); + mapName = list[sel].map.ToString(); + + map = MapHelper.GetMap(mapName); + game = new Game(map.Rows.Count, map.Rows[0].Count); + } else { @@ -74,6 +86,7 @@ static void Main(string[] args) } } + game.Id = gameId; if (!GameHelper.JoinGame(gameId, self.Id)) diff --git a/src/sdk/MagCore.Sdk/Helper/GameHelper.cs b/src/sdk/MagCore.Sdk/Helper/GameHelper.cs index 8bd7d2e..3232c7f 100644 --- a/src/sdk/MagCore.Sdk/Helper/GameHelper.cs +++ b/src/sdk/MagCore.Sdk/Helper/GameHelper.cs @@ -102,7 +102,7 @@ public static bool GetGame(string gameId, ref Game game) return false; } - public static string[] GameList() + public static dynamic[] GameList() { var code = ApiReq.CreateReq() .WithMethod("api/game", "get") @@ -110,13 +110,10 @@ public static string[] GameList() if (code == System.Net.HttpStatusCode.OK) { var result = DynamicJson.Parse(json); - List games = new List(); + List games = new List(); foreach (var item in result) { - if ((int)item.state == 0) - { - games.Add(item.id.ToString()); - } + games.Add(item); } return games.ToArray(); diff --git a/src/server/MagCore.Server/MagCore.Server.csproj b/src/server/MagCore.Server/MagCore.Server.csproj index 84de16b..d9217db 100644 --- a/src/server/MagCore.Server/MagCore.Server.csproj +++ b/src/server/MagCore.Server/MagCore.Server.csproj @@ -24,6 +24,12 @@ + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/src/server/MagCore.Server/Maps/RectLarge.map b/src/server/MagCore.Server/Maps/RectLarge.map new file mode 100644 index 0000000..3a720ab --- /dev/null +++ b/src/server/MagCore.Server/Maps/RectLarge.map @@ -0,0 +1,53 @@ +E=4 +S=0 +D=0 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 +11111111111111111111111111111111111111111111111111 diff --git a/src/server/MagCore.Server/Maps/RectMid.map b/src/server/MagCore.Server/Maps/RectMid.map new file mode 100644 index 0000000..97173a2 --- /dev/null +++ b/src/server/MagCore.Server/Maps/RectMid.map @@ -0,0 +1,33 @@ +E=4 +S=0 +D=0 +111111111111111111111111111111 +100011111111111111111111110001 +101111111111111111111111111101 +101001111111111111111111100101 +111011111111111111111111110111 +111110111111111111111111011111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111111111111111111111111111111 +111110111111111111111111011111 +111011111111111111111111110111 +101001111111111111111111100101 +101111111111111111111111111101 +100011111111111111111111110001 +111111111111111111111111111111 \ No newline at end of file