예제 #1
0
        private void walkAndAttackWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Random rnd = new Random();

            while (true)
            {
                direction = (DIRECTION)(rnd.Next() % 4);
                int isNeedShot = rnd.Next() % 3000;

                if (isNeedShot < 1000)
                {
                    TanksGame.ShootKeyDown(Keys.B);
                }

                switch (direction)
                {
                case DIRECTION.U:
                    BackgroundImage = Properties.Resources.light_ctank_u;

                    Point newUpLoc = new Point(Location.X, Location.Y - step);
                    if (newUpLoc.Y <= 0)
                    {
                        break;
                    }

                    Location = newUpLoc;
                    break;

                case DIRECTION.D:
                    BackgroundImage = Properties.Resources.light_ctank_d;

                    Point newDownLoc = new Point(Location.X, Location.Y + step);
                    if (newDownLoc.Y >= 600)
                    {
                        break;
                    }

                    Location = newDownLoc;
                    break;

                case DIRECTION.L:
                    BackgroundImage = Properties.Resources.light_ctank_l;

                    Point newLeftLoc = new Point(Location.X - step, Location.Y);
                    if (newLeftLoc.X <= 0)
                    {
                        break;
                    }

                    Location = newLeftLoc;
                    break;

                case DIRECTION.R:
                    BackgroundImage = Properties.Resources.light_ctank_r;

                    Point newRightLoc = new Point(Location.X + step, Location.Y);
                    if (newRightLoc.X >= 1200)
                    {
                        break;
                    }

                    Location = newRightLoc;
                    break;
                }

                Thread.Sleep(stepTimer);
            }
        }
예제 #2
0
        private void CompTanksAction_Tick(object sender, EventArgs e)
        {
            Random rnd = new Random();

            foreach (var tank in compTanks)
            {
                if (tank.IsDisposed)
                {
                    break;
                }

                tank.direction = (DIRECTION)(rnd.Next() % 4);
                int isNeedShot = rnd.Next() % 5000;

                if (isNeedShot < 2500 && isCompReadyToShoot == true)
                {
                    isCompReadyToShoot = false;
                    TanksGame.ShootKeyDown(Keys.B);
                }

                switch (tank.direction)
                {
                case DIRECTION.U:
                    tank.BackgroundImage = Properties.Resources.light_ctank_u;

                    Point newUpLoc = new Point(tank.Location.X, tank.Location.Y - compTankStep);
                    if (newUpLoc.Y <= 0)
                    {
                        break;
                    }

                    tank.Location = newUpLoc;
                    break;

                case DIRECTION.D:
                    tank.BackgroundImage = Properties.Resources.light_ctank_d;

                    Point newDownLoc = new Point(tank.Location.X, tank.Location.Y + compTankStep);
                    if (newDownLoc.Y >= 600)
                    {
                        break;
                    }

                    tank.Location = newDownLoc;
                    break;

                case DIRECTION.L:
                    tank.BackgroundImage = Properties.Resources.light_ctank_l;

                    Point newLeftLoc = new Point(tank.Location.X - compTankStep, tank.Location.Y);
                    if (newLeftLoc.X <= 0)
                    {
                        break;
                    }

                    tank.Location = newLeftLoc;
                    break;

                case DIRECTION.R:
                    tank.BackgroundImage = Properties.Resources.light_ctank_r;

                    Point newRightLoc = new Point(tank.Location.X + compTankStep, tank.Location.Y);
                    if (newRightLoc.X >= 1200)
                    {
                        break;
                    }

                    tank.Location = newRightLoc;
                    break;
                }
            }
        }