Esempio n. 1
0
        private void newEgg(int i, int j, bool bomb)
        {
            Point p   = new Point(j * FieldDimension + 5, (i) * FieldDimension + Vgap);
            int   rnd = 0;

            if (numBlocks > 0)
            {
                rnd = random.Next(colorNum);
            }
            else
            {
                rnd = random.Next(colorNum - 1);
            }
            if (rnd == 6)
            {
                numBlocks--;
            }
            Table[i, j] = new Egg(getColor(rnd, true), FieldDimension, p, rnd, true, speed);
            Table[i, j].currPosition = p;
        }
Esempio n. 2
0
 private void newEgg(int i, int j, bool bomb)
 {
     Point p = new Point(j * FieldDimension + 5, (i) * FieldDimension + Vgap);
     int rnd = 0;
     if (numBlocks > 0) rnd = random.Next(colorNum);
     else rnd = random.Next(colorNum - 1);
     if (rnd == 6) numBlocks--;
     Table[i, j] = new Egg(getColor(rnd, true), FieldDimension, p, rnd, true,speed);
     Table[i, j].currPosition = p;
 }
Esempio n. 3
0
        /// <summary>
        /// Gi menuva mestata na soodvetnite figuri
        /// </summary>
        /// <param name="direction"> pravec na menuvanje</param>
        /// <returns>true dokolku e vozmozna zamena, inaku false</returns>
        public bool swap(Egg.Direction direction)
        {
            currDir = direction;
            //menuvanje mesta so blok ne e dozvoleno
            if (Table[currEgg.X, currEgg.Y].isBrick()) return false;
            //vo zavisnost od pravecot se menuva pozicijata i mesto vo tabelata
            //currDir se menuva vo obratna nasoka bidejki se zameneti poziciite
            switch (direction)
            {
                case Egg.Direction.Up:
                    if (currEgg.X - 1 >= 0)
                    {
                        if (Table[currEgg.X - 1, currEgg.Y].isBrick()) return false;
                        Egg tmp = Table[currEgg.X, currEgg.Y];
                        Table[currEgg.X, currEgg.Y] = Table[currEgg.X - 1, currEgg.Y];
                        Table[currEgg.X - 1, currEgg.Y] = tmp;

                        int y = Table[currEgg.X, currEgg.Y].position.Y;
                        Table[currEgg.X, currEgg.Y].position = new Point(Table[currEgg.X, currEgg.Y].position.X, Table[currEgg.X - 1, currEgg.Y].position.Y);
                        Table[currEgg.X - 1, currEgg.Y].position = new Point(Table[currEgg.X, currEgg.Y].position.X, y);

                        currDir = Egg.Direction.Down;
                        return true;

                    }
                    break;
                case Egg.Direction.Right:
                    if (currEgg.Y + 1 < TableSize.Width)
                    {
                        if (Table[currEgg.X, currEgg.Y+1].isBrick()) return false;
                        Egg tmp = Table[currEgg.X, currEgg.Y];
                        Table[currEgg.X, currEgg.Y] = Table[currEgg.X, currEgg.Y + 1];
                        Table[currEgg.X, currEgg.Y + 1] = tmp;

                        int x = Table[currEgg.X, currEgg.Y].position.X;
                        Table[currEgg.X, currEgg.Y].position = new Point(Table[currEgg.X, currEgg.Y + 1].position.X, Table[currEgg.X, currEgg.Y].position.Y);
                        Table[currEgg.X, currEgg.Y + 1].position = new Point(x, Table[currEgg.X, currEgg.Y].position.Y);

                        currDir = Egg.Direction.Left;
                        return true;
                    }
                    break;
                case Egg.Direction.Left:
                    if (currEgg.Y - 1 >= 0)
                    {
                        if (Table[currEgg.X, currEgg.Y-1].isBrick()) return false;
                        Egg tmp = Table[currEgg.X, currEgg.Y];
                        Table[currEgg.X, currEgg.Y] = Table[currEgg.X, currEgg.Y - 1];
                        Table[currEgg.X, currEgg.Y - 1] = tmp;

                        int x = Table[currEgg.X, currEgg.Y].position.X;
                        Table[currEgg.X, currEgg.Y].position = new Point(Table[currEgg.X, currEgg.Y - 1].position.X, Table[currEgg.X, currEgg.Y].position.Y);
                        Table[currEgg.X, currEgg.Y - 1].position = new Point(x, Table[currEgg.X, currEgg.Y].position.Y);

                        currDir = Egg.Direction.Right;
                        return true;
                    }
                    break;
                case Egg.Direction.Down:
                    if (currEgg.X + 1 < TableSize.Height)
                    {
                        if (Table[currEgg.X+1, currEgg.Y].isBrick()) return false;
                        Egg tmp = Table[currEgg.X, currEgg.Y];
                        Table[currEgg.X, currEgg.Y] = Table[currEgg.X + 1, currEgg.Y];
                        Table[currEgg.X + 1, currEgg.Y] = tmp;

                        int y = Table[currEgg.X, currEgg.Y].position.Y;
                        Table[currEgg.X, currEgg.Y].position = new Point(Table[currEgg.X, currEgg.Y].position.X, Table[currEgg.X + 1, currEgg.Y].position.Y);
                        Table[currEgg.X + 1, currEgg.Y].position = new Point(Table[currEgg.X, currEgg.Y].position.X, y);

                        currDir = Egg.Direction.Up;
                        return true;
                    }
                    break;
            }
            return false;
        }
