PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/draugr_contrib/GameState.cs

https://bitbucket.org/ehvattum/draugr_contrib
C# | 117 lines | 86 code | 28 blank | 3 comment | 8 complexity | 6349efb0794d0ac122d49caad95e979a MD5 | raw file
  1. #region creds
  2. // --------------------------------------------------
  3. // ragesheep aka baconbike production
  4. // --------------------------------------------------
  5. #endregion
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using Newtonsoft.Json;
  10. namespace draugr_contrib
  11. {
  12. [Serializable]
  13. public class GameState
  14. {
  15. [NonSerialized]
  16. private List<Resource> resources;
  17. public string Error { get; set; }
  18. public Map Map { get; set; }
  19. public string Message { get; set; }
  20. public List<Player> Players { get; set; }
  21. public List<Resource> Resources
  22. {
  23. get { return this.resources; }
  24. set { this.resources = value; }
  25. }
  26. public bool Status { get; set; }
  27. public int Turn { get; set; }
  28. }
  29. public class Resource
  30. {
  31. public string Type { get; set; }
  32. }
  33. [Serializable]
  34. public class Map
  35. {
  36. public TileType[][] Data { get; set; }
  37. [JsonProperty("j-length")]
  38. public int Jlength { get; set; }
  39. [JsonProperty("k-length")]
  40. public int Klength { get; set; }
  41. public int GetReourceCount(TileType tileType)
  42. {
  43. return Data.SelectMany(jcollumn => jcollumn).Count(tile => tile == tileType);
  44. }
  45. }
  46. [Serializable]
  47. public class Player
  48. {
  49. public string Health { get; set; }
  50. public string Name { get; set; }
  51. public string Position { get; set; }
  52. [JsonProperty("primary-weapon")]
  53. public Weapon PrimaryWeapon { get; set; }
  54. public int Score { get; set; }
  55. [JsonProperty("secondary-weapon")]
  56. public Weapon SecondaryWeapon { get; set; }
  57. public string[] Coords()
  58. {
  59. return Position.Split(',');
  60. }
  61. }
  62. [Serializable]
  63. public class Weapon
  64. {
  65. public int Level { get; set; }
  66. public string Name { get; set; }
  67. public override bool Equals(object obj)
  68. {
  69. if (ReferenceEquals(null, obj))
  70. return false;
  71. if (ReferenceEquals(this, obj))
  72. return true;
  73. if (obj.GetType() != GetType())
  74. return false;
  75. return Equals((Weapon)obj);
  76. }
  77. public override int GetHashCode()
  78. {
  79. unchecked
  80. {
  81. return (Level * 397) ^ (Name != null ? Name.GetHashCode() : 0);
  82. }
  83. }
  84. protected bool Equals(Weapon other)
  85. {
  86. return Level == other.Level && string.Equals(Name, other.Name);
  87. }
  88. }
  89. }