diff --git a/.vs/Bowling/DesignTimeBuild/.dtbcache.v2 b/.vs/Bowling/DesignTimeBuild/.dtbcache.v2 index 02f8669..e2ddaac 100644 Binary files a/.vs/Bowling/DesignTimeBuild/.dtbcache.v2 and b/.vs/Bowling/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/Bowling/FileContentIndex/ae1d199b-49d2-4445-a221-676e55f405ee.vsidx b/.vs/Bowling/FileContentIndex/144a294b-9225-410a-b11d-79683234dd91.vsidx similarity index 95% rename from .vs/Bowling/FileContentIndex/ae1d199b-49d2-4445-a221-676e55f405ee.vsidx rename to .vs/Bowling/FileContentIndex/144a294b-9225-410a-b11d-79683234dd91.vsidx index a545fa9..39e52cf 100644 Binary files a/.vs/Bowling/FileContentIndex/ae1d199b-49d2-4445-a221-676e55f405ee.vsidx and b/.vs/Bowling/FileContentIndex/144a294b-9225-410a-b11d-79683234dd91.vsidx differ diff --git a/.vs/Bowling/FileContentIndex/3e5b10d1-6738-43b9-bce1-7acc81b77cdb.vsidx b/.vs/Bowling/FileContentIndex/3e5b10d1-6738-43b9-bce1-7acc81b77cdb.vsidx deleted file mode 100644 index 8122641..0000000 Binary files a/.vs/Bowling/FileContentIndex/3e5b10d1-6738-43b9-bce1-7acc81b77cdb.vsidx and /dev/null differ diff --git a/.vs/Bowling/FileContentIndex/544888fc-21ba-4ae3-a23a-9b22626db7dc.vsidx b/.vs/Bowling/FileContentIndex/44ec4c9d-d563-43c3-a76a-f42d9465aef5.vsidx similarity index 100% rename from .vs/Bowling/FileContentIndex/544888fc-21ba-4ae3-a23a-9b22626db7dc.vsidx rename to .vs/Bowling/FileContentIndex/44ec4c9d-d563-43c3-a76a-f42d9465aef5.vsidx diff --git a/.vs/Bowling/FileContentIndex/c44f0eb0-0ffc-4ff6-a158-767349595e58.vsidx b/.vs/Bowling/FileContentIndex/9748c7ed-d18a-4046-b072-9254ef58bb4f.vsidx similarity index 100% rename from .vs/Bowling/FileContentIndex/c44f0eb0-0ffc-4ff6-a158-767349595e58.vsidx rename to .vs/Bowling/FileContentIndex/9748c7ed-d18a-4046-b072-9254ef58bb4f.vsidx diff --git a/.vs/Bowling/v17/.suo b/.vs/Bowling/v17/.suo index 8d1fbbe..8d361f2 100644 Binary files a/.vs/Bowling/v17/.suo and b/.vs/Bowling/v17/.suo differ diff --git a/.vs/ProjectEvaluation/bowling.metadata.v2 b/.vs/ProjectEvaluation/bowling.metadata.v2 index 767881c..b73f1c3 100644 Binary files a/.vs/ProjectEvaluation/bowling.metadata.v2 and b/.vs/ProjectEvaluation/bowling.metadata.v2 differ diff --git a/.vs/ProjectEvaluation/bowling.projects.v2 b/.vs/ProjectEvaluation/bowling.projects.v2 index 9aa22c9..473ff3b 100644 Binary files a/.vs/ProjectEvaluation/bowling.projects.v2 and b/.vs/ProjectEvaluation/bowling.projects.v2 differ diff --git a/Bowling/Game1.cs b/Bowling/Game1.cs index a482336..3c22b1d 100644 --- a/Bowling/Game1.cs +++ b/Bowling/Game1.cs @@ -18,7 +18,7 @@ namespace Bowling } public class Game1 : Game { - private Color[] colors = { Color.White, Color.Red, Color.Black, Color.DeepSkyBlue, Color.DeepPink }; + private Color[] colors = { Color.White/*, Color.Red, Color.Black, Color.DeepSkyBlue, Color.DeepPink*/ }; private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; private static int gutter_height; @@ -67,7 +67,7 @@ namespace Bowling gutter_height = 50; ballStartPosition = new Vector2(10, gutter_top_y + (gutter_bottom_y - gutter_top_y) / 2 - 25); random = new Random(); - ball = new Ball(ballStartPosition, Vector2.Zero, colors[random.Next(colors.Length)], Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth); + ball = new Ball(ballStartPosition, Vector2.Zero, Color.White, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth); menu = new Menu(); player2 = new Player(); rowWidth = 80; @@ -138,6 +138,10 @@ namespace Bowling { ResetAll(); } + else if (msg == "12") + { + Exit(); + } else { player2.Deserialize(msg); @@ -224,7 +228,7 @@ namespace Bowling { player1.Score.Add(intermediateScore); intermediateScore = 0; - ball = new Ball(ballStartPosition, Vector2.Zero, Color.Blue, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth); + ball = new Ball(ballStartPosition, Vector2.Zero, Color.White, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth); ball.LoadContent(Content); if (player1.Score.Count <= 20 && player1.Score.Count % 2 == 0) { @@ -357,7 +361,7 @@ namespace Bowling private void ResetAll() { - ball = new Ball(ballStartPosition, Vector2.Zero, Color.Blue, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth); + ball = new Ball(ballStartPosition, Vector2.Zero, Color.White, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth); menu = new Menu(); player1.Score.Clear(); player2.Score.Clear(); diff --git a/Bowling/bin/Debug/netcoreapp3.1/.vs/Bowling/v17/.suo b/Bowling/bin/Debug/netcoreapp3.1/.vs/Bowling/v17/.suo index eea3dca..150bc8f 100644 Binary files a/Bowling/bin/Debug/netcoreapp3.1/.vs/Bowling/v17/.suo and b/Bowling/bin/Debug/netcoreapp3.1/.vs/Bowling/v17/.suo differ diff --git a/Bowling/bin/Debug/netcoreapp3.1/Bowling.dll b/Bowling/bin/Debug/netcoreapp3.1/Bowling.dll index cfbd498..007d562 100644 Binary files a/Bowling/bin/Debug/netcoreapp3.1/Bowling.dll and b/Bowling/bin/Debug/netcoreapp3.1/Bowling.dll differ diff --git a/Bowling/bin/Debug/netcoreapp3.1/Bowling.pdb b/Bowling/bin/Debug/netcoreapp3.1/Bowling.pdb index 7ec97c2..2a5c02f 100644 Binary files a/Bowling/bin/Debug/netcoreapp3.1/Bowling.pdb and b/Bowling/bin/Debug/netcoreapp3.1/Bowling.pdb differ diff --git a/Bowling/obj/Debug/netcoreapp3.1/Bowling.dll b/Bowling/obj/Debug/netcoreapp3.1/Bowling.dll index cfbd498..007d562 100644 Binary files a/Bowling/obj/Debug/netcoreapp3.1/Bowling.dll and b/Bowling/obj/Debug/netcoreapp3.1/Bowling.dll differ diff --git a/Bowling/obj/Debug/netcoreapp3.1/Bowling.pdb b/Bowling/obj/Debug/netcoreapp3.1/Bowling.pdb index 7ec97c2..2a5c02f 100644 Binary files a/Bowling/obj/Debug/netcoreapp3.1/Bowling.pdb and b/Bowling/obj/Debug/netcoreapp3.1/Bowling.pdb differ diff --git a/Bowling_Server/Classes/Player.cs b/Bowling_Server/Classes/Player.cs index adf2cb5..87866d7 100644 --- a/Bowling_Server/Classes/Player.cs +++ b/Bowling_Server/Classes/Player.cs @@ -7,17 +7,17 @@ namespace Bowling_Server.Classes { [Serializable] internal class Player - { + { [JsonProperty("name")] public string Name { get; set; } [JsonProperty("score")] - public List Score { get; set; } = new List(); + public List Score { get; set; } [NonSerialized] - public Socket socket; - - + public Socket Socket; + + public string Serialize() { return JsonConvert.SerializeObject(this); diff --git a/Bowling_Server/Program.cs b/Bowling_Server/Program.cs index 89ec13f..564c03d 100644 --- a/Bowling_Server/Program.cs +++ b/Bowling_Server/Program.cs @@ -47,7 +47,7 @@ namespace Bowling_Server string json = Encoding.ASCII.GetString(data, 0, recv); Player player = new Player(); player.Deserialize(json); - player.socket = client; + player.Socket = client; players.Add(player); }); thread.Start(); @@ -64,8 +64,12 @@ namespace Bowling_Server } public static void Send(string message, Socket client) { - byte[] data = Encoding.ASCII.GetBytes(message); - client.Send(data); + try + { + byte[] data = Encoding.ASCII.GetBytes(message); + client.Send(data); + } + catch { } } static void CastOpponents(List group) { @@ -75,7 +79,7 @@ namespace Bowling_Server { if (opponent != player) { - Send(opponent.Serialize(), player.socket); + Send(opponent.Serialize(), player.Socket); } } } @@ -91,20 +95,20 @@ namespace Bowling_Server Thread thread = new Thread(() => { byte[] data = new byte[1024]; - player.socket.ReceiveTimeout = 60000; + player.Socket.ReceiveTimeout = 60000; try { while (true) { - int dataLength = player.socket.Receive(data); + int dataLength = player.Socket.Receive(data); string json = Encoding.ASCII.GetString(data, 0, dataLength); if (json == "11") { foreach (var player in group) { - player.socket.Send(Encoding.ASCII.GetBytes("11")); - player.Score = new List(); - players.Add(player); + player.Socket.Send(Encoding.ASCII.GetBytes("11")); + player.Score = new List(); + players.Add(player); } break; } @@ -119,18 +123,20 @@ namespace Bowling_Server Console.WriteLine("Player disconnected"); if (group.IndexOf(player) == 1) { - group[0].socket.Send(Encoding.ASCII.GetBytes("11")); + group[1].Socket.Send(Encoding.ASCII.GetBytes("12")); + group[0].Socket.Send(Encoding.ASCII.GetBytes("11")); group[0].Score = new List(); players.Add(group[0]); } else { - group[1].socket.Send(Encoding.ASCII.GetBytes("11")); + group[0].Socket.Send(Encoding.ASCII.GetBytes("12")); + group[1].Socket.Send(Encoding.ASCII.GetBytes("11")); group[1].Score = new List(); players.Add(group[1]); } } - catch + catch (Exception e) { Console.WriteLine("Players disconnected. Can't process disconnection. Game ended."); } @@ -139,9 +145,5 @@ namespace Bowling_Server thread.Start(); } } - public void Die() - { - - } } } \ No newline at end of file diff --git a/Bowling_Server/bin/Debug/net5.0/Bowling_Server.dll b/Bowling_Server/bin/Debug/net5.0/Bowling_Server.dll index bdbdfdd..8ba5b95 100644 Binary files a/Bowling_Server/bin/Debug/net5.0/Bowling_Server.dll and b/Bowling_Server/bin/Debug/net5.0/Bowling_Server.dll differ diff --git a/Bowling_Server/bin/Debug/net5.0/Bowling_Server.pdb b/Bowling_Server/bin/Debug/net5.0/Bowling_Server.pdb index ecdce76..85bae19 100644 Binary files a/Bowling_Server/bin/Debug/net5.0/Bowling_Server.pdb and b/Bowling_Server/bin/Debug/net5.0/Bowling_Server.pdb differ diff --git a/Bowling_Server/obj/Debug/net5.0/Bowling_Server.dll b/Bowling_Server/obj/Debug/net5.0/Bowling_Server.dll index bdbdfdd..8ba5b95 100644 Binary files a/Bowling_Server/obj/Debug/net5.0/Bowling_Server.dll and b/Bowling_Server/obj/Debug/net5.0/Bowling_Server.dll differ diff --git a/Bowling_Server/obj/Debug/net5.0/Bowling_Server.pdb b/Bowling_Server/obj/Debug/net5.0/Bowling_Server.pdb index ecdce76..85bae19 100644 Binary files a/Bowling_Server/obj/Debug/net5.0/Bowling_Server.pdb and b/Bowling_Server/obj/Debug/net5.0/Bowling_Server.pdb differ diff --git a/Bowling_Server/obj/Debug/net5.0/ref/Bowling_Server.dll b/Bowling_Server/obj/Debug/net5.0/ref/Bowling_Server.dll index 2501dd5..245da11 100644 Binary files a/Bowling_Server/obj/Debug/net5.0/ref/Bowling_Server.dll and b/Bowling_Server/obj/Debug/net5.0/ref/Bowling_Server.dll differ diff --git a/Bowling_Server/obj/Debug/net5.0/refint/Bowling_Server.dll b/Bowling_Server/obj/Debug/net5.0/refint/Bowling_Server.dll index 2501dd5..245da11 100644 Binary files a/Bowling_Server/obj/Debug/net5.0/refint/Bowling_Server.dll and b/Bowling_Server/obj/Debug/net5.0/refint/Bowling_Server.dll differ