private void CreateApple(int percent)
        {
            if (Apples.Count < appleCount && rnd.Next(100) <= percent)
            {
                int x     = rnd.Next(view.MapWidth - BlockSize);
                int y     = rnd.Next(view.MapHeight - BlockSize);
                var apple = new AppleViewModel(x, y, 12, 12);

                if (Player != null)
                {
                    if (Walls.Find(wall => IsCollision(wall, apple)) == null &&
                        IsCollision(Player, apple) == false)
                    {
                        Apples.Add(apple);
                    }
                }
                else
                {
                    if (Walls.Find(wall => IsCollision(wall, apple)) == null &&
                        IsCollision(reservePlayer, apple) == false)
                    {
                        Apples.Add(apple);
                    }
                }
            }
        }
Esempio n. 2
0
        private void CreateApples()
        {
            int x, y;

            while (Apples.Count < amountApples)
            {
                x = r.Next(6) * 40;
                y = r.Next(6) * 40;

                bool flag = true;

                foreach (Apple a in Apples)
                {
                    if (a.X == x && a.Y == y)
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    Apples.Add(new Apple(x, y));
                }
            }
        }
Esempio n. 3
0
        private void LoadData()
        {
            #region Apple
            Apples.Add(new Apple
            {
                Color = AppleColor.Green,
                Kind  = "Gold",
                Price = 2.56
            });

            Apples.Add(new Apple
            {
                Color = AppleColor.Green,
                Kind  = "Gold",
                Price = 3.90
            });

            Apples.Add(new Apple
            {
                Color = AppleColor.Yellow,
                Kind  = "Double Sun",
                Price = 4.56
            });
            #endregion

            #region SoldApple

            SoldApples.Add(new SoldApple
            {
                Color = AppleColor.Green,
                Kind  = "Gold",
                Price = 5.56
            });
            SoldApples.Add(new SoldApple
            {
                Color = AppleColor.Red,
                Kind  = "Gold FD",
                Price = 13.90
            });
            SoldApples.Add(new SoldApple
            {
                Color = AppleColor.Yellow,
                Kind  = "Double Sun",
                Price = 45.56
            });
            SoldApples.Add(new SoldApple
            {
                Color = AppleColor.Yellow,
                Kind  = "Double Sun",
                Price = 15.56
            });
            SoldApples.Add(new SoldApple
            {
                Color = AppleColor.Red,
                Kind  = "Double Sun",
                Price = 7.56
            });
            #endregion
        }
        public void PutOn(IGameComponent item)
        {
            if (item.Type == GameComponentType.Apple)
            {
                Apples.Add((IFoodComponent)item);
            }

            _drawableObjs.Add(item);
        }
Esempio n. 5
0
        private void AddApple(int AppleCount)
        {
            var RandomGenerator = new Random();

            for (int i = 0; i < AppleCount; i++)
            {
                int   X          = RandomGenerator.Next(FieldSize.Width - 2);
                int   Y          = RandomGenerator.Next(FieldSize.Height - 2);
                Point P          = new Point(X + 1, Y + 1);
                bool  Acceptable = true;
                foreach (LineSeg Obstacle in Obstacles)
                {
                    if (Intersect(P, Obstacle))
                    {
                        Acceptable = false;
                    }
                }
                foreach (LineSeg Body in SnakeBody)
                {
                    if (Intersect(P, Body))
                    {
                        Acceptable = false;
                    }
                }
                foreach (Point Q in Apples)
                {
                    if (Math.Abs(P.X - Q.X) <= AppleSize / 2 && Math.Abs(P.Y - Q.Y) <= AppleSize / 2)
                    {
                        Acceptable = false;
                    }
                }
                if (Acceptable)
                {
                    Apples.Add(P);
                }
                else
                {
                    i--;
                }
            }
        }
