Example #1
0
    protected override void UpdateLevel()
    {
        spawnTimer--;

        if (spawnTimer <= 0)
        {
            spawnTimer = (int)(spawnTimeSecs * updatesPerSec);

            for (int i = 0; i < 1; i++)
            {
                Asteroid current = (Asteroid)CreateObject("AsteroidPF", GetRandomGameEdge(), GetRandomAngle());
                current.velocity = GetRandomVelocity(current.maxSpeed);
            }

            for (int i = 0; i < 1; i++)
            {
                LazerShooter current = (LazerShooter)CreateObject("LazerShooterPF", GetRandomGameEdge(), GetRandomAngle());
                current.velocity = GetRandomVelocity(current.maxSpeed);
            }

            for (int i = 0; i < 1; i++)
            {
                MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomGameEdge(), GetRandomAngle());
                current.velocity = GetRandomVelocity(current.maxSpeed);
            }

            for (int i = 0; i < 1; i++)
            {
                LazerEmitter current = (LazerEmitter)CreateObject("LazerEmitterPF", GetRandomGameEdge(), GetRandomAngle());
                current.velocity = GetRandomVelocity(current.maxSpeed);
            }
        }
    }
        private ACommand detonateMineProcess(DetonateMineCommand command, Battlefield.RobotAndBattlefield robotAndBattlefield)
        {
            BattlefieldRobot robot       = robotAndBattlefield.ROBOT;
            Battlefield      battlefield = robotAndBattlefield.BATTLEFIELD;
            MineLayer        mineLayer   = robot as MineLayer;

            if (mineLayer == null)
            {
                return(new ErrorCommand(robot.ROBOT_TYPE + " cannot use detonate mine command."));
            }

            Mine mine;

            if (mineLayer.MINES_BY_ID.TryGetValue(command.MINE_ID, out mine) && mineLayer.HitPoints > 0)
            {
                mineLayer.MINES_BY_ID.Remove(command.MINE_ID);
                lock (battlefield.detonatedMines) {
                    battlefield.detonatedMines.Add(mine);
                }
                return(new DetonateMineAnswerCommand(true));
            }
            else
            {
                return(new DetonateMineAnswerCommand(false));
            }
        }
        private ACommand putMineProcess(PutMineCommand command, Battlefield.RobotAndBattlefield robotAndBattlefield)
        {
            BattlefieldRobot robot = robotAndBattlefield.ROBOT;

            MineLayer mineLayer = robot as MineLayer;

            if (mineLayer == null)
            {
                return(new ErrorCommand(robot.ROBOT_TYPE + " cannot use put mine command."));
            }

            if (mineLayer.MinesNow < mineLayer.MineGun.MAX_MINES && mineLayer.HitPoints > 0)
            {
                int id = PutMineAnswerCommand.FALSE_MINE_ID + 1;
                while (mineLayer.MINES_BY_ID.ContainsKey(id))
                {
                    id++;
                }
                mineLayer.MINES_BY_ID.Add(id, new Mine(id, mineLayer.X, mineLayer.Y, mineLayer));
                return(new PutMineAnswerCommand(true, id));
            }
            else
            {
                return(new PutMineAnswerCommand(false, PutMineAnswerCommand.FALSE_MINE_ID));
            }
        }
Example #4
0
 public static Item CreateRandomItem(int level, ItemType itemType)
 {
     if (itemType == ItemType.Cannon)
     {
         return(Cannon.CreateRandomCannon(level));
     }
     else if (itemType == ItemType.EMPGenerator)
     {
         return(EMPGenerator.CreateRandomEMPGenerator(level));
     }
     else if (itemType == ItemType.Engine)
     {
         return(Engine.CreateRandomEngine(level));
     }
     else if (itemType == ItemType.Flamethrower)
     {
         return(Flamethrower.CreateRandomFlamethrower(level));
     }
     else if (itemType == ItemType.Hangar)
     {
         return(Hangar.CreateRandomHangar(level));
     }
     else if (itemType == ItemType.Harpoon)
     {
         return(Harpoon.CreateRandomHarpoon(level));
     }
     else if (itemType == ItemType.Hull)
     {
         return(Hull.CreateRandomHull(level));
     }
     else if (itemType == ItemType.Laser)
     {
         return(Laser.CreateRandomLaser(level));
     }
     else if (itemType == ItemType.LifeSupport)
     {
         return(LifeSupport.CreateRandomLifeSupport(level));
     }
     else if (itemType == ItemType.MineLayer)
     {
         return(MineLayer.CreateRandomMineLayer(level));
     }
     else if (itemType == ItemType.Reactor)
     {
         return(Reactor.CreateRandomReactor(level));
     }
     else if (itemType == ItemType.RocketLauncher)
     {
         return(RocketLauncher.CreateRandomRocketLauncher(level));
     }
     else if (itemType == ItemType.ShieldGenerator)
     {
         return(ShieldGenerator.CreateRandomShieldGenerator(level));
     }
     else
     {
         return(null);
     }
 }
