diff --git a/.vs/Bowling/DesignTimeBuild/.dtbcache.v2 b/.vs/Bowling/DesignTimeBuild/.dtbcache.v2 index 23681df..9ba3c8b 100644 Binary files a/.vs/Bowling/DesignTimeBuild/.dtbcache.v2 and b/.vs/Bowling/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/Bowling/FileContentIndex/044bda40-8ffb-427e-9839-6bac7ad70c8c.vsidx b/.vs/Bowling/FileContentIndex/044bda40-8ffb-427e-9839-6bac7ad70c8c.vsidx deleted file mode 100644 index 2fa350b..0000000 Binary files a/.vs/Bowling/FileContentIndex/044bda40-8ffb-427e-9839-6bac7ad70c8c.vsidx and /dev/null differ diff --git a/.vs/Bowling/FileContentIndex/087687d0-ba50-4bf9-9d06-acbef1642b29.vsidx b/.vs/Bowling/FileContentIndex/087687d0-ba50-4bf9-9d06-acbef1642b29.vsidx new file mode 100644 index 0000000..52272b6 Binary files /dev/null and b/.vs/Bowling/FileContentIndex/087687d0-ba50-4bf9-9d06-acbef1642b29.vsidx differ diff --git a/.vs/Bowling/FileContentIndex/0d902478-9fc7-4a0b-90f3-5a6ddcfc3ce9.vsidx b/.vs/Bowling/FileContentIndex/0d902478-9fc7-4a0b-90f3-5a6ddcfc3ce9.vsidx deleted file mode 100644 index f62aeda..0000000 Binary files a/.vs/Bowling/FileContentIndex/0d902478-9fc7-4a0b-90f3-5a6ddcfc3ce9.vsidx and /dev/null differ diff --git a/.vs/Bowling/FileContentIndex/cba72597-085c-4605-a2d1-fda056678e48.vsidx b/.vs/Bowling/FileContentIndex/cba72597-085c-4605-a2d1-fda056678e48.vsidx new file mode 100644 index 0000000..d8ea8a0 Binary files /dev/null and b/.vs/Bowling/FileContentIndex/cba72597-085c-4605-a2d1-fda056678e48.vsidx differ diff --git a/.vs/Bowling/FileContentIndex/4543de32-8d2e-495f-92d0-e6ad1f4c9fa2.vsidx b/.vs/Bowling/FileContentIndex/e42a5ae0-fb19-47f3-84f2-948fa17f38f4.vsidx similarity index 100% rename from .vs/Bowling/FileContentIndex/4543de32-8d2e-495f-92d0-e6ad1f4c9fa2.vsidx rename to .vs/Bowling/FileContentIndex/e42a5ae0-fb19-47f3-84f2-948fa17f38f4.vsidx diff --git a/.vs/Bowling/FileContentIndex/bae8f6d6-7f0c-4c67-a7f1-7980f40c5933.vsidx b/.vs/Bowling/FileContentIndex/ff899c91-0438-4ebb-9dc5-44ee8bccf800.vsidx similarity index 100% rename from .vs/Bowling/FileContentIndex/bae8f6d6-7f0c-4c67-a7f1-7980f40c5933.vsidx rename to .vs/Bowling/FileContentIndex/ff899c91-0438-4ebb-9dc5-44ee8bccf800.vsidx diff --git a/.vs/Bowling/v17/.suo b/.vs/Bowling/v17/.suo index 5e06854..de496a7 100644 Binary files a/.vs/Bowling/v17/.suo and b/.vs/Bowling/v17/.suo differ diff --git a/Bowling.sln b/Bowling.sln index 890e68d..bcc43e4 100644 --- a/Bowling.sln +++ b/Bowling.sln @@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bowling_Server", "Bowling_S EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetLib", "BowlingNetLib\NetLib.csproj", "{8F4FCE29-064E-45E4-AF43-87F31420EF2F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{A3F442D5-C149-401F-BC5C-9BADED32E621}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,10 +27,6 @@ Global {8F4FCE29-064E-45E4-AF43-87F31420EF2F}.Debug|Any CPU.Build.0 = Debug|Any CPU {8F4FCE29-064E-45E4-AF43-87F31420EF2F}.Release|Any CPU.ActiveCfg = Release|Any CPU {8F4FCE29-064E-45E4-AF43-87F31420EF2F}.Release|Any CPU.Build.0 = Release|Any CPU - {A3F442D5-C149-401F-BC5C-9BADED32E621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A3F442D5-C149-401F-BC5C-9BADED32E621}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A3F442D5-C149-401F-BC5C-9BADED32E621}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A3F442D5-C149-401F-BC5C-9BADED32E621}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Bowling/Classes/Player.cs b/Bowling/Classes/Player.cs index 41e1fe7..14119ee 100644 --- a/Bowling/Classes/Player.cs +++ b/Bowling/Classes/Player.cs @@ -14,9 +14,9 @@ namespace Bowling.Classes public string Name { get; set; } [JsonProperty("score")] - public List Score { get; set; } + public List Score { get; set; } = new List(); + - public string Serialize() { return JsonConvert.SerializeObject(this); diff --git a/Bowling/Connect.Designer.cs b/Bowling/Connect.Designer.cs index a57b83a..9a296fc 100644 --- a/Bowling/Connect.Designer.cs +++ b/Bowling/Connect.Designer.cs @@ -121,6 +121,7 @@ this.Controls.Add(this.NameTB); this.Name = "Connect"; this.Text = "Launcher"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Connect_FormClosing); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Bowling/Connect.cs b/Bowling/Connect.cs index 89ce54c..9915a6b 100644 --- a/Bowling/Connect.cs +++ b/Bowling/Connect.cs @@ -39,5 +39,9 @@ namespace Bowling private void ExitBtn_Click(object sender, EventArgs e) { } + + private void Connect_FormClosing(object sender, FormClosingEventArgs e) + { + } } } diff --git a/Bowling/Game1.cs b/Bowling/Game1.cs index a208f3d..ba50af9 100644 --- a/Bowling/Game1.cs +++ b/Bowling/Game1.cs @@ -7,12 +7,13 @@ using System.Collections.Generic; using System.Windows.Forms; using NetLib; using System.Threading; +using System.Text; namespace Bowling { public enum GameState { - Menu, Game, Exit, Connect_to_server, EndGame + Menu, Game, Exit, Connect_to_server, PauseGame, EndGame } public class Game1 : Game { @@ -33,8 +34,7 @@ namespace Bowling private Vector2 ballStartPosition; private List tableLabels; private int intermediateScore; - private Classes.UI.Label lblCountP1; - private Classes.UI.Label lblCountP2; + private int counter; private List pins = new List(); @@ -52,6 +52,7 @@ namespace Bowling _graphics.PreferredBackBufferHeight = 1000; Content.RootDirectory = "Content"; IsMouseVisible = true; + Window.Title = "Bowling"; } protected override void Initialize() @@ -70,6 +71,7 @@ namespace Bowling tableMarginLeft = 20; tableLabels = new List(); intermediateScore = 0; + counter = 0; base.Initialize(); } @@ -125,12 +127,34 @@ namespace Bowling { while (true) { - player2.Deserialize(NetLib.NetLib.Receive()); + string msg = NetLib.NetLib.Receive(); + if (msg == "11") + { + ResetAll(); + break; + } + else + { + player2.Deserialize(msg); + } } }); thread.Start(); } - else { gameState = GameState.Menu; } + else { gameState = GameState.Exit; } + break; + case GameState.EndGame: + counter++; + if (counter >= 300) + { + gameState = GameState.Menu; + NetLib.NetLib.Send("11"); + counter = 0; + } + break; + case GameState.PauseGame: + if (player2.Score.Count == 21 || (player2.Score.Count == 20 && player2.Score[18] + player2.Score[19] != 10)) gameState = GameState.EndGame; + if (tableLabels.Count >= 77) gameState = GameState.EndGame; break; } base.Update(gameTime); @@ -161,8 +185,22 @@ namespace Bowling case GameState.Menu: menu.Draw(_spriteBatch); break; + case GameState.EndGame: + DrawGrid(); + foreach (Classes.UI.Label lbl in tableLabels) + { + lbl.Draw(_spriteBatch); + } + break; + case GameState.PauseGame: + DrawGrid(); + foreach (Classes.UI.Label lbl in tableLabels) + { + lbl.Draw(_spriteBatch); + } + break; } - + base.Draw(gameTime); _spriteBatch.End(); } @@ -190,9 +228,10 @@ namespace Bowling { if (player1.Score[18] + player1.Score[19] == 10) NewMove(); } - if (player1.Score.Count == 20 && player1.Score[18] + player1.Score[19] != 10) + if (player1.Score.Count == 21 || (player1.Score.Count == 20 && player1.Score[18] + player1.Score[19] != 10)) { - gameState = GameState.EndGame; + gameState = GameState.PauseGame; + if (player2.Score.Count == 21 || (player2.Score.Count == 20 && player2.Score[18] + player2.Score[19] != 10)) gameState = GameState.EndGame; } SendPlayerData(player1); } @@ -250,8 +289,9 @@ namespace Bowling if (i % 2 == 0) score = 0; else if (i == 1) score = Sum(player1.Score); else score = Sum(player2.Score); - Classes.UI.Label lbl = new Classes.UI.Label(score.ToString(), new Vector2(tableMarginLeft + rowWidth * 12 + rowWidth / 2, tableMarginTop + countRows + rowHeight + 5), + Classes.UI.Label lbl = new Classes.UI.Label(score.ToString(), new Vector2(tableMarginLeft + rowWidth * 12 + rowWidth / 2 - 15, tableMarginTop + countRows + rowHeight + ((i % 2 == 1) ? 15 : 5)), Color.Fuchsia); + if (i % 2 == 1) lbl.FontName = "gameFont2"; lbl.LoadContent(Content); tableLabels.Add(lbl); countRows += (i != 0 && i % 2 == 1) ? 2 * rowHeight : rowHeight; @@ -274,6 +314,14 @@ namespace Bowling lbl.LoadContent(Content); tableLabels.Add(lbl); } + Classes.UI.Label label_p1_name = new Classes.UI.Label(player1.Name[0].ToString(), new Vector2(tableMarginLeft + 2, tableMarginTop + rowHeight), + Color.Red); + label_p1_name.LoadContent(Content); + tableLabels.Add(label_p1_name); + + Classes.UI.Label label_p2_name = new Classes.UI.Label(player2.Name[0].ToString(), new Vector2(tableMarginLeft + 2, tableMarginTop + 4 * rowHeight), Color.Red); + label_p2_name.LoadContent(Content); + tableLabels.Add(label_p2_name); } private void NewMove() @@ -296,5 +344,23 @@ namespace Bowling { NetLib.NetLib.Send(player.Serialize()); } + + private void ResetAll() + { + ball = new Ball(ballStartPosition, Vector2.Zero, Color.Blue, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth); + menu = new Menu(); + player2 = new Player(); + player1 = new Player(); + rowWidth = 80; + rowHeight = 50; + tableMarginTop = 20; + tableMarginLeft = 20; + tableLabels = new List(); + intermediateScore = 0; + counter = 0; + gameState = GameState.Menu; + pins.Clear(); + LoadContent(); + } } } \ No newline at end of file diff --git a/Bowling/bin/Debug/netcoreapp3.1/.vs/Bowling/v17/.suo b/Bowling/bin/Debug/netcoreapp3.1/.vs/Bowling/v17/.suo new file mode 100644 index 0000000..a1730cb Binary files /dev/null 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 e8a6ff7..6b76cd7 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 2d169a2..ec7eee2 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.csproj.AssemblyReference.cache b/Bowling/obj/Debug/netcoreapp3.1/Bowling.csproj.AssemblyReference.cache index 640f763..bd853f5 100644 Binary files a/Bowling/obj/Debug/netcoreapp3.1/Bowling.csproj.AssemblyReference.cache and b/Bowling/obj/Debug/netcoreapp3.1/Bowling.csproj.AssemblyReference.cache differ diff --git a/Bowling/obj/Debug/netcoreapp3.1/Bowling.csproj.GenerateResource.cache b/Bowling/obj/Debug/netcoreapp3.1/Bowling.csproj.GenerateResource.cache index f466f25..643bc1f 100644 Binary files a/Bowling/obj/Debug/netcoreapp3.1/Bowling.csproj.GenerateResource.cache and b/Bowling/obj/Debug/netcoreapp3.1/Bowling.csproj.GenerateResource.cache differ diff --git a/Bowling/obj/Debug/netcoreapp3.1/Bowling.dll b/Bowling/obj/Debug/netcoreapp3.1/Bowling.dll index e8a6ff7..6b76cd7 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 2d169a2..ec7eee2 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 716ce68..adf2cb5 100644 --- a/Bowling_Server/Classes/Player.cs +++ b/Bowling_Server/Classes/Player.cs @@ -12,7 +12,7 @@ namespace Bowling_Server.Classes public string Name { get; set; } [JsonProperty("score")] - public List Score { get; set; } + public List Score { get; set; } = new List(); [NonSerialized] public Socket socket; diff --git a/Bowling_Server/Program.cs b/Bowling_Server/Program.cs index c4c8b8f..1cae0e9 100644 --- a/Bowling_Server/Program.cs +++ b/Bowling_Server/Program.cs @@ -1,11 +1,10 @@ -using System; +using Bowling_Server.Classes; +using System; using System.Collections.Generic; -using Bowling_Server.Classes; using System.Net; using System.Net.Sockets; -using System.Threading; -using NetLib; using System.Text; +using System.Threading; namespace Bowling_Server { @@ -99,20 +98,39 @@ namespace Bowling_Server { int dataLength = player.socket.Receive(data); string json = Encoding.ASCII.GetString(data, 0, dataLength); + if (json.Contains("11")) + { + foreach (var player in group) + { + player.socket.Send(Encoding.ASCII.GetBytes("11")); + player.Score = new List(); + players.Add(player); + } + break; + } player.Deserialize(json); CastOpponents(group); } } catch { - Console.WriteLine("Player disconnected"); - if (group.IndexOf(player) == 1) + try { - players.Add(group[0]); + Console.WriteLine("Player disconnected"); + if (group.IndexOf(player) == 1) + { + group[0].socket.Send(Encoding.ASCII.GetBytes("11")); + players.Add(group[0]); + } + else + { + group[1].socket.Send(Encoding.ASCII.GetBytes("11")); + players.Add(group[1]); + } } - else + catch { - players.Add(group[1]); + Console.WriteLine("Players disconnected. Can't process disconnection. Game ended."); } } }); diff --git a/Bowling_Server/bin/Debug/net5.0/Bowling_Server.dll b/Bowling_Server/bin/Debug/net5.0/Bowling_Server.dll index 1dc4656..0e0cb23 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 de58c73..9983838 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.csproj.AssemblyReference.cache b/Bowling_Server/obj/Debug/net5.0/Bowling_Server.csproj.AssemblyReference.cache index b01f42b..0e640df 100644 Binary files a/Bowling_Server/obj/Debug/net5.0/Bowling_Server.csproj.AssemblyReference.cache and b/Bowling_Server/obj/Debug/net5.0/Bowling_Server.csproj.AssemblyReference.cache differ diff --git a/Bowling_Server/obj/Debug/net5.0/Bowling_Server.dll b/Bowling_Server/obj/Debug/net5.0/Bowling_Server.dll index 1dc4656..0e0cb23 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 de58c73..9983838 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