Ejemplo n.º 1
0
        /// <summary>
        /// Gets a tile by criteria from a set.
        /// </summary>
        /// <param name="tilesSet">The set of tiles.</param>
        /// <param name="family">The <see cref="Family"/> value.</param>
        /// <param name="number">Optionnal; the <see cref="Number"/> value; default value is <c>Null</c>.</param>
        /// <param name="dragon">Optionnal; the <see cref="Dragon"/> value; default value is <c>Null</c>.</param>
        /// <param name="wind">Optionnal; the <see cref="Wind"/> value; default value is <c>Null</c>.</param>
        /// <param name="isRedDora">Optionnal; the <see cref="IsRedDora"/> value; default value is <c>Null</c>.</param>
        /// <returns></returns>
        public static TilePivot GetTile(IEnumerable <TilePivot> tilesSet, FamilyPivot family, byte?number = null,
                                        DragonPivot?dragon = null, WindPivot?wind = null, bool?isRedDora = null)
        {
            if (tilesSet == null)
            {
                return(null);
            }

            tilesSet = tilesSet.Where(t => t.Family == family);
            if (number.HasValue)
            {
                tilesSet = tilesSet.Where(t => t.Number == number.Value);
            }
            if (dragon.HasValue)
            {
                tilesSet = tilesSet.Where(t => t.Dragon == dragon.Value);
            }
            if (wind.HasValue)
            {
                tilesSet = tilesSet.Where(t => t.Wind == wind.Value);
            }
            if (isRedDora.HasValue)
            {
                tilesSet = tilesSet.Where(t => t.IsRedDora == isRedDora.Value);
            }

            return(tilesSet.FirstOrDefault());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="family"><see cref="FamilyPivot"/>.</param>
        /// <param name="number">Number between 1 and 9.</param>
        /// <exception cref="ArgumentException"><see cref="Messages.InvalidTileFamilyError"/></exception>
        /// <exception cref="ArgumentException"><see cref="Messages.InvalidTileFamilyError"/></exception>
        public TilePivot(FamilyPivot family, int number)
        {
            if (family == FamilyPivot.Dragon || family == FamilyPivot.Wind)
            {
                throw new ArgumentException(Messages.InvalidTileFamilyError, nameof(family));
            }
            if (number < 1 || number > 9)
            {
                throw new ArgumentException(Messages.InvalidTileFamilyError, nameof(number));
            }

            Number = number;
            Family = family;

            string familyName = "caractère";

            switch (Family)
            {
            case FamilyPivot.Bamboo:
                familyName = "bambou";
                break;

            case FamilyPivot.Circle:
                familyName = "cercle";
                break;
            }
            Graphic = (Bitmap)DllRsc.ResourceManager.GetObject(string.Format("{0}_{1}", familyName, Number));
        }
Ejemplo n.º 3
0
        // Checks if the list of tiles forms a valid combination.
        private bool IsValidCombination()
        {
            IEnumerable <FamilyPivot> families = _tiles.Select(t => t.Family).Distinct();

            if (families.Count() > 1)
            {
                // KO : more than one family.
                return(false);
            }

            FamilyPivot family = families.First();

            if (family == FamilyPivot.Dragon)
            {
                // Expected : only one type of dragon.
                return(_tiles.Select(t => t.Dragon).Distinct().Count() == 1);
            }
            else if (family == FamilyPivot.Wind)
            {
                // Expected : only one type of wind.
                return(_tiles.Select(t => t.Wind).Distinct().Count() == 1);
            }

            if (_tiles.Count() == 3)
            {
                if (_tiles.Select(t => t.Number).Distinct().Count() == 1)
                {
                    // OK : only one number of caracter / circle / bamboo.
                    return(true);
                }
                else
                {
                    // Expected : tiles form a sequence [0 / +1 / +2]
                    return(_tiles.ElementAt(0).Number == _tiles.ElementAt(1).Number - 1 &&
                           _tiles.ElementAt(1).Number == _tiles.ElementAt(2).Number - 1);
                }
            }
            else
            {
                // Expected : only one number of caracter / circle / bamboo.
                return(_tiles.Select(t => t.Number).Distinct().Count() == 1);
            }
        }
Ejemplo n.º 4
0
 // Constructor for non-honor families.
 private TilePivot(FamilyPivot family, byte number, bool isRedDora = false)
 {
     Family    = family;
     Number    = number;
     IsRedDora = isRedDora;
 }