Example #5
0
        private IClassEquipment buyClassEquipment(BattlefieldRobot r, int classEquipmentId)
        {
            IClassEquipment classEquipment = null;

            {
                Tank tank = r as Tank;
                if (tank != null)
                {
                    classEquipment = tank.Gun;
                    if (gunsById.TryGetValue(classEquipmentId, out Gun wantedBuy) && !wantedBuy.Equals(classEquipment))
                    {
                        if (r.Gold >= wantedBuy.COST)
                        {
                            r.Gold  -= wantedBuy.COST;
                            tank.Gun = wantedBuy;
                        }
                    }
                }
            }

            {
                MineLayer mineLayer = r as MineLayer;
                if (mineLayer != null)
                {
                    classEquipment = mineLayer.MineGun;
                    if (mineGunsById.TryGetValue(classEquipmentId, out MineGun wantedBuy) && !wantedBuy.Equals(classEquipment))
                    {
                        if (r.Gold >= wantedBuy.COST)
                        {
                            r.Gold           -= wantedBuy.COST;
                            mineLayer.MineGun = wantedBuy;
                        }
                    }
                }
            }

            {
                Repairman repairman = r as Repairman;
                if (repairman != null)
                {
                    classEquipment = repairman.RepairTool;
                    if (repairToolsById.TryGetValue(classEquipmentId, out RepairTool wantedBuy) && !wantedBuy.Equals(classEquipment))
                    {
                        if (r.Gold >= wantedBuy.COST)
                        {
                            r.Gold -= wantedBuy.COST;
                            repairman.RepairTool = wantedBuy;
                        }
                    }
                }
            }
            return(classEquipment);
        }
