Exemplo n.º 1
0
        bool ScoreColumnPresent(RegularCandies[,] matrix)
        {
            //this will be use as a counter.
            int count = 1;
            //the current candy
            RegularCandies currentCandy = RegularCandies.JellyBean;

            for (int col = 0; col < matrix.GetLength(1); col++)
            {
                for (int row = 0; row < matrix.GetLength(0); row++)
                {
                    if (row + col != 0)
                    {
                        //if the candy is the same as in the matrix add 1 to counter
                        if (currentCandy == matrix[row, col])
                        {
                            count++;
                        }
                        else if (count >= 3)
                        {
                            //to check if the counter reaches 3;
                            return(true);
                        }
                        else
                        {
                            //if its the same candies, set the counter to 1;
                            count = 1;
                        }
                    }
                    //set a new current candy
                    currentCandy = matrix[row, col];
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        bool ScoreColumnPresent(RegularCandies[,] matrix)
        {
            int            counter = 0;
            RegularCandies candy   = matrix[0, 0];

            for (int col = 0; col < matrix.GetLength(1); col++)
            {
                for (int row = 0; row < matrix.GetLength(0); row++)
                {
                    if (counter == 0)
                    {
                        counter = 1;
                        candy   = matrix[row, col];
                    }
                    else if (candy == matrix[row, col])
                    {
                        counter++;
                        if (counter == 3)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        counter = 0;
                        candy   = matrix[row, col];
                    }
                }
                counter = 0;
            }
            return(false);
        }
Exemplo n.º 3
0
        void DisplayCandies(RegularCandies[,] PlayingField)
        {
            for (int row = 0; row < PlayingField.GetLength(0); row++)
            {
                for (int col = 0; col < PlayingField.GetLength(1); col++)
                {
                    int number = (int)PlayingField[row, col];

                    switch (number)
                    {
                    case 0: Console.ForegroundColor = ConsoleColor.Yellow; break;

                    case 1: Console.ForegroundColor = ConsoleColor.Green; break;

                    case 2: Console.ForegroundColor = ConsoleColor.Blue; break;

                    case 3: Console.ForegroundColor = ConsoleColor.Magenta; break;

                    case 4: Console.ForegroundColor = ConsoleColor.Red; break;

                    case 5: Console.ForegroundColor = ConsoleColor.DarkYellow; break;
                    }

                    Console.Write("# ");
                }
                Console.WriteLine();
            }

            Console.ResetColor();
        }
Exemplo n.º 4
0
        public static bool ScoreKolomAanwezig(RegularCandies[,] speelveld)
        {
            int currentCandy = (int)speelveld[0, 0];
            int nextCandy    = 0;
            int score        = 1;

            for (int i = 0; i < speelveld.Length; i++)
            {
                int y = i / speelveld.GetLength(0);
                int x = i % speelveld.GetLength(0);

                nextCandy = (int)speelveld[x, y];

                if (nextCandy == currentCandy)
                {
                    score++;
                    if (score == 3)
                    {
                        return(true);
                    }
                }
                else
                {
                    score = 1;
                }
                currentCandy = (int)speelveld[x, y];
            }
            return(false);
        }
        private bool ScoreColumnCheck(RegularCandies[,] field)
        {
            for (int r = 0; r < field.GetLength(0); r++)
            {
                int            curr    = 1;
                RegularCandies currcan = field[r, 0];

                for (int c = 1; c < field.GetLength(1); c++)
                {
                    if (currcan == field[r, c])
                    {
                        curr++;
                        if (curr == POINTSCORE)
                        {
                            Console.WriteLine("On column {0} there {1} next to eachother.", r + 1, curr);
                            return(true);
                        }
                    }
                    else
                    {
                        curr = 1;
                    }
                    currcan = field[r, c];
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public bool ScoreColumnPresent(RegularCandies[,] matrix)
        {
            RegularCandies regularCandies = new RegularCandies();
            int            count          = 1;

            for (int col = 0; col < matrix.GetLength(1); col++)
            {
                for (int row = 0; row < matrix.GetLength(0); row++)
                {
                    if (regularCandies == matrix[row, col])
                    {
                        count++;
                        regularCandies = matrix[row, col];
                    }
                    else
                    {
                        count = 1;
                    }

                    if (count >= 3)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 7
0
        void WritePlayingField(RegularCandies[,] playingField, string filename)
        {
            Random       rnd    = new Random();
            StreamWriter writer = new StreamWriter(filename);
            int          row;
            int          colomn;

            writer.WriteLine(playingField.GetLength(0));
            writer.WriteLine(playingField.GetLength(1));

            for (row = 0; row < playingField.GetLength(0); row++)
            {
                List <int> candyvalues = new List <int>();
                for (colomn = 0; colomn < playingField.GetLength(1); colomn++)
                {
                    int            value      = rnd.Next(1, 7);
                    RegularCandies candyvalue = (RegularCandies)value;
                    playingField[row, colomn] = candyvalue;
                    candyvalues.Add(value);
                    writer.Write(value + " ");
                }

                writer.WriteLine();
            }

            writer.Close();
        }
        public static bool ScoreRowCheck(RegularCandies[,] field)
        {
            for (int r = 0; r < field.GetLength(0); r++)
            {
                int            curr    = 1;
                RegularCandies currcan = field[0, r];

                for (int c = 1; c < field.GetLength(1); c++)
                {
                    if (currcan == field[c, r])
                    {
                        curr++;
                        if (curr == 3)
                        {
                            Console.WriteLine("On row {0} there {1} next to eachother.", r + 1, curr);
                            return(true);
                        }
                    }
                    else
                    {
                        curr = 1;
                    }
                    currcan = field[c, r];
                }
            }
            return(false);
        }
Exemplo n.º 9
0
        bool ScoreColumnPresent(RegularCandies[,] playingField)
        {
            for (int c = 0; c < playingField.GetLength(1); c++)
            {
                int counter1 = 1;
                Console.WriteLine("");

                for (int r = 0; r < playingField.GetLength(0); r++)
                {
                    Console.Write(playingField[r, c]);
                    RegularCandies curCandy = playingField[r, c];

                    if (curCandy == playingField[r, c])
                    {
                        counter1++;
                    }
                    else
                    {
                        counter1 = 1;
                        curCandy = playingField[r, c];
                    }

                    Console.WriteLine(curCandy);
                    Console.WriteLine(counter1++);
                }
            }
            return(false);
        }
Exemplo n.º 10
0
        bool ScoreRowPresent(RegularCandies[,] candies)
        {
            int currentcandy = 0;
            int scorecombo   = 1;

            for (int row = 0; row < candies.GetLength(0); row++)
            {
                for (int colomn = 0; colomn < candies.GetLength(1); colomn++)
                {
                    if (currentcandy != 0)
                    {
                        if (currentcandy == (int)candies[row, colomn])
                        {
                            scorecombo++;
                        }
                        else
                        {
                            scorecombo   = 1;
                            currentcandy = (int)candies[row, colomn];
                        }
                        if (scorecombo >= 3)
                        {
                            return(true);
                        }
                    }

                    else if (currentcandy == 0)
                    {
                        currentcandy = (int)candies[row, colomn];
                    }
                }
            }
            return(false);
        }
Exemplo n.º 11
0
        bool ScoreRijAanwezig(RegularCandies[,] candies)
        {
            // Standaard benodigde waardes
            int teller = 1;

            for (int r = 0; r < candies.GetLength(0); r++)
            {
                for (int k = 0; k < candies.GetLength(1); k++)
                {
                    if (k + 1 < candies.GetLength(1) && candies[r, k] == candies[r, k + 1])
                    {
                        teller++;
                        if (teller >= 3)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        teller = 1;
                    }
                }
            }
            return(false);
        }
Exemplo n.º 12
0
        bool ScoreKolomAanwezig(RegularCandies[,] candies)
        {
            int teller = 1;


            for (int r = 0; r < candies.GetLength(0); r++)
            {
                for (int k = 0; k < candies.GetLength(1); k++)
                {
                    if (r + 1 < candies.GetLength(0) && candies[r, k] == candies[r + 1, k])
                    {
                        teller++;
                        r++;

                        if (r + 1 < candies.GetLength(0) && candies[r, k] == candies[r + 1, k])
                        {
                            teller++;
                        }
                        else
                        {
                            r--;
                            teller = 1;
                        }
                        if (teller >= 3)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 13
0
        bool ScoreRowPresent(RegularCandies[,] PlayingField)
        {
            for (int row = 0; row < PlayingField.GetLength(0); row++)
            {
                int candyCounter = 1;

                for (int col = 1; col < PlayingField.GetLength(1); col++)
                {
                    if ((int)PlayingField[row, col] == (int)PlayingField[row, col - 1])
                    {
                        candyCounter++;
                    }
                    else
                    {
                        candyCounter = 1;
                    }

                    if (candyCounter >= 4)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        bool ScoreColumnnPresent(RegularCandies[,] matrix)       // i need to try and make foreach version of this
        {
            RegularCandies MainCandy = RegularCandies.JellyBean; //variable not sure..
            int            count     = 1;                        //this is for the counter if there is a row found.

            for (int column = 0; column < matrix.GetLength(0); column++)
            {
                for (int row = 0; row < matrix.GetLength(1); row++)
                {
                    if (row + column != 0)
                    {
                        if (matrix[row, column] == MainCandy)
                        {
                            count++;
                        }
                        else if (count >= 3)
                        {
                            //Console.WriteLine("column score")
                            return(true);
                        }
                        else// this doesnt make sense, i need to understand and see how this works, shown by jurek
                        {
                            count = 1;
                        }
                    }
                    MainCandy = matrix[row, column];// i need some explanation for this
                }
            }
            //Console.WriteLine("no colunn score")
            return(false);
        }
        private void WritePlayfield(RegularCandies[,] field, string filename)
        {
            StreamWriter sw = new StreamWriter(@"..\\..\\" + filename + ".txt");

            try
            {
                sw.WriteLine(field.GetLength(0));
                sw.WriteLine(field.GetLength(1));
                int w = field.GetLength(0);
                int h = field.GetLength(1);
                for (int i = 0; i < h; i++)
                {
                    string temp = "";
                    for (int b = 0; b < w; b++)
                    {
                        temp += (int)field[b, i] + " ";
                    }
                    sw.WriteLine(temp);
                }
            }
            finally
            {
                sw.Close();
            }
        }
Exemplo n.º 16
0
        public static bool ScoreColumnPresent(RegularCandies[,] matrix)
        {
            // Give lastCandy an initial value so the compiler doesn't complain
            RegularCandies lastCandy = RegularCandies.Jellybean;

            int counter = 1;

            // Exactly like ScoreRowPresent but columns and rows switched
            for (int col = 0; col < matrix.GetLength(1); col++)
            {
                for (int row = 0; row < matrix.GetLength(0); row++)
                {
                    // Start from the second element, since the first cannot be compared to anything.
                    if (row + col != 0)
                    {
                        if (lastCandy == matrix[row, col])
                        {
                            counter++;
                        }
                        else
                        {
                            counter = 1;
                        }

                        if (counter >= 3)
                        {
                            return(true);
                        }
                    }
                    lastCandy = matrix[row, col];
                }
            }
            return(false);
        }
Exemplo n.º 17
0
        bool ScoreRowPresent(RegularCandies[,] playingField)
        {
            for (int r = 0; r < playingField.GetLength(0); r++)
            {
                int counter = 1;

                for (int c = 0; c < playingField.GetLength(1); c++)
                {
                    if (c != 0)
                    {
                        RegularCandies curCandy = playingField[r, c - 1];

                        if (curCandy == playingField[r, c])
                        {
                            counter++;
                        }
                        else
                        {
                            counter  = 1;
                            curCandy = playingField[r, c];
                        }
                    }
                    if (counter >= 3)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 18
0
 void start(int nrOfRows, int nrOfColums)
 {
     RegularCandies[,] pf           = new RegularCandies[nrOfRows, nrOfColums];
     RegularCandies[,] playingField = initCandies(pf);
     displayCandies(playingField);
     Console.WriteLine((ScoreRowPresent(playingField)) ? "row found" : "no row score");
     Console.WriteLine((ScoreColumnPresent(playingField)) ? "column found" : "no column score");
 }
Exemplo n.º 19
0
 void InitCandies(RegularCandies[,] candies)
 {
     for (int r = 0; r < candies.GetLength(0); r++)
     {
         for (int k = 0; k < candies.GetLength(1); k++)
         {
             candies[r, k] = (RegularCandies)rnd.Next(1, 7);
         }
     }
 }
        private void InitCandies(RegularCandies[,] field)
        {
            Random rand = new Random();

            for (int r = 0; r < field.GetLength(0); r++)
            {
                for (int c = 0; c < field.GetLength(1); c++)
                {
                    field[r, c] = (RegularCandies)rand.Next(0, Enum.GetNames(typeof(RegularCandies)).Length);
                }
            }
        }
Exemplo n.º 21
0
        void InitCandies(RegularCandies[,] matrix)
        {
            Random rng = new Random();

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    matrix[row, col] = (RegularCandies)rng.Next(1, 7);
                }
            }
        }
Exemplo n.º 22
0
        void InitCandies(ref RegularCandies[,] speelveld)
        {
            Random rnd = new Random();

            for (int x = 0; x < speelveld.GetLength(0); x++)
            {
                for (int y = 0; y < speelveld.GetLength(1); y++)
                {
                    speelveld[x, y] = (RegularCandies)rnd.Next(0, 7);
                }
            }
        }
Exemplo n.º 23
0
        void InitCandies(RegularCandies[,] matrix)
        {
            Random rnd = new Random();

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    matrix[i, j] = (RegularCandies)rnd.Next(1, 7);
                }
            }
        }
        void InitCandies(RegularCandies[,] matrix)// question C
        {
            Random rnd = new Random();

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                for (int column = 0; column < matrix.GetLength(1); column++)
                {
                    matrix[row, column] = (RegularCandies)rnd.Next(1, 7);//to fix this one, dont know what im doing wrong.
                }
                //Console.WriteLine();
            }
        }
Exemplo n.º 25
0
 void InitCandies(RegularCandies[,] matrix)
 {
     int num;
     Random rnd = new Random();
     for (int row = 0; row < matrix.GetLength(0); row++)
     {
         for (int col = 0; col < matrix.GetLength(1); col++)
         {
             num = rnd.Next(0, 6);
             matrix[row, col] = (RegularCandies)num;
         }
     }
 }
Exemplo n.º 26
0
        void InitCandies(RegularCandies[,] playingField)
        {
            Random Rnd = new Random();

            for (int r = 0; r < playingField.GetLength(0); r++)
            {
                for (int c = 0; c < playingField.GetLength(1); c++)
                {
                    int number = Rnd.Next(1, Enum.GetValues(typeof(RegularCandies)).Length);
                    playingField[r, c] = (RegularCandies)number;
                }
            }
        }
Exemplo n.º 27
0
        void DisplayCandies(RegularCandies[,] matrix)
        {
            RegularCandies candy;
            string symbol = "#";
            Console.ForegroundColor = ConsoleColor.Black;
            Console.Write(" 0");
            Console.ResetColor();
            for (int col = 0; col < matrix.GetLength(0); col++)
            {
                Console.Write($" {col}");
            }
            Console.WriteLine();

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.Write($" {row}");
                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    candy = matrix[row, col];

                    if (candy == RegularCandies.JellyBean)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    else if (candy == RegularCandies.Lozenge)
                    {
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    else if (candy == RegularCandies.LemonDrop)
                    {
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                    }
                    else if (candy == RegularCandies.GumSquare)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                    }
                    else if (candy == RegularCandies.LollipopHead)
                    {
                        Console.ForegroundColor = ConsoleColor.Blue;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                    }

                    Console.Write(" {0}", symbol);
                    Console.ResetColor();
                }
                Console.WriteLine();
            }
        }
Exemplo n.º 28
0
        void PrintCandies(RegularCandies[,] speelveld)
        {
            int rows    = speelveld.GetLength(0);
            int columns = speelveld.GetLength(1);

            for (int r = 0; r < rows; r++)
            {
                for (int c = 0; c < columns; c++)
                {
                    RegularCandies toPrint = speelveld[r, c];

                    switch (toPrint)
                    {
                    case RegularCandies.JellyBean:
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;

                    case RegularCandies.Lozenge:
                        Console.ForegroundColor = ConsoleColor.DarkYellow;
                        break;

                    case RegularCandies.LemonDrop:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        break;

                    case RegularCandies.GumSquare:
                        Console.ForegroundColor = ConsoleColor.Green;
                        break;

                    case RegularCandies.LollipopHead:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        break;

                    case RegularCandies.JujubeCluster:
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        break;

                    default:
                        Console.ResetColor();
                        break;
                    }

                    Console.Write("# ");
                }

                Console.WriteLine();
            }

            Console.ResetColor();
        }
Exemplo n.º 29
0
        void InitCandies(ref RegularCandies[,] speelveld, string bestandsnaam)
        {
            try
            {
                speelveld = LeesSpeelveld(bestandsnaam);
            }
            catch (Exception e)
            {
                Console.WriteLine("An error has occured: " + e.Message);
                Console.WriteLine("Creating a new random field...");

                InitCandies(ref speelveld);
            }
        }
Exemplo n.º 30
0
        RegularCandies[,] initCandies(RegularCandies[,] playingField)
        {
            Array  values = Enum.GetValues(typeof(RegularCandies));
            Random random = new Random();

            for (int i = 0; i < playingField.GetLength(0); i++)
            {
                for (int j = 0; j < playingField.GetLength(1); j++)
                {
                    playingField[i, j] = (RegularCandies)values.GetValue(random.Next(values.Length));
                }
            }
            return(playingField);
        }