Exemplo n.º 1
0
        public IEnumerator Update()
        {
            Snake.Initialize();

            Pellet.Update();

            IsOver = false;

            while (!IsOver)
            {
                var cell = Snake.GetNextCell();

                if (cell.IsActive() && Pellet.Cell != cell)
                {
                    EndGame(false);
                }
                else
                {
                    Snake.AddHead(cell);

                    if (Pellet.Cell == cell)
                    {
                        UpdatePelletScore();
                    }
                    else
                    {
                        Snake.RemoveTail();
                    }
                }

                yield return(new WaitForSeconds(TimeSkipPerFrame));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws the food pellets
        /// </summary>
        /// <param name="Canvas">Canvas object (game screen) to draw on</param>
        public void Draw(Graphics Canvas)
        {
            // Iterate over all food pellets and draw them
            Brush SnakeColor = Brushes.DarkBlue;

            foreach (FoodPellet Pellet in m_FoodPellets)
            {
                Point PartPos = Pellet.GetPosition();
                Canvas.FillEllipse(SnakeColor, new Rectangle(PartPos.X + (m_CircleRadius / 4), PartPos.Y + (m_CircleRadius / 4), m_CircleRadius / 2, m_CircleRadius / 2));
            }
        }
Exemplo n.º 3
0
        // 畫圖時間
        public void Draw(Graphics Canvas)
        {
            // 跑一遍食物然後畫畫
            Brush SnakeColor = Brushes.BlueViolet;

            foreach (FoodPellet Pellet in m_FoodPellets)
            {
                Point PartPos = Pellet.GetPosition();
                Canvas.FillEllipse(SnakeColor, new Rectangle(PartPos.X + (m_CircleRadius / 4), PartPos.Y + (m_CircleRadius / 4), m_CircleRadius / 2, m_CircleRadius / 2));
            }
        }
Exemplo n.º 4
0
        // Dibuja los puntos de comida
        public void Personalizar(Graphics Canvas)
        {
            // Dibujar los puntos
            Brush ColorDeSnake = Brushes.Crimson;

            foreach (Comida Pellet in PuntosDeComida)
            {
                Puntos PartPos = Pellet.GetPosicion();
                Canvas.FillEllipse(ColorDeSnake, new Rectangle(PartPos.X + (RadioCirculo / 4), PartPos.Y + (RadioCirculo / 4), RadioCirculo / 2, RadioCirculo / 2));
            }
        }
Exemplo n.º 5
0
        private void UpdatePelletScore()
        {
            if (Score >= MaxScore)
            {
                EndGame(true);
            }
            else
            {
                Pellet.Update();

                UpdateScoreSignal.Dispatch(++Score);
            }
        }
Exemplo n.º 6
0
        private void BindPellet(PelletConfig p, GridConfig g)
        {
            while ((p.RowInset << 1) >= g.Rows)
            {
                p.RowInset >>= 1;
            }

            while ((p.ColumnInset << 1) >= g.Columns)
            {
                p.ColumnInset >>= 1;
            }

            var pellet = new Pellet(p.Color, p.RowInset, p.ColumnInset);

            injectionBinder.Bind <IPellet> ().ToValue(pellet).ToSingleton();
        }
Exemplo n.º 7
0
        public bool IsIntersectingRectWithRed(Rectangle rect, bool RemoveFood)
        {
            foreach (FoodPelletRed Pellet in m_FoodPelletsRed)
            {
                Point PartPos = Pellet.GetPosition();

                if (rect.IntersectsWith(new Rectangle(PartPos.X, PartPos.Y, m_CircleRadius, m_CircleRadius)))
                {
                    if (RemoveFood)
                    {
                        m_FoodPelletsRed.Remove(Pellet);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Determines whether the given rectangle intersects with any existing food pellets
        /// </summary>
        /// <param name="rect">The rectangle to check for collision with food pellets</param>
        /// <param name="RemoveFood">Whether to remove the food pellets intersecting with the rectangle</param>
        /// <returns>Whether there was an intersection</returns>
        public bool IsIntersectingRect(Rectangle rect, bool RemoveFood)
        {
            foreach (FoodPellet Pellet in m_FoodPellets) // Check each food pellet
            {
                Point PartPos = Pellet.GetPosition();

                // Check rectangle intersection with food pellet
                if (rect.IntersectsWith(new Rectangle(PartPos.X, PartPos.Y, m_CircleRadius, m_CircleRadius)))
                {
                    if (RemoveFood) // Remove food pellet if RemoveFood parameter is true
                    {
                        m_FoodPellets.Remove(Pellet);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 9
0
        // 吃到食物偵測器
        public bool IsIntersectingRect(Rectangle rect, bool RemoveFood)
        {
            foreach (FoodPellet Pellet in m_FoodPellets) // 跑一遍食物陣列
            {
                Point PartPos = Pellet.GetPosition();

                // 檢查是否碰到食物
                if (rect.IntersectsWith(new Rectangle(PartPos.X, PartPos.Y, m_CircleRadius, m_CircleRadius)))
                {
                    if (RemoveFood)
                    {
                        m_FoodPellets.Remove(Pellet);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 10
0
        // Determina si el rectángulo dado cruza con cualquier punto de alimentos existentes
        public bool IsRectanguloIntersectado(Rectangle rect, bool RemoverComida)
        {
            foreach (Comida Pellet in PuntosDeComida) // Revisa cada punto de comida
            {
                Puntos PartPos = Pellet.GetPosicion();

                // Revisa intersección existente de rectángulo con puntos de comida
                if (rect.IntersectsWith(new Rectangle(PartPos.X, PartPos.Y, RadioCirculo, RadioCirculo)))
                {
                    if (RemoverComida) // Remove food pellet if RemoveFood parameter is true
                    {
                        PuntosDeComida.Remove(Pellet);
                    }
                    return(true);
                }
            }
            return(false);
        }