Esempio n. 4
0
        /// <summary>
        /// funkcija so koja se spustaat jajcata odozgora i se inicijaliziraat novi
        /// </summary>
        /// <returns>true se dodeka se spustaat jajcata, na krajot false</returns>
        public bool drop()
        {
            //vo nekoja iteracija se preskoknuva prviot del
            if (!skip)
            {
                empties = new List<Size>();
                //se baraat prazni polinja
                for (int i = 0; i < TableSize.Width; i++)
                {
                    for (int j = 0; j < TableSize.Height; j++)
                    {
                        if (Table[j, i] == null)
                        {
                            empties.Add(new Size(i, j));
                            break;
                        }
                    }
                }
                //dokolku nema prazni polinja ne padjaat figuri
                if (empties.Count == 0)
                {
                    return false;
                }
                //pogornite figuri gi zazimaat mestata na praznite i se inicijaliziraat novi
                for (int i = 0; i < empties.Count; i++)
                {
                    int col = empties.ElementAt(i).Width;
                    int row = empties.ElementAt(i).Height;

                    while (row != 0)
                    {
                        Table[row, col] = Table[row - 1, col];
                        int y = Table[row, col].position.Y + FieldDimension;
                        int x = Table[row, col].position.X;
                        Table[row, col].position = new Point(x, y);
                        row--;
                    }
                    int rnd = 0;
                    if (numBlocks > 0)
                    {
                        rnd = random.Next(colorNum);
                    }
                    else
                    {
                        rnd = random.Next(colorNum-1);
                    }
                    if (rnd == 6) numBlocks--;
                    Table[0, col] = new Egg(getColor(rnd, false), FieldDimension, new Point(col * FieldDimension + 5, Vgap), rnd, false,speed);

                }
                //vo slednata iteracija ke se preskokne ovoj del
                skip = true;
            }

            for (int i = 0; i < empties.Count; i++)
            {
                int col = empties.ElementAt(i).Width;
                int row = empties.ElementAt(i).Height;

                while (row >= 0)
                {
                    //koga ke prestanat da padjaat vo slednata iteracija pak se proveruva za prazni polinja
                    if (!Table[row, col].move(Egg.Direction.Down))
                    {
                        skip = false;
                    }
                    row--;
                }
            }
            return true;
        }
