diff --git a/BSR_Client/Constants.cs b/BSR_Client/Constants.cs index fe1d158..ce86997 100644 --- a/BSR_Client/Constants.cs +++ b/BSR_Client/Constants.cs @@ -1,7 +1,10 @@ using System; using System.Collections.Generic; +using System.Windows.Controls; using System.Windows.Media; +using System.Windows.Shapes; +#pragma warning disable IDE0079 #pragma warning disable IDE0044 namespace BSR_Client @@ -73,6 +76,24 @@ public partial class MainWindow private bool PacketHandled = false; private bool UsedTrashBin = false; + private class ElementLib + { + public Rectangle[] Bullets; + public ProgressBar[] HealthBars; + public Button[] Items; + public Button[] Players; + + public ElementLib(MainWindow w) + { + Bullets = new Rectangle[] { w.Bullet1, w.Bullet2, w.Bullet3, w.Bullet4, w.Bullet5, w.Bullet6, w.Bullet7, w.Bullet8 }; + HealthBars = new ProgressBar[] { w.Health1, w.Health2, w.Health3, w.Health4, w.Health5 }; + Items = new Button[] { w.Item1, w.Item2, w.Item3, w.Item4, w.Item5, w.Item6, w.Item7, w.Item8 }; + Players = new Button[] { w.Player1, w.Player2, w.Player3, w.Player4, w.Player5 }; + } + } + + private ElementLib Elements = null; + private class SoundLib { public MediaPlayer Title = new MediaPlayer() { Volume = 0.1 }; diff --git a/BSR_Client/Logic.cs b/BSR_Client/Logic.cs index 7203e2f..304fcbc 100644 --- a/BSR_Client/Logic.cs +++ b/BSR_Client/Logic.cs @@ -1,12 +1,10 @@ using System; using System.Diagnostics; -using System.Linq; using System.Reflection; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; -using System.Windows.Shapes; namespace BSR_Client { @@ -26,16 +24,14 @@ public void ShowBullets(EBullet[] bullets) nblank++; } Announce(nlive + " lives, " + nblank + " blanks"); - Rectangle[] displays = new Rectangle[] { Bullet1, Bullet2, Bullet3, Bullet4, Bullet5, Bullet6, Bullet7, Bullet8 }; for (int i = 0; i < bullets.Length; i++) - displays[i].Fill = bullets[i] == EBullet.Live ? Brushes.Red : Brushes.Gray; + Elements.Bullets[i].Fill = bullets[i] == EBullet.Live ? Brushes.Red : Brushes.Gray; } public void ResetBullets() { - Rectangle[] displays = new Rectangle[] { Bullet1, Bullet2, Bullet3, Bullet4, Bullet5, Bullet6, Bullet7, Bullet8 }; - for (int i = 0; i < displays.Length; i++) - displays[i].Fill = Brushes.Transparent; + for (int i = 0; i < Elements.Bullets.Length; i++) + Elements.Bullets[i].Fill = Brushes.Transparent; } public void Dead() @@ -74,14 +70,12 @@ public void RemovePlayer(string player) { Players.Remove(player); PlayerTurns.Remove(player); - ProgressBar[] displays = new ProgressBar[] { Health1, Health2, Health3, Health4, Health5 }; - Button[] players = new Button[] { Player1, Player2, Player3, Player4, Player5 }; int it = 0; - foreach (Button b in players) + foreach (Button b in Elements.Players) { if (IsPlayerSlot(b, player)) { - displays[it].Value = 0; + Elements.HealthBars[it].Value = 0; break; } it++; @@ -113,10 +107,9 @@ public void GenerateItems(bool remoteGenerate, int remoteCount) public int GetItemCount() { - Button[] displays = new Button[] { Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8 }; int count = 0; - for (int i = 0; i < displays.Length; i++) - if (!IsItemSlot(displays[i], "Nothing")) + for (int i = 0; i < Elements.Items.Length; i++) + if (!IsItemSlot(Elements.Items[i], "Nothing")) count++; return count; } @@ -125,21 +118,19 @@ public void UpdateLives(string player, int lives, bool set, bool lose, bool sync { if (set && lose) return; - ProgressBar[] displays = new ProgressBar[] { Health1, Health2, Health3, Health4, Health5 }; - Button[] players = new Button[] { Player1, Player2, Player3, Player4, Player5 }; if (sync) Packet.Create(EPacket.UpdateLives).Add(player).Add(lives).Add(set).Add(lose).Send(Sync); int it = 0; - foreach (Button b in players) + foreach (Button b in Elements.Players) { if (IsPlayerSlot(b, player)) { if (set) - displays[it].Value = lives; + Elements.HealthBars[it].Value = lives; else if (lose) - displays[it].Value -= lives; + Elements.HealthBars[it].Value -= lives; else - displays[it].Value += lives; + Elements.HealthBars[it].Value += lives; break; } it++; @@ -214,12 +205,11 @@ public bool AddPlayer(string username) if (Players.Contains(username)) return false; Players.Add(username); - Button[] displays = new Button[] { Player1, Player2, Player3, Player4, Player5 }; - for (int i = 0; i < displays.Length; i++) + for (int i = 0; i < Elements.Players.Length; i++) { - if (IsPlayerSlot(displays[i], "None")) + if (IsPlayerSlot(Elements.Players[i], "None")) { - SetPlayerData(displays[i], username, true); + SetPlayerData(Elements.Players[i], username, true); break; } } @@ -260,18 +250,15 @@ public bool IsPlayerActive() public void SetActive(bool active) { Shoot.IsEnabled = active; - Button[] items = new Button[] { Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8 }; - foreach (Button i in items) + foreach (Button i in Elements.Items) i.IsEnabled = false; - items = new Button[] { Player1, Player2, Player3, Player4, Player5 }; - foreach (Button i in items) + foreach (Button i in Elements.Players) i.IsEnabled = false; } public void HideInactivePlayers() { - Button[] items = new Button[] { Player1, Player2, Player3, Player4, Player5 }; - foreach (Button i in items) + foreach (Button i in Elements.Players) if (IsPlayerSlot(i, "None")) i.Visibility = Visibility.Hidden; } @@ -279,15 +266,12 @@ public void HideInactivePlayers() public void PrepareGun() { Shoot.IsEnabled = false; - Button[] items = new Button[] { Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8 }; - foreach (Button i in items) + foreach (Button i in Elements.Items) i.IsEnabled = false; - items = new Button[] { Player1, Player2, Player3, Player4, Player5 }; - ProgressBar[] displays = new ProgressBar[] { Health1, Health2, Health3, Health4, Health5 }; int it = 0; - foreach (Button i in items) + foreach (Button i in Elements.Players) { - if (!IsPlayerSlot(i, "None") && displays[it].Value > 0) + if (!IsPlayerSlot(i, "None") && Elements.HealthBars[it].Value > 0) i.IsEnabled = true; it++; } @@ -328,8 +312,7 @@ public string GetItemType(Button slot) public void SetAngry(string player) { - Button[] items = new Button[] { Player1, Player2, Player3, Player4, Player5 }; - foreach (Button i in items) + foreach (Button i in Elements.Players) { if (IsPlayerSlot(i, player)) { @@ -381,13 +364,11 @@ public void SetItemData(Button slot, EItem type) public int GetHealth() { - Button[] items = new Button[] { Player1, Player2, Player3, Player4, Player5 }; - ProgressBar[] displays = new ProgressBar[] { Health1, Health2, Health3, Health4, Health5 }; int it = 0; - foreach (Button i in items) + foreach (Button i in Elements.Players) { if (IsPlayerSlot(i, MyName)) - return (int)displays[it].Value; + return (int)Elements.HealthBars[it].Value; it++; } return 0; @@ -395,15 +376,14 @@ public int GetHealth() public bool SetItem(EItem type, bool enable = false) { - Button[] displays = new Button[] { Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8 }; - for (int i = 0; i < displays.Length; i++) + for (int i = 0; i < Elements.Items.Length; i++) { - if (IsItemSlot(displays[i], "Nothing")) + if (IsItemSlot(Elements.Items[i], "Nothing")) { - displays[i].Visibility = Visibility.Visible; - SetItemData(displays[i], type); + Elements.Items[i].Visibility = Visibility.Visible; + SetItemData(Elements.Items[i], type); if (enable) - displays[i].IsEnabled = true; + Elements.Items[i].IsEnabled = true; return true; } } @@ -412,21 +392,19 @@ public bool SetItem(EItem type, bool enable = false) public void HideEmptyItemSlots() { - Button[] displays = new Button[] { Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8 }; - for (int i = 0; i < displays.Length; i++) - if (IsItemSlot(displays[i], "Nothing")) - displays[i].Visibility = Visibility.Hidden; + for (int i = 0; i < Elements.Items.Length; i++) + if (IsItemSlot(Elements.Items[i], "Nothing")) + Elements.Items[i].Visibility = Visibility.Hidden; } public EItem UseItem(string slot) { Button it = null; - Button[] displays = new Button[] { Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8 }; - for (int i = 0; i < displays.Length; i++) + for (int i = 0; i < Elements.Items.Length; i++) { - if (displays[i].Name == slot) + if (Elements.Items[i].Name == slot) { - it = displays[i]; + it = Elements.Items[i]; break; } } @@ -445,12 +423,9 @@ public EItem UseItem(string slot) public void UnlockItems() { - Button[] displays = new Button[] { Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8 }; - for (int i = 0; i < displays.Length; i++) - { - if (!IsItemSlot(displays[i], "Nothing")) - displays[i].IsEnabled = true; - } + for (int i = 0; i < Elements.Items.Length; i++) + if (!IsItemSlot(Elements.Items[i], "Nothing")) + Elements.Items[i].IsEnabled = true; } public bool ProcessIsRunning() diff --git a/BSR_Client/MainWindow.xaml b/BSR_Client/MainWindow.xaml index b05dc64..0eb0eae 100644 --- a/BSR_Client/MainWindow.xaml +++ b/BSR_Client/MainWindow.xaml @@ -39,11 +39,26 @@ - - - - - + + + + + + + + + + + + + + + + + + + +