draugr_contrib /draugr_contrib/GameState.cs

Language C# Lines 117
MD5 Hash 7fd1828175ab178c8e4b496f6a9537a3 Estimated Cost $2,055 (why?)
Repository https://bitbucket.org/ehvattum/draugr_contrib.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#region creds

// --------------------------------------------------
// ragesheep aka baconbike production
// --------------------------------------------------

#endregion

using System;
using System.Collections.Generic;
using System.Linq;

using Newtonsoft.Json;

namespace draugr_contrib
{
    [Serializable]
    public class GameState
    {
        [NonSerialized]
        private List<Resource> resources;

        public string Error { get; set; }
        public Map Map { get; set; }
        public string Message { get; set; }
        public List<Player> Players { get; set; }

        public List<Resource> Resources

        {
            get { return this.resources; }
            set { this.resources = value; }
        }

        public bool Status { get; set; }
        public int Turn { get; set; }
    }

    public class Resource
    {
        public string Type { get; set; }
    }

    [Serializable]
    public class Map
    {
        public TileType[][] Data { get; set; }

        [JsonProperty("j-length")]
        public int Jlength { get; set; }

        [JsonProperty("k-length")]
        public int Klength { get; set; }


        public int GetReourceCount(TileType tileType)
        {
            return Data.SelectMany(jcollumn => jcollumn).Count(tile => tile == tileType);
        }
    }

    [Serializable]
    public class Player
    {
        public string Health { get; set; }
        public string Name { get; set; }
        public string Position { get; set; }

        [JsonProperty("primary-weapon")]
        public Weapon PrimaryWeapon { get; set; }

        public int Score { get; set; }

        [JsonProperty("secondary-weapon")]
        public Weapon SecondaryWeapon { get; set; }


        public string[] Coords()
        {
            return Position.Split(',');
        }
    }

    [Serializable]
    public class Weapon
    {
        public int Level { get; set; }
        public string Name { get; set; }


        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
                return false;
            if (ReferenceEquals(this, obj))
                return true;
            if (obj.GetType() != GetType())
                return false;
            return Equals((Weapon)obj);
        }


        public override int GetHashCode()
        {
            unchecked
            {
                return (Level * 397) ^ (Name != null ? Name.GetHashCode() : 0);
            }
        }


        protected bool Equals(Weapon other)
        {
            return Level == other.Level && string.Equals(Name, other.Name);
        }
    }
}
Back to Top