Esempio n. 5
0
        /// <summary>
        /// funkcija so koja se spustaat jajcata odozgora i se inicijaliziraat novi
        /// </summary>
        /// <returns>true se dodeka se spustaat jajcata, na krajot false</returns>
        public bool drop()
        {
            //vo nekoja iteracija se preskoknuva prviot del
            if (!skip)
            {
                empties = new List <Size>();
                //se baraat prazni polinja
                for (int i = 0; i < TableSize.Width; i++)
                {
                    for (int j = 0; j < TableSize.Height; j++)
                    {
                        if (Table[j, i] == null)
                        {
                            empties.Add(new Size(i, j));
                            break;
                        }
                    }
                }
                //dokolku nema prazni polinja ne padjaat figuri
                if (empties.Count == 0)
                {
                    return(false);
                }
                //pogornite figuri gi zazimaat mestata na praznite i se inicijaliziraat novi
                for (int i = 0; i < empties.Count; i++)
                {
                    int col = empties.ElementAt(i).Width;
                    int row = empties.ElementAt(i).Height;

                    while (row != 0)
                    {
                        Table[row, col] = Table[row - 1, col];
                        int y = Table[row, col].position.Y + FieldDimension;
                        int x = Table[row, col].position.X;
                        Table[row, col].position = new Point(x, y);
                        row--;
                    }
                    int rnd = 0;
                    if (numBlocks > 0)
                    {
                        rnd = random.Next(colorNum);
                    }
                    else
                    {
                        rnd = random.Next(colorNum - 1);
                    }
                    if (rnd == 6)
                    {
                        numBlocks--;
                    }
                    Table[0, col] = new Egg(getColor(rnd, false), FieldDimension, new Point(col * FieldDimension + 5, Vgap), rnd, false, speed);
                }
                //vo slednata iteracija ke se preskokne ovoj del
                skip = true;
            }

            for (int i = 0; i < empties.Count; i++)
            {
                int col = empties.ElementAt(i).Width;
                int row = empties.ElementAt(i).Height;

                while (row >= 0)
                {
                    //koga ke prestanat da padjaat vo slednata iteracija pak se proveruva za prazni polinja
                    if (!Table[row, col].move(Egg.Direction.Down))
                    {
                        skip = false;
                    }
                    row--;
                }
            }
            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Gi menuva mestata na soodvetnite figuri
        /// </summary>
        /// <param name="direction"> pravec na menuvanje</param>
        /// <returns>true dokolku e vozmozna zamena, inaku false</returns>
        public bool swap(Egg.Direction direction)
        {
            currDir = direction;
            //menuvanje mesta so blok ne e dozvoleno
            if (Table[currEgg.X, currEgg.Y].isBrick())
            {
                return(false);
            }
            //vo zavisnost od pravecot se menuva pozicijata i mesto vo tabelata
            //currDir se menuva vo obratna nasoka bidejki se zameneti poziciite
            switch (direction)
            {
            case Egg.Direction.Up:
                if (currEgg.X - 1 >= 0)
                {
                    if (Table[currEgg.X - 1, currEgg.Y].isBrick())
                    {
                        return(false);
                    }
                    Egg tmp = Table[currEgg.X, currEgg.Y];
                    Table[currEgg.X, currEgg.Y]     = Table[currEgg.X - 1, currEgg.Y];
                    Table[currEgg.X - 1, currEgg.Y] = tmp;

                    int y = Table[currEgg.X, currEgg.Y].position.Y;
                    Table[currEgg.X, currEgg.Y].position     = new Point(Table[currEgg.X, currEgg.Y].position.X, Table[currEgg.X - 1, currEgg.Y].position.Y);
                    Table[currEgg.X - 1, currEgg.Y].position = new Point(Table[currEgg.X, currEgg.Y].position.X, y);

                    currDir = Egg.Direction.Down;
                    return(true);
                }
                break;

            case Egg.Direction.Right:
                if (currEgg.Y + 1 < TableSize.Width)
                {
                    if (Table[currEgg.X, currEgg.Y + 1].isBrick())
                    {
                        return(false);
                    }
                    Egg tmp = Table[currEgg.X, currEgg.Y];
                    Table[currEgg.X, currEgg.Y]     = Table[currEgg.X, currEgg.Y + 1];
                    Table[currEgg.X, currEgg.Y + 1] = tmp;

                    int x = Table[currEgg.X, currEgg.Y].position.X;
                    Table[currEgg.X, currEgg.Y].position     = new Point(Table[currEgg.X, currEgg.Y + 1].position.X, Table[currEgg.X, currEgg.Y].position.Y);
                    Table[currEgg.X, currEgg.Y + 1].position = new Point(x, Table[currEgg.X, currEgg.Y].position.Y);

                    currDir = Egg.Direction.Left;
                    return(true);
                }
                break;

            case Egg.Direction.Left:
                if (currEgg.Y - 1 >= 0)
                {
                    if (Table[currEgg.X, currEgg.Y - 1].isBrick())
                    {
                        return(false);
                    }
                    Egg tmp = Table[currEgg.X, currEgg.Y];
                    Table[currEgg.X, currEgg.Y]     = Table[currEgg.X, currEgg.Y - 1];
                    Table[currEgg.X, currEgg.Y - 1] = tmp;

                    int x = Table[currEgg.X, currEgg.Y].position.X;
                    Table[currEgg.X, currEgg.Y].position     = new Point(Table[currEgg.X, currEgg.Y - 1].position.X, Table[currEgg.X, currEgg.Y].position.Y);
                    Table[currEgg.X, currEgg.Y - 1].position = new Point(x, Table[currEgg.X, currEgg.Y].position.Y);

                    currDir = Egg.Direction.Right;
                    return(true);
                }
                break;

            case Egg.Direction.Down:
                if (currEgg.X + 1 < TableSize.Height)
                {
                    if (Table[currEgg.X + 1, currEgg.Y].isBrick())
                    {
                        return(false);
                    }
                    Egg tmp = Table[currEgg.X, currEgg.Y];
                    Table[currEgg.X, currEgg.Y]     = Table[currEgg.X + 1, currEgg.Y];
                    Table[currEgg.X + 1, currEgg.Y] = tmp;

                    int y = Table[currEgg.X, currEgg.Y].position.Y;
                    Table[currEgg.X, currEgg.Y].position     = new Point(Table[currEgg.X, currEgg.Y].position.X, Table[currEgg.X + 1, currEgg.Y].position.Y);
                    Table[currEgg.X + 1, currEgg.Y].position = new Point(Table[currEgg.X, currEgg.Y].position.X, y);

                    currDir = Egg.Direction.Up;
                    return(true);
                }
                break;
            }
            return(false);
        }
Esempio n. 7
0
        /// <summary>
        /// Proverka na tabela za ponistuvanje na nekoi jajca
        /// </summary>
        /// <returns>broj na ponisteni jajca</returns>
        public int checkTable()
        {
            //objasneta vo dokumentacijata
            int        count = 0;
            List <int> col   = new List <int>();
            List <int> row   = new List <int>();

            for (int i = 0; i < TableSize.Height; i++)
            {
                Egg  lastegg = null;
                int  br      = 1;
                bool check   = false;
                for (int j = 0; j < TableSize.Width; j++)
                {
                    if (lastegg != null && Table[i, j].Equals(lastegg))
                    {
                        br++;
                        if (j == TableSize.Width - 1)
                        {
                            check = true;
                        }
                    }
                    else
                    {
                        if (br > 2)
                        {
                            count += br;
                            while (br != 0)
                            {
                                row.Add(i);
                                col.Add(j - br);
                                br--;
                            }
                        }
                        br      = 1;
                        lastegg = Table[i, j];
                    }
                }

                if (br > 2 && check)
                {
                    count += br;
                    while (br != 0)
                    {
                        row.Add(i);
                        col.Add(TableSize.Width - br);
                        br--;
                    }
                }
            }

            for (int j = 0; j < TableSize.Width; j++)
            {
                Egg  lastegg = null;
                int  br      = 1;
                bool check   = false;
                for (int i = 0; i < TableSize.Height; i++)
                {
                    if (lastegg != null && Table[i, j].Equals(lastegg))
                    {
                        br++;
                        if (i == TableSize.Height - 1)
                        {
                            check = true;
                        }
                    }
                    else
                    {
                        if (br > 2)
                        {
                            count += br;
                            while (br != 0)
                            {
                                bool predict = false;
                                for (int k = 0; k < row.Count; k++)
                                {
                                    if (row.ElementAt(k) == i - br && col.ElementAt(k) == j)
                                    {
                                        predict = true;
                                    }
                                }

                                if (predict)
                                {
                                    newEgg(i - br, j, true);
                                    row.Remove(i - br);
                                    col.Remove(j);
                                }
                                else
                                {
                                    row.Add(i - br);
                                    col.Add(j);
                                }
                                br--;
                            }
                        }
                        br      = 1;
                        lastegg = Table[i, j];
                    }
                }
                if (br > 2 && check)
                {
                    count += br;
                    while (br != 0)
                    {
                        bool predict = false;
                        for (int i = 0; i < row.Count; i++)
                        {
                            if (row.ElementAt(i) == TableSize.Height - br && col.ElementAt(i) == j)
                            {
                                predict = true;
                            }
                        }

                        if (predict)
                        {
                            newEgg(TableSize.Height - br, j, true);
                            row.Remove(TableSize.Height - br);
                            col.Remove(j);
                        }
                        else
                        {
                            row.Add(TableSize.Height - br);
                            col.Add(j);
                        }
                        br--;
                    }
                }
            }
            for (int i = 0; i < row.Count; i++)
            {
                int r = row.ElementAt(i);
                int c = col.ElementAt(i);

                if (Table[r, c] != null && Table[r, c].Bomb)
                {
                    if (r > 0)
                    {
                        Table[r - 1, c] = null;
                        count++;
                        if (c > 0)
                        {
                            Table[r - 1, c - 1] = null;
                            Table[r, c - 1]     = null;
                            count += 2;
                        }
                        if (c + 1 < TableSize.Width)
                        {
                            Table[r - 1, c + 1] = null;
                            Table[r, c + 1]     = null;
                            count += 2;
                        }
                    }

                    if (r + 1 < TableSize.Height)
                    {
                        Table[r + 1, c] = null;
                        count++;
                        if (c > 0)
                        {
                            Table[r + 1, c - 1] = null;
                            count++;
                        }
                        if (c + 1 < TableSize.Width)
                        {
                            Table[r + 1, c + 1] = null;
                            count++;
                        }
                    }
                }
                Table[row.ElementAt(i), col.ElementAt(i)] = null;
            }
            return(count);
        }