Exemple #1
0
 public static bool Contains(SetPiece p, List<SetPiece> list)
 {
     foreach (SetPiece s in list)
     {
         if (p.Equals(s))
             return true;
     }
     return false;
 }
Exemple #2
0
        /// <summary>
        /// Given 3 set pieces, this routine determines is there is a Match.
        /// To get a Match, all 4 variables (Color, Shape, Fill, and Number)
        /// must all be the same or all be different.  If a Match is found,
        /// the function returns true.  Otherwise,  it returns false.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public static bool ContainsMatch(SetPiece a, SetPiece b, SetPiece c)
        {
            bool ret = true;
            if (!Match(a.Number, b.Number, c.Number))
                ret = false;
            if (ret && !Match(a.Color, b.Color, c.Color))
                ret = false;
            if (ret && !Match(a.Shape, b.Shape, c.Shape))
                ret = false;
            if (ret && !Match(a.Fill, b.Fill, c.Fill))
                ret = false;

            return ret;
        }
Exemple #3
0
        /// <summary>
        /// Creates a Set Piece with Random color, number, shape. Fill is constant
        /// </summary>
        /// <returns></returns>
        public static SetPiece CreateSimplePiece()
        {
            SetPiece p = new SetPiece();

            p.Color = GameLogic.RandomNumber(1, 3);
            p.Number = GameLogic.RandomNumber(1, 3);
            p.Shape = GameLogic.RandomNumber(1, 3);
            p.Fill = 1;
            return p;
        }
Exemple #4
0
        /// <summary>
        /// Creates a Set Piece with Random color, number, shape, fill that does not exist in the 
        /// given list of pieces
        /// </summary>
        /// <returns></returns>
        public static SetPiece CreatePiece(List<SetPiece> list)
        {
            bool cont = true;
            SetPiece p = new SetPiece();
            while (cont)
            {

                p.Color = GameLogic.RandomNumber(1, 3);
                p.Number = GameLogic.RandomNumber(1, 3);
                p.Shape = GameLogic.RandomNumber(1, 3);
                p.Fill = GameLogic.RandomNumber(1, 3);
                if (!Contains(p, list))
                {
                    //found a new card!
                    cont = false;
                }
            }
            return p;
        }