Add() public method

public Add ( vlue ) : void
return void
コード例 #1
0
        private void levelOneConfigure()
        {
            Point userSpot = new Point(500, 500);

            userTank        = new UserTank(TANK_TYPE.LIGHT, SPEED_LEVEL.HIGHT, userSpot);
            isUserTankAlive = true;
            Controls.Add(userTank);
            userTank.Show();

            Point compSpot       = new Point(500, 50);
            int   spotDifference = -200;
            int   countOfEnemies = 5;

            for (int i = 0; i < countOfEnemies; i++)
            {
                CompTank compTank = new CompTank(TANK_TYPE.LIGHT, SPEED_LEVEL.HIGHT, new Point(compSpot.X + spotDifference, compSpot.Y));
                compTanks.Add(compTank);
                Controls.Add(compTank);
                compTank.Show();

                spotDifference += 100;
            }

            userTank.Focus();
            bulletsMoveWorker.Start();
            resultGameChecker.Start();
            compTanksActionWorker.Start();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: adamfur/AtomicGraph
        static void Main(string[] args)
        {
            var list = new AtomicList <Atomic <int> > {
                2, 3
            };

            using (var scope = new AmbientAtomicScope())
            {
                list[0].Value = -1;
                list.Add(77);
                Print(list);
            }
            Print(list);
        }
コード例 #3
0
        private void CompTanksAction_Tick(object sender, EventArgs e)
        {
            foreach (var tank in compTanks)
            {
                if (tank.IsDisposed)
                {
                    break;
                }

                tank.Direction = tank.Strategy.GetNewDirection();

                if (tank.Strategy.IsNeedShoot())
                {
                    TanksReadyToShoot.Add(tank);
                }

                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 <= gameFieldLocationY)
                    {
                        tank.Location = new Point(tank.Location.X, gameFieldLocationY);
                        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 + tankHeight >= gameFieldLocationY + gameFieldHeight)
                    {
                        tank.Location = new Point(tank.Location.X, gameFieldLocationY + gameFieldHeight - tankHeight);
                        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 <= gameFieldLocationX)
                    {
                        tank.Location = new Point(gameFieldLocationX, tank.Location.Y);
                        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 >= gameFieldLocationX + gameFieldWidth)
                    {
                        tank.Location = new Point(gameFieldLocationX + gameFieldWidth - tankWidth, tank.Location.Y);
                        break;
                    }

                    tank.Location = newRightLoc;
                    break;
                }
            }

            foreach (var tank in TanksReadyToShoot)
            {
                var bullet = new Bullet(BULLET_TYPE.COMP, tank.Direction, GetBarrelLocation(tank.Location));
                bullets.Add(bullet);
                Controls.Add(bullet);
                bullet.Show();
            }

            TanksReadyToShoot.Clear();
        }
コード例 #4
0
        private void TanksGame_KeyDown(object sender, KeyEventArgs e)
        {
            Random rnd    = new Random();
            Bullet bullet = null;

            switch (e.KeyCode)
            {
            case Keys.W:
                userTank.BackgroundImage = Properties.Resources.light_utank_u;
                userTank.direction       = DIRECTION.U;

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

                userTank.Location = newUpLoc;
                break;

            case Keys.S:
                userTank.BackgroundImage = Properties.Resources.light_utank_d;
                userTank.direction       = DIRECTION.D;

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

                userTank.Location = newDownLoc;
                break;

            case Keys.A:
                userTank.BackgroundImage = Properties.Resources.light_utank_l;
                userTank.direction       = DIRECTION.L;

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

                userTank.Location = newLeftLoc;
                break;

            case Keys.D:
                userTank.BackgroundImage = Properties.Resources.light_utank_r;
                userTank.direction       = DIRECTION.R;

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

                userTank.Location = newRightLoc;
                break;

            case Keys.Space:
                if (!isReadyToShoot)
                {
                    break;
                }

                bullet = new Bullet(BULLET_TYPE.USER, userTank.direction, userTank.Location);
                bullets.Add(bullet);
                Controls.Add(bullet);
                bullet.Show();
                isReadyToShoot = false;
                gunLabel.Text  = "Gun: Reloading";
                reloadTimer.Start();
                break;

            case Keys.B:
                if (compTanks.Count() == 0)
                {
                    break;
                }

                int tankIndex = rnd.Next() % compTanks.Count();
                bullet = new Bullet(BULLET_TYPE.COMP, compTanks[tankIndex].direction, compTanks[tankIndex].Location);
                bullets.Add(bullet);
                Controls.Add(bullet);
                bullet.Show();
                isCompReadyToShoot = true;
                break;
            }
        }