示例#1
0
        private void AddRandomCheese()
        {
            Coordenadas newCoord = null;
            bool        found    = false;

            while (!found)
            {
                int nX = 1 + Rand.Next(x_piece_count - 2);
                int nY = 1 + Rand.Next(y_piece_count - 2);

                newCoord = new Coordenadas(nX, nY);


                bool colision = false;

                int snakelength = snake_campo.Count;
                for (int index = 0; index < snakelength; index++)
                {
                    if (snake_campo[index] == newCoord)
                    {
                        colision = true;
                    }
                }

                found = !colision;
            }


            apples.Add(newCoord);
        }
示例#2
0
        public void RestoreState(Bundle icicle)
        {
            SetMode(GameMode.Paused);

            apples         = Coordenadas.ArrayToList(icicle.GetIntArray("mCheeseList"));
            mDireccion     = (Direccion)icicle.GetInt("mDireccion");
            mSig_Direccion = (Direccion)icicle.GetInt("mSig_Direccion");
            mMoveDelay     = icicle.GetInt("mMoveDelay");
            mPuntos        = icicle.GetLong("mPuntos");
            snake_campo    = Coordenadas.ArrayToList(icicle.GetIntArray("mSnakeTrail"));
        }
示例#3
0
        public Bundle SaveState()
        {
            Bundle map = new Bundle();

            map.PutIntArray("mCheeseList", Coordenadas.ListToArray(apples));
            map.PutInt("mDireccion", (int)mDireccion);
            map.PutInt("mSig_Direccion", (int)mSig_Direccion);
            map.PutInt("mMoveDelay", mMoveDelay);
            map.PutLong("mPuntos", mPuntos);
            map.PutIntArray("mSnakeTrail", Coordenadas.ListToArray(snake_campo));

            return(map);
        }
示例#4
0
        private void UpdateSnake()
        {
            bool growSnake = false;

            Coordenadas head    = snake_campo[0];
            Coordenadas newHead = new Coordenadas(1, 1);

            mDireccion = mSig_Direccion;

            switch (mDireccion)
            {
            case Direccion.Derecha:
                newHead = new Coordenadas(head.X + 1, head.Y);
                break;

            case Direccion.Izquierda:
                newHead = new Coordenadas(head.X - 1, head.Y);
                break;

            case Direccion.Arriba:
                newHead = new Coordenadas(head.X, head.Y - 1);
                break;

            case Direccion.Abajo:
                newHead = new Coordenadas(head.X, head.Y + 1);
                break;
            }


            if ((newHead.X < 1) || (newHead.Y < 1) || (newHead.X > x_piece_count - 2) ||
                (newHead.Y > y_piece_count - 2))
            {
                SetMode(GameMode.Lost);

                return;
            }


            foreach (Coordenadas snake in snake_campo)
            {
                if (snake.Equals(newHead))
                {
                    SetMode(GameMode.Lost);
                    return;
                }
            }


            foreach (Coordenadas apple in apples)
            {
                if (apple.Equals(newHead))
                {
                    apples.Remove(apple);
                    AddRandomCheese();

                    mPuntos++;

                    mMoveDelay = (int)(mMoveDelay * 0.9);


                    growSnake = true;

                    break;
                }
            }


            snake_campo.Insert(0, newHead);


            if (!growSnake)
            {
                snake_campo.RemoveAt(snake_campo.Count - 1);
            }

            int index = 0;


            foreach (Coordenadas c in snake_campo)
            {
                if (index == 0)
                {
                    SetPiece(PieceType.Verde, c.X, c.Y);
                }
                else
                {
                    SetPiece(PieceType.Rojo, c.X, c.Y);
                }

                index++;
            }
        }
示例#5
0
        private void UpdateSnake()
        {
            bool growSnake = false;

            Coordenadas head = snake_campo[0];
            Coordenadas newHead = new Coordenadas (1, 1);

            mDireccion = mSig_Direccion;

            switch (mDireccion) {
                case Direccion.Derecha:
                    newHead = new Coordenadas (head.X + 1, head.Y);
                    break;
                case Direccion.Izquierda:
                    newHead = new Coordenadas (head.X - 1, head.Y);
                    break;
                case Direccion.Arriba:
                    newHead = new Coordenadas (head.X, head.Y - 1);
                    break;
                case Direccion.Abajo:
                    newHead = new Coordenadas (head.X, head.Y + 1);
                    break;
            }

            if ((newHead.X < 1) || (newHead.Y < 1) || (newHead.X > x_piece_count - 2)
                || (newHead.Y > y_piece_count - 2)) {
                SetMode (GameMode.Lost);

                return;
            }

            foreach (Coordenadas snake in snake_campo) {
                if (snake.Equals (newHead)) {
                    SetMode (GameMode.Lost);
                    return;
                }
            }

            foreach (Coordenadas apple in apples) {
                if (apple.Equals (newHead)) {
                    apples.Remove (apple);
                    AddRandomCheese ();

                    mPuntos++;

                    mMoveDelay = (int)(mMoveDelay * 0.9);

                    growSnake = true;

                    break;
                }
            }

            snake_campo.Insert (0, newHead);

            if (!growSnake)
                snake_campo.RemoveAt (snake_campo.Count - 1);

            int index = 0;

            foreach (Coordenadas c in snake_campo) {
                if (index == 0)
                    SetPiece (PieceType.Verde, c.X, c.Y);
                else
                    SetPiece (PieceType.Rojo, c.X, c.Y);

                index++;
            }
        }
示例#6
0
        private void AddRandomCheese()
        {
            Coordenadas newCoord = null;
            bool found = false;

            while (!found) {

                int nX = 1 + Rand.Next (x_piece_count - 2);
                int nY = 1 + Rand.Next (y_piece_count - 2);

                newCoord = new Coordenadas (nX, nY);

                bool colision = false;

                int snakelength = snake_campo.Count;
                for (int index = 0; index < snakelength; index++) {
                    if (snake_campo[index] == newCoord) {
                        colision = true;
                    }
                }

                found = !colision;
            }

            apples.Add (newCoord);
        }
示例#7
0
        public override bool Equals(object obj)
        {
            Coordenadas other = (Coordenadas)obj;

            return(X == other.X && Y == other.Y);
        }