Esempio n. 6
0
        private void CreateApples()
        {
            int _x;
            int _y;

            while (Apples.Count < _applesAmount)
            {
                _x = random.Next(_fieldWidth - 20);
                _y = random.Next(_fieldHeight - 20);

                bool flag = false;

                foreach (var a in Walls)
                {
                    if (AllCollision.BoxCollides(_x, _y, 15, 15, a.XLeft, a.YUp, a.XRight - a.XLeft, a.YDown - a.YUp))
                    {
                        flag = true;
                        break;
                    }
                }

                foreach (var a in Apples)
                {
                    if (AllCollision.BoxCollides(_x, _y, 15, 15, a.X, a.Y, 20, 20))
                    {
                        flag = true;
                        break;
                    }
                }

                if (flag == false)
                {
                    Apples.Add(new Apple(_x, _y));
                }
            }
        }
        public void RespOfApples()
        {
            while (Apples.Count < applesCount)
            {
                Apples.Add(new Apple());
                foreach (var item in Obstacles)
                {
                    if (Apples.Last().Collide(item))
                    {
                        Apples.RemoveAt(Apples.Count - 1);
                        break;
                    }
                }

                for (int i = 0; i < Apples.Count; i++)
                {
                    if (Apples.Last().Collide(Apples[i]) && Apples.Last() != Apples[i])
                    {
                        Apples.RemoveAt(Apples.Count - 1);
                        break;
                    }
                }
            }
        }
Esempio n. 8
0
        public void SpawnApples()
        {
            while (Apples.Count < applesCount)
            {
                Apples.Add(new Apple());
                foreach (var item in Walls)
                {
                    if (Apples.Last().CollidesWith(item))
                    {
                        Apples.RemoveAt(Apples.Count - 1);
                        break;
                    }
                }

                for (int i = 0; i < Apples.Count; i++)
                {
                    if (Apples.Last().CollidesWith(Apples[i]) && Apples.Last() != Apples[i])
                    {
                        Apples.RemoveAt(Apples.Count - 1);
                        break;
                    }
                }
            }
        }
Esempio n. 9
0
        public void ResetLevel()
        {
            TilesSolid.Clear();
            TilesOneWayPlatform.Clear();
            TilesSpike.Clear();
            Apples.Clear();
            Grounders.Clear();
            Flyer.Clear();
            windRs.Clear();
            Sneakers.Clear();
            SneakerTimers.Clear();

            if (windDir != Direction.None)
            {
                PreLoadWind(random);
            }

            for (var j = 0; j < LEVEL_HEIGHT; j++)
            {
                for (var i = 0; i < LEVEL_WIDTH; i++)
                {
                    switch (tilemap[i, j])
                    {
                    case Tile.Player:
                        InitializePlayer(i * 16, j * 16);
                        break;

                    case Tile.Goal:
                        goal = new Hitbox(i * 16, j * 16, 16, 16);
                        break;

                    case Tile.Wall:
                        TilesSolid.Add(new Hitbox(i * 16, j * 16, 16, 16));
                        break;

                    case Tile.NoGrapple:
                        TilesSolid.Add(new Hitbox(i * 16, j * 16, 16, 16));
                        break;

                    case Tile.OneWayPlatform:
                        TilesOneWayPlatform.Add(new Hitbox(i * 16, j * 16, 16, 16));
                        break;

                    case Tile.Spike:
                        TilesSpike.Add(new Hitbox(i * 16, j * 16 + 8, 16, 8));
                        break;

                    case Tile.Apple:
                        Apples.Add(new Hitbox(i * 16 + 2, j * 16 + 2, 12, 12));
                        break;

                    case Tile.Grounder:
                        Grounders.Add(new Mobile(i * 16, j * 16, GROUNDER_SPEED, 0, 16, 16));
                        break;

                    case Tile.Flyer:
                        Flyer.Add(new Mobile(i * 16, j * 16, FLYER_SPEED, 0, 16, 16));
                        break;

                    case Tile.Sneaker:
                        Sneakers.Add(new Hitbox(i * 16, j * 16, 16, 16));
                        SneakerTimers.Add(-1);
                        break;
                    }
                }
            }
        }