示例#1
0
文件: Map.cs 项目: vygantas1998/snake
        public void addFood(int x, int y, bool isBuff, PowerUpType powerUpType, int random)
        {
            AbstractPowerUpFactory powerUpFactory = PowerUpFactoryProducer.getFactory(isBuff);
            PowerUp sizePowerUp = powerUpFactory.getPowerUp(x, y, powerUpType, random);

            PowerUps.Add(sizePowerUp);
        }
示例#2
0
    public void clickedUndoInstantBuy()
    {
        UndoPowerUp un = new UndoPowerUp();

        //List<PowerUpBase> playerPowerUps = listPowerUp1.GetActivePowerUps();
        //playerPowerUps.Add(un);
        //listPowerUp1.Init(playerPowerUps);
        listPowerUp1.Add(un);
        initializePowerUp();
    }
示例#3
0
 private void SpawnPowerUps(GameObject brick)
 {
     // caso um double aleatório seja maior que a chance de criar um powerup
     // da dificuldade atual, um powerup aleatório é gerado
     if (Util.Random.NextDouble() > Difficulty.PowerUpChance)
     {
         List <string> types = Difficulty.PowerUpTypes;
         Dictionary <string, float> duration = Difficulty.PowerUpDuration;
         string type = types[Util.Random.Next(0, types.Count)];
         PowerUps.Add(new PowerUp(type, Color.DeepPink.ToVector3(), duration[type], brick.Position, ResourceManager.GetTex(type)));
     }
 }
示例#4
0
        /// <summary>
        /// Adding / updating Powerups
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="message"></param>
        public void AddPowerUp(JObject obj, string message)
        {
            int     id = (int)obj.First;
            PowerUp pw = JsonConvert.DeserializeObject <PowerUp>(message);

            if (!PowerUps.ContainsKey(id))
            {
                PowerUps.Add(id, pw);
            }

            else
            {
                PowerUps[id] = PowerUps[id].Update(pw);
            }
        }
示例#5
0
        public void GenerateSidePanelItems()
        {
            var bitcoins = new SidePanelItem {
                Type = "Bitcoin", Value = Player.Bitcoins
            };
            var laptops = new SidePanelItem {
                Type = "Laptops", Value = Player.MaxLaptops
            };
            var laptoplength = new SidePanelItem {
                Type = "LaptopLength", Value = Player.LaptopLength
            };

            PowerUps.Add(bitcoins);
            PowerUps.Add(laptops);
            PowerUps.Add(laptoplength);
        }
示例#6
0
        /// <summary>
        /// Adds a new powerup to the player
        /// </summary>
        /// <param name="powerUp"></param>
        public void AddPowerUp(PowerUp powerUp)
        {
            if (powerUp.IsCumulative)
            {
                PowerUps.Add(powerUp);
            }
            else
            {
                ResetOrAddPowerUp(powerUp);
            }

            // Only the server can update the score, because the client receives score updates via RPC
            if (Network.isServer)
            {
                Score += 1;
            }
        }
示例#7
0
        /// <summary>
        /// Adds a new powerup to the player, or resets a powerup if exists in the list.
        /// </summary>
        /// <param name="powerUp"></param>
        private void ResetOrAddPowerUp(PowerUp powerUp)
        {
            bool contains = false;

            foreach (PowerUp p in PowerUps)
            {
                if (p == powerUp)
                {
                    p.Reset();
                    contains = true;
                    break;
                }
            }
            if (!contains)
            {
                PowerUps.Add(powerUp);
            }
        }
示例#8
0
        private bool UpdateIsFullUpgrade()
        {
            // wenn geklickt wird und es aktiv ist, wird es hinzugefügt
            // wenn das Geld alle ist, wird es entfernt, siehe "Upgrade()"

            // klick aktiviert es, wenn es eingeschaltet ist, solange Geld da ist
            var gameIsFullUpgradeActive = GameScript.Game.IsFullUpgradeActive;

            if (MouseHelper.IsMouseLeftDown && gameIsFullUpgradeActive && active)
            {
                PowerUps.Add(PowerUp.MAXIMUM);
            }
            else if (!gameIsFullUpgradeActive)
            {
                PowerUps.Remove(PowerUp.MAXIMUM);
            }

            return(PowerUps.Contains(PowerUp.MAXIMUM));
        }
