Ejemplo n.º 1
0
        private void genBigBait(int res)
        {
            int blankSize = bigBlank.Count;
            int bx        = bigBlank[res][0];
            int by        = bigBlank[res][1];

            if (matrix[by, bx] == 2)
            {
                int loop = 0;
                foreach (int[] coord in bigBlank)
                {
                    loop++;
                    if (matrix[coord[1], coord[0]] == 0 && matrix[coord[1], coord[0] + 1] == 0)
                    {
                        bx = coord[0];
                        by = coord[1];
                        break;
                    }
                }
                if (loop == blankSize)
                {
                    return;
                }
            }
            matrix[by, bx]     = 3;
            matrix[by, bx + 1] = 3;
            big = new BigFood(bx, by);
        }
Ejemplo n.º 2
0
        public int work()
        {
            baitsWork();
            if (timeToSnakeGrow == 0)
            {
                matrix[sn.ly, sn.lx] = 0;
            }
            else
            {
                timeToSnakeGrow--;
            }

            sn.work();
            if (isSnakeDie())
            {
                GameOver = true;
                return(SNAKE_DIE);
            }
            matrix[sn.fy, sn.fx] = 2;

            int flag1 = smallBaitState(sn.fx, sn.fy);

            if (flag1 == SMALL_IS_EATED)
            {
                sn.grow(SmallFood.WORTH);
                small = null;
                genBaits();
                return(SmallFood.WORTH);
            }
            int flag2 = bigBaitState(sn.fx, sn.fy);

            if (flag2 == BIG_IS_EATED_LEFT)
            {
                removePartOfBigBait(big.X + 1, big.Y, big.X, big.Y);
                sn.grow(BigFood.WORTH);
                bigTime = 0;
                big     = null;
                return(BigFood.SCRORE);
            }
            if (flag2 == BIG_IS_EATED_RIGHT)
            {
                removePartOfBigBait(big.X, big.Y, big.X + 1, big.Y);
                sn.grow(BigFood.WORTH);
                bigTime = 0;
                big     = null;
                return(BigFood.SCRORE);
            }
            if (flag1 == SMALL_NO_EXIST && flag2 == BIG_NO_EXIST)
            {
                return(NO_BAIT);
            }
            else
            {
                return(NORMAL);
            }
        }
Ejemplo n.º 3
0
        public void reset()
        {
            List <int[]> part = sn.getPart();
            int          size = part.Count;

            for (int i = 1; i < size; i++)
            {
                matrix[part[i][1], part[i][0]] = 0;
            }
            sn              = null;
            small           = null;
            big             = null;
            timeToSnakeGrow = 0;
            count           = 0;
            bigTime         = 0;
            GameOver        = false;
        }
Ejemplo n.º 4
0
        private void genBaits()
        {
            count++;
            Random r = new Random();

            if (count == 7)
            {
                count   = 0;
                bigTime = bigTimeLimit;
                if (big != null)
                {
                    removeBigBait(big.X, big.Y);
                    big = null;
                }
                genBigBait(r.Next(0, bigBlank.Count()));
            }
            genSmallBait(r.Next(0, blank.Count()));
        }
Ejemplo n.º 5
0
 private void baitsWork()
 {
     if (big != null)
     {
         if (bigTime == 0)
         {
             removeBigBait(big.X, big.Y);
             big = null;
         }
         else
         {
             big.work();
         }
         bigTime--;
     }
     if (small != null)
     {
         small.work();
     }
 }