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);
        }
        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);
        }
Beispiel #3
0
        void Start()
        {
            RegularCandies[,] playingfield = new RegularCandies[9, 9];
            InitCandies(playingfield);
            DisplayCandies(playingfield);

            if (ScoreRowPresent(playingfield))
            {
                Console.WriteLine("row score!");
            }
            else
            {
                Console.WriteLine("no row score");
            }

            if (ScoreColumnPresent(playingfield))
            {
                Console.WriteLine("column score!");
            }
            else
            {
                Console.WriteLine("no column score!");
            }

            Console.ReadKey();
        }
        private void Start()
        {
            RegularCandies[,] playfield = new RegularCandies[7, 7];
            InitCandies(playfield);
            PrintCandies(playfield);
            ScoreRowCheck(playfield);
            if (ScoreRowCheck(playfield))
            {
                Console.WriteLine("Score row found");
            }
            else
            {
                Console.WriteLine("Score row not found");
            }

            if (ScoreColumnCheck(playfield))
            {
                Console.WriteLine("Score column found");
            }
            else
            {
                Console.WriteLine("Score column not found");
            }

            Console.ReadKey();
        }
        RegularCandies[,] ReadPlayingField(string filename)
        {
            RegularCandies[,] playingField = new RegularCandies[10, 10];//add this here so that, it can use the size of the arrays
            StreamReader reader = new StreamReader(filename);

            //while(!reader.EndOfStream)
            // {
            // string[]field = s.Split();
            try//im not sure if im using this properly
            {
                for (int i = 0; i < playingField.GetLength(0); i++)
                {
                    string   s             = reader.ReadLine();//sisi showed me the way
                    string[] numberStrings = s.Split(' ');
                    for (int j = 0; j < playingField.GetLength(1); j++)
                    {
                        playingField[i, j] = (RegularCandies)int.Parse(numberStrings[j]);
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Exception occured: {0}", exception.Message);
            }

            // }
            reader.Close();
            return(playingField);
        }
Beispiel #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);
        }
        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);
        }
Beispiel #8
0
        void Start()
        {
            RegularCandies[,] speelveld = new RegularCandies[9, 9];

            InitCandies(speelveld);
            PrintCandies(speelveld);

            if (ScoreRijAanwezig(speelveld))
            {
                Console.WriteLine("Ja, er is een score rij aanwezig");
            }
            else
            {
                Console.WriteLine("Nee, er is geen score rij aanwezig");
            }

            if (ScoreKolomAanwezig(speelveld))
            {
                Console.WriteLine("Ja, er is een score kolom aanwezig");
            }
            else
            {
                Console.WriteLine("Nee, er is geen score kolom aanwezig");
            }


            Console.ReadKey();
        }
Beispiel #9
0
        void Start()
        {
            RegularCandies[,] playingField = new RegularCandies[9, 9];
            InitCandies(playingField);
            DisplayCandies(playingField);
            bool scorerow    = ScoreRowPresent(playingField);
            bool scorecolumn = ScoreColumnPresent(playingField);

            //this for the score row
            if (scorerow)
            {
                Console.WriteLine("row score");
            }
            else
            {
                Console.WriteLine("no row score");
            }

            //message when there is a score in the column
            if (scorecolumn)
            {
                Console.WriteLine("column score");
            }
            else
            {
                Console.WriteLine("no column  score");
            }
        }
Beispiel #10
0
        void Start()
        {
            RegularCandies[,] speelveld = new RegularCandies[9, 9];

            InitCandies(ref speelveld);
            PrintCandies(speelveld);

            if (ScoreRijAanwezig(speelveld))
            {
                Console.WriteLine("Er is een score rij aanwezig");
            }
            else
            {
                Console.WriteLine("Er is GEEN score rij aanwezig");
            }

            if (ScoreKolomAanwezig(speelveld))
            {
                Console.WriteLine("Er is een score kolom aanwezig");
            }
            else
            {
                Console.WriteLine("Er is GEEN score kolom aanwezig");
            }
        }
        private void Start()
        {
            CandyCrushLogica.RegularCandies[,] playfield = new RegularCandies[7, 7];
            InitCandies(playfield);
            PrintCandies(playfield);

            CandyCrusher.ScoreRowCheck(playfield);
            ReadPlayfield("Playfield");
            WritePlayfield(playfield, "Playfield");

            if (CandyCrusher.ScoreRowCheck(playfield))
            {
                Console.WriteLine("Score row found");
            }
            else
            {
                Console.WriteLine("Score row not found");
            }

            if (CandyCrusher.ScoreColumnCheck(playfield))
            {
                Console.WriteLine("Score column found");
            }
            else
            {
                Console.WriteLine("Score column not found");
            }

            Console.ReadKey();
        }