示例#9
0
        public void TriggerPowerup(PowerUp powerUp)
        {
            PowerUp similarPowerup = null;

            switch (powerUp.PowerUpType)
            {
            case PowerUpType.Bigger:
            case PowerUpType.Smaller:
                similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Bigger || p.PowerUpType == PowerUpType.Smaller).FirstOrDefault();
                break;

            case PowerUpType.Longer:
            case PowerUpType.Shorter:
                similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Longer || p.PowerUpType == PowerUpType.Shorter).FirstOrDefault();
                break;

            case PowerUpType.Faster:
            case PowerUpType.Slower:
                similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Faster || p.PowerUpType == PowerUpType.Slower).FirstOrDefault();
                break;

            case PowerUpType.Stronger:
            case PowerUpType.Weaker:
                similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Stronger || p.PowerUpType == PowerUpType.Weaker).FirstOrDefault();
                break;

            case PowerUpType.Magnetize:
                similarPowerup = PowerUps.Where(p => p.PowerUpType == PowerUpType.Magnetize).FirstOrDefault();
                break;
            }

            if (similarPowerup == null)
            {
                PowerUps.Add(powerUp);
            }
            else
            {
                PowerUps.Remove(similarPowerup);
                PowerUps.Add(powerUp);
            }

            powerUp.Activate();
        }
示例#10
0
        // Randomly generates rectangles and powerUps on every level.
        // First it chooses a position for the plus powerUp, then
        // for the remaining positions randomly chooses if it will be a rectangle or powerUp or empty space.
        // High probability for a rectangle, low probability for a powerUp or empty space.
        public void GenerateObjects()
        {
            int        height        = top + objectHeight + 3;
            int        step          = 80;
            int        extraStep     = step / 5;
            int        startingPoint = left + 6;
            List <int> positions     = new List <int>();

            for (int i = 0; i < objectsToGenerate; i++)
            {
                positions.Add(i);
            }

            // plus powerUp - generate position
            int rnd = random.Next(objectsToGenerate);

            positions.Remove(rnd);
            Point plusPosition = new Point(startingPoint + rnd * step + extraStep, height);

            PowerUps.Add(powerUpFactory.GeneratePowerUp(plusPosition, "plus")); //plus powerUp

            foreach (int pos in positions)
            {
                rnd = random.Next(11);

                if (rnd < 7)
                {
                    Point point = new Point(startingPoint + pos * step, height);
                    Rectangles.Add(new Rectangle(point, rectWidth, objectHeight, Color.Blue, Level));
                }
                else if (rnd < 9)
                {
                    Point point = new Point(startingPoint + pos * step + extraStep, height);
                    PowerUps.Add(powerUpFactory.GeneratePowerUp(point, random.Next(10)));
                }
                //else -> empty position
            }
        }
示例#11
0
        // If a ball has too low vertical velocity, it generates a powerUp that moves
        // the ball in a random direction to unstuck the ball.
        public void CheckForStuckBalls()
        {
            currentTicks++;

            if (currentTicks < ticksAllowedBeforeGameIsStuck)
            {
                return;
            }

            currentTicks -= 5;

            foreach (Ball ball in Balls)
            {
                if (Math.Abs(ball.VelocityY) < minAllowedVerticalVelocity)
                {
                    Point nextBallPosition = new Point(
                        ball.Center.X + (int)ball.VelocityX - Ball.RADIUS,
                        ball.Center.Y + (int)ball.VelocityY - Ball.RADIUS);

                    PowerUps.Add(powerUpFactory.GeneratePowerUp(nextBallPosition, "randomdirection"));
                    break;
                }
            }
        }
示例#12
0
 private void AddPowerUp(PowerUp powerUp)
 {
     PowerUps.Add(powerUp);
     AddChild(powerUp, -30);
 }