Beispiel #1
0
        // tvö pör
        public int tvoPor(Teningar teningar)
        {
            int[] tidniTafla = new int[] { 0, 0, 0, 0, 0, 0 };
            for (int j = 6; j > 0; j--)
            {
                for (int i = 0; i < teningar.teningar.Length; i++)
                {
                    if (j == teningar.teningar[i])
                    {
                        tidniTafla[j - 1] += 1;
                    }
                }
            }
            int fjoldiPara = 0;
            int sum        = 0;

            for (int i = 6; i > 0; i--)
            {
                if (tidniTafla[i - 1] >= 2)
                {
                    sum        += 2 * i;
                    fjoldiPara += 1;
                }
            }

            return(sum);
        }
Beispiel #2
0
        static void Main()
        {
            Teningar teningar = new Teningar();


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Yatzi());
        }
Beispiel #3
0
        // leggur saman gildi allra teninganna
        public int summaAllra(Teningar teningar)
        {
            int sum = 0;

            for (int i = 0; i < teningar.teningar.Length; i++)
            {
                sum += teningar.teningar[i];
            }
            return(sum);
        }
Beispiel #4
0
 // staðfestir fullt hús
 public int fulltHus(Teningar teningar)
 {
     int[] ten = teningar.getTeningar();
     Array.Sort(ten);
     if ((ten[0] == ten[1] && ten[1] == ten[2]) && (ten[3] == ten[4]) || (ten[0] == ten[1] && ten[2] == ten[3]) && (ten[3] == ten[4]))
     {
         return(summaAllra(teningar));
     }
     return(0);
 }
Beispiel #5
0
        // leggur saman alla teninga með tilteknu gildi.
        public int summaEinnTilSex(int value, Teningar teningar)
        {
            int sum = 0;

            for (int i = 0; i < teningar.teningar.Length; i++)
            {
                if (teningar.teningar[i] == value)
                {
                    sum += value;
                }
            }
            return(sum);
        }
Beispiel #6
0
        // n = 1 - litla röð: 1-5
        // n = 2 - stóra röð: 2-6
        public int rod(int n, Teningar teningar)
        {
            int[] ten = teningar.getTeningar();
            int   sum = 0;

            Array.Sort(ten);
            for (int i = 0; i < ten.Length; i++)
            {
                if (i + n == ten[i])
                {
                    sum += i + n;
                }
                else
                {
                    sum = 0;
                }
            }
            return(sum);
        }
Beispiel #7
0
 // Leitar að n eins teningum, tvennu, þrennu, fernu eða yatzi.
 public int nEins(int fjoldi, Teningar teningar)
 {
     for (int i = 6; i > 0; i--)
     {
         int count = 0;
         for (int j = 0; j < teningar.teningar.Length; j++)
         {
             if (i == teningar.teningar[j])
             {
                 count++;
             }
             if (count >= fjoldi)
             {
                 return(j * fjoldi);
             }
         }
     }
     return(0);
 }