Beispiel #12
0
        void Start()
        {
            RegularCandies[,] playingField = new RegularCandies[10, 10];
            InitCandies(playingField);
            DisplayCandies(playingField);
            Console.WriteLine();
            if (ScoreRowPresent(playingField))
            {
                Console.WriteLine("Row score!");
            }
            else
            {
                Console.WriteLine("No row score.");
            }

            if (ScoreColumnPresent(playingField))
            {
                Console.WriteLine("Column score!");
            }
            else
            {
                Console.WriteLine("No column score.");
            }

            _ = Console.ReadKey();
        }
Beispiel #13
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);
        }
        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);
        }
Beispiel #15
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);
        }
Beispiel #16
0
        void Start()
        {
            //prep
            RegularCandies[,] PlayingField = new RegularCandies[12, 8];
            InitCandies(PlayingField);
            DisplayCandies(PlayingField);

            //scores
            Console.WriteLine();
            bool scoreRow = ScoreRowPresent(PlayingField);

            if (scoreRow == true)
            {
                Console.WriteLine("Row Score!");
            }
            else
            {
                Console.WriteLine("No Row Score :(");
            }

            bool scoreCol = ScoreColPresent(PlayingField);

            if (scoreCol == true)
            {
                Console.WriteLine("Column Score!");
            }
            else
            {
                Console.WriteLine("No Column Score :(");
            }

            //end
            Console.ReadKey(true);
        }
Beispiel #17
0
        RegularCandies[,] LeesSpeelveld(ref StreamReader reader)
        {
            string gelezenregel;
            int    xmax, ymax;

            gelezenregel = reader.ReadLine();

            string[] xyparams = gelezenregel.Split(' ');
            xmax = int.Parse(xyparams[0]);
            ymax = int.Parse(xyparams[1]);

            RegularCandies[,] speelveld = new RegularCandies[xmax, ymax];

            for (int y = 0; y < ymax; y++)
            {
                gelezenregel = reader.ReadLine();
                string[] nummers = gelezenregel.Split(' ');
                for (int x = 0; x < xmax; x++)
                {
                    speelveld[x, y] = (RegularCandies)int.Parse(nummers[x]);
                }
            }

            reader.Close();
            return(speelveld);
        }
Beispiel #18
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);
        }
Beispiel #19
0
        RegularCandies[,] LeesSpeelveld(string bestandsnaam)
        {
            StreamReader sr = new StreamReader(PATH + bestandsnaam);

            try
            {
                int rows    = int.Parse(sr.ReadLine());
                int columns = int.Parse(sr.ReadLine());

                RegularCandies[,] speelveld = new RegularCandies[rows, columns];

                for (int r = 0; r < rows; r++)
                {
                    string   regel   = sr.ReadLine();
                    string[] candies = regel.Split(' ');

                    for (int c = 0; c < columns; c++)
                    {
                        speelveld[r, c] = (RegularCandies)int.Parse(candies[c]);
                    }
                }

                sr.Close();

                return(speelveld);
            }
            catch (Exception e)
            {
                sr.Close();

                throw e;
            }
        }
Beispiel #20
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);
        }
Beispiel #21
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();
        }
Beispiel #22
0
        void Start(int nrOfRows, int nrOfColumns)
        {
            RegularCandies[,] playingField = new RegularCandies[nrOfRows, nrOfColumns];

            InitCandies(playingField);
            DisplayCandies(playingField);
            bool scoreRow = ScoreRowPresent(playingField);

            if (scoreRow == true)
            {
                Console.WriteLine("row score");
            }
            else
            {
                Console.WriteLine("no row score");
            }

            bool scoreCol = ScoreColumnPresent(playingField);

            if (scoreRow == true)
            {
                Console.WriteLine("column score");
            }
            else
            {
                Console.WriteLine("no column score");
            }
        }
