예제 #1
0
        public static void DirectionControl(MovableFigure gameObject, GameTime gameTime)
        {
            gameObject.TimeMove += gameTime.LoopTime;

            if (gameObject.TimeMove > 90)
            {
                if (KeyBoard.getState().IsKeyDown(Keys.LEFT))
                {
                    gameObject.Move(Direction.Left);
                    Console.Beep(32000, 1);
                    gameObject.TimeMove = 0;
                }
                else if (KeyBoard.getState().IsKeyDown(Keys.RIGHT))
                {
                    gameObject.Move(Direction.Right);
                    Console.Beep(32000, 1);
                    gameObject.TimeMove = 0;
                }
                else if (KeyBoard.getState().IsKeyDown(Keys.UP))
                {
                    gameObject.Move(Direction.Top);
                    Console.Beep(32000, 1);
                    gameObject.TimeMove = 0;
                }
                else if (KeyBoard.getState().IsKeyDown(Keys.DOWN))
                {
                    gameObject.Move(Direction.Bottom);
                    Console.Beep(32000, 1);
                    gameObject.TimeMove = 0;
                }
            }
        }
예제 #2
0
        protected void Update(GameTime gameTime)
        {
            timeCreateBot    += gameTime.LoopTime;
            timeBotTankShoot += gameTime.LoopTime;
            tank.TimeStep    += gameTime.LoopTime;

            if (CountKilled >= 10 && level == 1)
            {
                tank.LoadNewModel("-x-|-x-|1*1|1-1");
                level = 2;
            }
            else if (CountKilled >= 20 && level == 2)
            {
                tank.LoadNewModel("--x--|--x--|11*11|11111|11-11");
                level = 3;
            }
            else if (CountKilled >= 30 && level == 3)
            {
                tank.LoadNewModel("--x--|--1--|-x1x-|11*11|11111|11-11");
                level = 4;
            }
            else if (CountKilled >= 40 && level == 4)
            {
                tank.LoadNewModel("x---x|-1-1-|--*--|--1-x|---1-");
                tank.IsOriginGun = true;
                level            = 5;
            }
            else if (CountKilled >= 50 && level == 5)
            {
                tank.LoadNewModel("x---x|1---1|-1-1-|--*--|--1-x|---1-");
                tank.IsOriginGun = true;
                level            = 6;
            }

            tank.Update(gameTime);

            foreach (Tank t in bots)
            {
                t.Update(gameTime);
            }

            if (KeyBoard.getState().IsKeyDown(Keys.LCONTROL) || KeyBoard.getState().IsKeyDown(Keys.SPACE))
            {
                if (tank.TimeStep >= 600)
                {
                    tank.Shoot(tank.CurrentDirection);
                    CountShoot++;
                    bulletsLayout.RemoveAllFigures();

                    for (int i = 0; i < tank.getBullets().Length; i++)
                    {
                        Bullet b = tank.getBullets()[i];
                        if (!b.NotAlive())
                        {
                            bulletsLayout.AddFigure(b);
                        }
                    }
                    Console.Beep(5000, 20);

                    tank.TimeStep = 0;
                }
            }

            Bullet[] bullets = tank.getBullets();
            for (int j = 0; j < bullets.Length; j++)
            {
                for (int i = 0; i < bots.Count; i++)
                {
                    Bullet b = bullets[j];
                    Tank   t = bots[i];

                    if (t.HasPoint(b.X, b.Y))
                    {
                        if (t.Strike())
                        {
                            mainLayout.Remove(t);
                            bots.Remove(t);
                            i--;
                            CountKilled++;
                            Console.Beep(1000, 5);
                        }
                        else
                        {
                            Console.Beep(3000, 5);
                        }
                        bulletsLayout.Remove(b);
                        tank.RemoveBullet(b);
                    }
                }
            }

            /*if (KeyBoard.getState().IsKeyDown(Keys.SPACE)) {
             *  foreach (Tank t in bots)
             *      t.DettachControl();
             * }*/

            /*if (timeBotTankShoot > 5000) {
             *  foreach (Tank t in bots) {
             *      t.Shoot(t.CurrentDirection);
             *      foreach (Bullet b in t.getBullets()) {
             *          bulletsLayout.AddFigure(b);
             *      }
             *  }
             *  timeBotTankShoot = 0;
             * }*/

            if (timeCreateBot > 2000 && bots.Count < maxCountBot)
            {
                Tank newTank = new Tank(r.Next(25, 70), r.Next(3, 20), "-x-|1*1|1-1", true);
                newTank.AttachControl(Control.BotControl);
                //newTank.Color = r.Next(0, 2) == 1 ? ConsoleColor.Red : ConsoleColor.Yellow;
                mainLayout.AddFigure(newTank);
                bots.Add(newTank);
                timeCreateBot = 0;
            }
        }