Example #6
0
    protected override void CreateLevel()
    {
        MusicPlay("sounds/level1Loop");

        levelSize = new Vector2(80, 60); //set the level size

        CreateObject("SpaceDustPF", gameBounds.center, 0);

        for (int i = 0; i < 4; i++)
        {
            Asteroid current = (Asteroid)CreateObject("AsteroidPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            HomingMine current = (HomingMine)CreateObject("HomingMinePF", GetRandomPosition(), GetRandomAngle());
        }

        for (int i = 0; i < 2; i++)
        {
            RandomTurner current = (RandomTurner)CreateObject("RandomTurnerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            RubberyDebris current = (RubberyDebris)CreateObject("RubberyDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            SputteringDebris current = (SputteringDebris)CreateObject("SputteringDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            IndestructableDebris current = (IndestructableDebris)CreateObject("IndestructableDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        GravityWellController well = (GravityWellController)CreateObject("GravityWellControllerPF");
    }
        protected void initRobot(BattlefieldRobot robot)
        {
            robot.Motor     = Motors[0];
            robot.Armor     = Armors[0];
            robot.HitPoints = robot.Armor.MAX_HP;

            switch (robot.ROBOT_TYPE)
            {
            case RobotType.MINE_LAYER:
                MineLayer mineLayer = robot as MineLayer;
                if (mineLayer != null)
                {
                    mineLayer.MineGun  = MineGuns[0];
                    mineLayer.MinesNow = 0;
                    mineLayer.MINES_BY_ID.Clear();
                }
                break;

            case RobotType.TANK:
                Tank tank = robot as Tank;
                if (tank != null)
                {
                    tank.Gun        = Guns[0];
                    tank.GunsToLoad = 0;
                }
                break;

            case RobotType.REPAIRMAN:
                Repairman repairman = robot as Repairman;
                if (repairman != null)
                {
                    repairman.RepairTool     = RepairTools[0];
                    repairman.RepairToolUsed = 0;
                }
                break;

            default:
                throw new NotSupportedException("Unsupported type of robot.");
            }

            Point position = obstacleManager.StartRobotPosition(ARENA_MAX_SIZE, ARENA_MAX_SIZE);

            robot.X = position.X;
            robot.Y = position.Y;
        }
Example #8
0
    protected override void CreateLevel()
    {
        MusicPlay("sounds/level1Loop");

        levelSize = new Vector2(80, 60); //set the level size

        CreateObject("SpaceDustPF", gameBounds.center, 0);

        IngameInterface.DisplayMessage("Survive for 5 minutes", 3);

        for (int i = 0; i < 2; i++)
        {
            Asteroid current = (Asteroid)CreateObject("AsteroidPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            Rammer current = (Rammer)CreateObject("RammerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            LazerShooter current = (LazerShooter)CreateObject("LazerShooterPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            SputteringDebris current = (SputteringDebris)CreateObject("SputteringDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        ChargedShots charged = (ChargedShots)CreateObject("ChargedShotPF");

        spawnTimer = (int)(spawnTimeSecs * updatesPerSec);
    }
Example #9
0
        public void PutMinesAtRandomLocation_PutsMinesIntoMineField_WhenCalled()
        {
            // Arrange
            var       random    = Substitute.For <IRandom>();
            var       mineField = Substitute.For <IMineField>();
            MineLayer sut       = CreateSut(random,
                                            mineField);

            random.Next(Arg.Any <int>(),
                        Arg.Any <int>()).Returns(0,
                                                 0,
                                                 1,
                                                 1
                                                 );

            // Act
            sut.PutMinesAtRandomLocation(2);

            // Assert
            mineField.Received().PutMineAt(0,
                                           0);
            mineField.Received().PutMineAt(1,
                                           1);
        }
Example #10
0
    protected override void UpdateLevel()
    {
        remaining = 0;

        foreach (DestructableObject item in destructables)
        {
            if (item.team <= 0)
            {
                remaining++;
            }
        }

        spawnTimer--;

        if (spawnTimer <= 0)
        {
            spawnTimer = (int)(spawnTimeSecs * updatesPerSec);

            wave++;
            switch (wave)
            {
            case 1:
                IngameInterface.DisplayMessage("Wave 1", MESSAGE_SECS);
                for (int i = 0; i < 1; i++)
                {
                    SlowTurner current = (SlowTurner)CreateObject("SlowTurnerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    LazerShooter current = (LazerShooter)CreateObject("LazerShooterPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    RandomTurner current = (RandomTurner)CreateObject("RandomTurnerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                for (int i = 0; i < 2; i++)
                {
                    Asteroid current = (Asteroid)CreateObject("AsteroidPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                for (int i = 0; i < 1; i++)
                {
                    RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    LazerEmitter current = (LazerEmitter)CreateObject("LazerEmitterPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                break;

            case 2:
                IngameInterface.DisplayMessage("Wave 2", MESSAGE_SECS);
                for (int i = 0; i < 1; i++)
                {
                    SlowTurner current = (SlowTurner)CreateObject("SlowTurnerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    LazerShooter current = (LazerShooter)CreateObject("LazerShooterPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    RandomTurner current = (RandomTurner)CreateObject("RandomTurnerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                for (int i = 0; i < 2; i++)
                {
                    Asteroid current = (Asteroid)CreateObject("AsteroidPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    HomingMine current = (HomingMine)CreateObject("HomingMinePF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                for (int i = 0; i < 1; i++)
                {
                    RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                break;

            case 3:
                IngameInterface.DisplayMessage("Wave 3", MESSAGE_SECS);
                for (int i = 0; i < 1; i++)
                {
                    MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                for (int i = 0; i < 2; i++)
                {
                    Asteroid current = (Asteroid)CreateObject("AsteroidPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                for (int i = 0; i < 1; i++)
                {
                    SlowTurner current = (SlowTurner)CreateObject("SlowTurnerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    LazerShooter current = (LazerShooter)CreateObject("LazerShooterPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                break;

            case 4:
                IngameInterface.DisplayMessage("Wave 4", MESSAGE_SECS);
                for (int i = 0; i < 1; i++)
                {
                    MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                for (int i = 0; i < 2; i++)
                {
                    Asteroid current = (Asteroid)CreateObject("AsteroidPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }

                for (int i = 0; i < 1; i++)
                {
                    SlowTurner current = (SlowTurner)CreateObject("SlowTurnerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity(current.maxSpeed);
                }
                break;

            default:
                break;
            }
        }
    }
Example #11
0
    protected override void CreateLevel()
    {
        MusicPlay("sounds/level1Loop");

        levelSize    = new Vector2(100, 80); //set the level size
        minSize      = new Vector2(10, 8);
        shrinkAmount = (levelSize - minSize) / (SHRINK_SECONDS * updatesPerSec);

        CreateObject("SpaceDustPF", gameBounds.center, 0);

        IngameInterface.DisplayMessage("Kill all enemies before space collapses!", 3);

        for (int i = 0; i < 4; i++)
        {
            HomingMine current = (HomingMine)CreateObject("HomingMinePF", GetRandomPosition(), GetRandomAngle());
        }

        for (int i = 0; i < 2; i++)
        {
            Blob current = (Blob)CreateObject("BlobPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            Rammer current = (Rammer)CreateObject("RammerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            LazerShooter current = (LazerShooter)CreateObject("LazerShooterPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 3; i++)
        {
            RandomTurner current = (RandomTurner)CreateObject("RandomTurnerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            LazerEmitter current = (LazerEmitter)CreateObject("LazerEmitterPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            IndestructableDebris current = (IndestructableDebris)CreateObject("IndestructableDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        Shield shield = (Shield)CreateObject("ShieldPF");
    }
Example #12
0
    private const int WAVE_TIME_SECS         = 60; //60 seconds between waves

    protected override void UpdateLevel()
    {
        waveTimer--;

        //determine if there are any enemies left in the level
        bool noEnemies = true;

        foreach (DestructableObject item in destructables)
        {
            if (item.team <= 0)
            {
                noEnemies = false;
                break;
            }
        }

        //if it is time for the next wave or there are not more enemies, go to the next wave
        if (waveTimer <= 0 || noEnemies)
        {
            //reset waveTimer
            waveTimer = (int)(WAVE_TIME_SECS * updatesPerSec);

            //update wave numbers
            type++;
            if (type > NUM_TYPES)
            {
                type = 1;
                round++;
            }

            //find which type of enemies to spawn, then spawn a number equal to the round
            //bascially, each type is gone through one at a time then it is started at the
            //begining again but this time, waves make one more of that type than last time
            //each type also gives the user a different item, each round the item given gets stronger
            //a message is dispayed to the user when each wave is spawned, telling them abou the wave
            switch (type)
            {
            case 1:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Suttering Debris and a "
                                               + round + " power Heal item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    SputteringDebris current = (SputteringDebris)CreateObject("SputteringDebrisPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                Heal heal = (Heal)CreateObject("HealPF");
                heal.healthPerSecGain *= round * ITEM_POWER_INCRIMENT;
                break;

            case 2:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Aseroid(s) and a "
                                               + round + " power MultiShot item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    Asteroid current = (Asteroid)CreateObject("AsteroidPF", GetRandomGameEdge(), GetRandomAngle(), 0, random.Next(100));
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                MultiShots multiShot = (MultiShots)CreateObject("MultiShotPF");
                multiShot.numberOfShots *= round * ITEM_POWER_INCRIMENT;
                break;

            case 3:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Lazer Emitters(s) and a "
                                               + round + " power Lazer Sword item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    LazerEmitter current = (LazerEmitter)CreateObject("LazerEmitterPF", GetRandomGameEdge(), GetRandomAngle(), 0, random.Next(100));
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                LazerSword sword = (LazerSword)CreateObject("LazerSwordPF");
                sword.swordLength *= round * ITEM_POWER_INCRIMENT;
                break;

            case 4:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Random Turner(s) and a "
                                               + round + " power Homing Missiles item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    RandomTurner current = (RandomTurner)CreateObject("RandomTurnerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                HomingMissiles homing = (HomingMissiles)CreateObject("HomingMissilesPF");
                homing.missileDamge *= round * ITEM_POWER_INCRIMENT;
                break;

            case 5:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Mine Layer(s) and a "
                                               + round + " power Gravity Well Controller item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                GravityWellController well = (GravityWellController)CreateObject("GravityWellControllerPF");
                well.maxGravity *= round * ITEM_POWER_INCRIMENT;
                break;

            case 6:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Rotating Lazer Sentry(s) and a "
                                               + round + " power Lazer Beam item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                LazerBeam beam = (LazerBeam)CreateObject("LazerBeamPF");
                beam.beamDamge = (beam.beamDamge - 1) * round * ITEM_POWER_INCRIMENT + 1;
                break;

            case 7:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Green Blob(s) and a "
                                               + round + " power Rapid Shots item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    GreenBlob current = (GreenBlob)CreateObject("GreenBlobPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                RapidShots rapid = (RapidShots)CreateObject("RapidShotsPF");
                rapid.shotDamage *= round * ITEM_POWER_INCRIMENT;
                break;

            case 8:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Red Blob(s) and a "
                                               + round + " power Armor item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    RedBlob current = (RedBlob)CreateObject("RedBlobPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                Armor armor = (Armor)CreateObject("ArmorPF");
                armor.armorGain *= round * ITEM_POWER_INCRIMENT;
                break;

            case 9:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Blue Blob(s) and a "
                                               + round + " power Charged Shot item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    BlueBlob current = (BlueBlob)CreateObject("BlueBlobPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                ChargedShots charged = (ChargedShots)CreateObject("ChargedShotPF");
                charged.shotMaxDamage *= round * ITEM_POWER_INCRIMENT;
                break;

            case 10:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Slow Turner(s) and a "
                                               + round + " power Homing Mines item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    SlowTurner current = (SlowTurner)CreateObject("SlowTurnerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                HomingMines mines = (HomingMines)CreateObject("HomingMinesPF");
                mines.maxMines     = (int)(round * ITEM_POWER_INCRIMENT * mines.maxMines);
                mines.layTimeSecs *= round * ITEM_POWER_INCRIMENT;
                break;

            case 11:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " Rammer(s) and a "
                                               + round + " power Accelerant item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    Rammer current = (Rammer)CreateObject("RammerPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                Accelerant accelerant = (Accelerant)CreateObject("AccelerantFP");
                accelerant.accelerationPerSecGain *= round * ITEM_POWER_INCRIMENT;
                break;

            case 12:
                IngameInterface.DisplayMessage("Wave " + (type * (round - 1) + type) + ", " + round + " LazerShooter(s) and a "
                                               + round + " power Shield item.", WAVE_MESSAGE_TIME);
                for (int i = 0; i < round; i++)
                {
                    LazerShooter current = (LazerShooter)CreateObject("LazerShooterPF", GetRandomGameEdge(), GetRandomAngle());
                    current.velocity = GetRandomVelocity((int)current.maxSpeed);
                }
                Shield shield = (Shield)CreateObject("ShieldPF");
                shield.shieldWidth *= round * ITEM_POWER_INCRIMENT / 2.0f;
                break;

            default:
                if (type > 12)
                {
                    round++;
                }
                type      = 0;
                waveTimer = 0;
                Debug.Log("Veraible 'type' has an invalid value of: " + type);
                break;
            }
        }
    }
        private ACommand initProcess(InitCommand command, Battlefield.NetworkStreamAndBattlefield networkStreamAndBattlefield)
        {
            Battlefield battlefield = networkStreamAndBattlefield.BATTLEFIELD;

            IClassEquipment classEquipment = null;

            // get teamId for this robot
            if (!battlefield.robotTeamIdByTeamName.TryGetValue(command.TEAM_NAME, out int teamId))
            {
                lock (battlefield.robotsByTeamId) {
                    lock (battlefield.robotTeamIdByTeamName) {
                        if (battlefield.robotTeamIdByTeamName.Count < battlefield.TEAMS)
                        {
                            teamId = battlefield.idForTeam++;
                            battlefield.robotsByTeamId[teamId] = new List <BattlefieldRobot>();
                            battlefield.robotTeamIdByTeamName.Add(command.TEAM_NAME, teamId);
                        }
                        else
                        {
                            return(new ErrorCommand("Too many teams."));
                        }
                    }
                }
            }
            else
            {
                lock (battlefield.robotsByTeamId) {
                    if (battlefield.robotsByTeamId[teamId].Count >= battlefield.ROBOTS_IN_TEAM)
                    {
                        return(new ErrorCommand("Too many robots in one team."));
                    }
                }
            }

            BattlefieldRobot robot;

            // create robot
            switch (command.ROBOT_TYPE)
            {
            case RobotType.MINE_LAYER:
                robot = new MineLayer(teamId, idForRobot++, networkStreamAndBattlefield.NETWORK_STREAM);
                initRobot(robot);
                classEquipment = ((MineLayer)robot).MineGun;
                break;

            case RobotType.TANK:
                robot = new Tank(teamId, idForRobot++, networkStreamAndBattlefield.NETWORK_STREAM);
                initRobot(robot);
                classEquipment = ((Tank)robot).Gun;
                break;

            case RobotType.REPAIRMAN:
                robot = new Repairman(teamId, idForRobot++, networkStreamAndBattlefield.NETWORK_STREAM);
                initRobot(robot);
                classEquipment = ((Repairman)robot).RepairTool;
                break;

            default:
                return(new ErrorCommand("Unsupported RobotType (" + command.ROBOT_TYPE + ") support only" + RobotType.MINE_LAYER + ", " + RobotType.TANK + ", " + RobotType.REPAIRMAN));
            }


            lock (battlefield.robots) {
                battlefield.robots.Add(robot);
            }
            lock (battlefield.robotsById) {
                battlefield.robotsById[robot.ID] = robot;
            }
            lock (battlefield.robotsByTeamId) {
                battlefield.robotsByTeamId[teamId].Add(robot);
            }

            lock (battlefield.robotsByStream) {
                battlefield.robotsByStream.Add(networkStreamAndBattlefield.NETWORK_STREAM, robot);
            }
            robot.NAME = command.NAME;

            lock (battlefield.battlefieldTurn) {
                battlefield.battlefieldTurn.AddRobot(new Robot(robot.ID, robot.TEAM_ID, robot.Score, robot.Gold, robot.HitPoints, robot.X, robot.Y,
                                                               robot.AngleDrive, robot.NAME));
                battlefield.turnDataModel?.Add(battlefieldTurn.ConvertToTurn(), false);
                battlefield.viewer?.StepNext();
            }

            return(battlefield.addToInitAnswerCommand(new InitAnswerCommand(battlefield.MAX_TURN, battlefield.lap, battlefield.MAX_LAP,
                                                                            robot.ID, robot.TEAM_ID, classEquipment.ID, robot.Armor.ID, robot.Motor.ID)));
        }
Example #14
0
    protected override void CreateLevel()
    {
        MusicPlay("sounds/level1Loop");

        levelSize = new Vector2(80, 60); //set the level size

        CreateObject("SpaceDustPF", gameBounds.center, 0);

        for (int i = 0; i < 8; i++)
        {
            HomingMine current = (HomingMine)CreateObject("HomingMinePF", GetRandomPosition(), GetRandomAngle());
        }

        for (int i = 0; i < 2; i++)
        {
            SlowTurner current = (SlowTurner)CreateObject("SlowTurnerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            LazerShooter current = (LazerShooter)CreateObject("LazerShooterPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            MineLayer current = (MineLayer)CreateObject("MineLayerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            LazerEmitter current = (LazerEmitter)CreateObject("LazerEmitterPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 4; i++)
        {
            IndestructableDebris current = (IndestructableDebris)CreateObject("IndestructableDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            RedBlob current = (RedBlob)CreateObject("RedBlobPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            GreenBlob current = (GreenBlob)CreateObject("GreenBlobPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            BlueBlob current = (BlueBlob)CreateObject("BlueBlobPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        Armor armor = (Armor)CreateObject("ArmorPF");
    }