Beispiel #23
0
        RegularCandies[,] LeesSpeelveld(string bestandsnaam)
        {
            RegularCandies[,] speelveld = new RegularCandies[9, 9];
            StreamReader reader = new StreamReader(bestandsnaam);

            // Als het niet lukt moet de reader ook gesloten worden anders kunnen we niet overschrijven.
            try
            {
                for (int r = 0; r < speelveld.GetLength(0); r++)
                {
                    string   regel        = reader.ReadLine();
                    string[] getalStrings = regel.Split(' ');
                    for (int k = 0; k < speelveld.GetLength(1); k++)
                    {
                        speelveld[r, k] = (RegularCandies)int.Parse(getalStrings[k]);
                    }
                }
                reader.Close();
                return(speelveld);
            }
            catch (Exception)
            {
                reader.Close();
                throw;
            }
        }
Beispiel #24
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");
 }
        void Start()
        {
            RegularCandies[,] playingField = new RegularCandies[8, 8];;

            string filename = "playingfield.txt";

            bool fileread = false;

            if (File.Exists(filename))
            {
                Console.WriteLine("Loading");
                try
                {
                    playingField = ReadPlayingField(filename);
                    fileread     = true;
                }

                catch (Exception)
                {
                    fileread = false;
                }
            }

            if (!fileread)
            {
                Console.WriteLine("Generating new field");
                playingField = new RegularCandies[8, 8];
                InitCandies(playingField);

                WritePlayingField(playingField, filename);
            }

            DisplayCandies(playingField);

            bool rowScored = CandyCrusher.ScoreRowPresent(playingField);
            bool colScored = CandyCrusher.ScoreColumnPresent(playingField);


            if (rowScored)
            {
                Console.WriteLine("row score!");
            }
            else
            {
                Console.WriteLine("no row score");
            }

            if (colScored)
            {
                Console.WriteLine("column score!");
            }
            else
            {
                Console.WriteLine("no column score");
            }

            Console.ReadKey();
        }
Beispiel #26
0
        void Start()
        {
            RegularCandies[,] candies = new RegularCandies[6, 6];
            InitCandies(candies);
            DisplayCandies(candies);
            DisplayScore(ScoreRowPresent(candies), ScoreColomnPresent(candies));

            Console.ReadKey();
        }
Beispiel #27
0
        void Start()
        {
            RegularCandies[,] speelveld = new RegularCandies[5, 5];

            InitCandies(ref speelveld);

            PrintCandies(speelveld);
            Console.WriteLine($"Horizontal: {ScoreRijAanwezig(speelveld)}\nVertical: {ScoreKolomAanwezig(speelveld)}");

            Console.ReadKey();
        }
Beispiel #28
0
        bool Start()
        {
            RegularCandies[,] playingField;
            Position posRow = new Position();
            Position posCol = new Position();

            if (File.Exists("playingField.txt"))
            {
                playingField = ReadPlayingField("playingField.txt");
            }
            else
            {
                playingField = new RegularCandies[10, 10];
                InitCandies(playingField);
                WritePlayingField(playingField, "playingField.txt");
            }
            DisplayCandies(playingField);
            Console.WriteLine();
            if (ScoreRowPresent(playingField, out posRow))
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Row score! ");
                Console.ResetColor();
                Console.WriteLine($"First position: ({posRow.column}, {posRow.row})");
            }
            else
            {
                Console.WriteLine("No row score.");
            }
            Console.WriteLine();
            if (ScoreColumnPresent(playingField, out posCol))
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Column score! ");
                Console.ResetColor();
                Console.WriteLine($"First position: ({posCol.column}, {posCol.row})");
            }
            else
            {
                Console.WriteLine("No column score.");
            }

            if (RemoveSaveFile())
            {
                File.Delete("playingField.txt");
                Console.WriteLine("Your safe file has been succesfully deleted.");
            }


            return(ProgramTools.LoopProgram());
        }
Beispiel #29
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();
        }
Beispiel #30
0
        void InitCandies(RegularCandies[,] candies)
        {
            Random rnd = new Random();

            for (int row = 0; row < candies.GetLength(0); row++)
            {
                for (int colomn = 0; colomn < candies.GetLength(1); colomn++)
                {
                    int            value      = rnd.Next(1, 7);
                    RegularCandies candyvalue = (RegularCandies)value;
                    candies[row, colomn] = candyvalue;
                }
            }
        }