Exemple #1
0
        public Form2(string p1, string p2, string mf)
        {
            // Load data from previous form
            InitializeComponent();
            player1Name = p1;
            player2Name = p2;
            mapFile     = mf;

            // Load MapFile data
            Size = new System.Drawing.Size(800, 600);
            MapFile file = new MapFile(Application.StartupPath + "\\" + mapFile);

            file.loadData();

            // Load tanks for MapFile
            tank1 = (Tank)file.Tanks[0];
            tank2 = (Tank)file.Tanks[1];

            // Create tanks --------------------------------------------------------------------------------

            // Set locations of tanks
            Point point1 = new Point(tank1.Horizontal, tank1.Vertical);

            greentank.Location = point1;
            Point point2 = new Point(tank2.Horizontal, tank2.Vertical);

            redtank.Location = point2;

            // Set sizes of tanks
            greentank.Size      = new System.Drawing.Size(60, 60);
            greentank.BackColor = Color.Transparent;
            redtank.Size        = new System.Drawing.Size(60, 60);

            // Set image of greentank
            switch (tank1.Direction)
            {
            case 0:
                greentank.Image = greenimage0;
                break;

            case 1:
                greentank.Image = greenimage1;
                break;

            case 2:
                greentank.Image = greenimage2;
                break;

            case 3:
                greentank.Image = greenimage3;
                break;
            }

            // Set image of redtank
            switch (tank2.Direction)
            {
            case 0:
                redtank.Image = redimage0;
                break;

            case 1:
                redtank.Image = redimage1;
                break;

            case 2:
                redtank.Image = redimage2;
                break;

            case 3:
                redtank.Image = redimage3;
                break;
            }

            // Add tanks to form
            this.Controls.Add(greentank);
            this.Refresh();
            this.Controls.Add(redtank);
            this.Refresh();

            // Create bullets ------------------------------------------------------------------------------

            // Set locations of bullets
            Point point3 = new Point(-100, -100);

            bullet1.Location = point3;
            bullet2.Location = point3;

            // Set sizes of bullets
            bullet1.Size = new System.Drawing.Size(30, 30);
            bullet2.Size = new System.Drawing.Size(30, 30);

            // Set image of bullets
            bullet1.Image = bulletimage;
            bullet2.Image = bulletimage;

            // Add bullets to form
            this.Controls.Add(bullet1);
            this.Refresh();
            this.Controls.Add(bullet2);
            this.Refresh();

            // Create walls --------------------------------------------------------------------------------
            walls[0] = wall1;
            walls[1] = wall2;
            walls[2] = wall3;
            walls[3] = wall4;
            walls[4] = wall5;

            // Set wall attributes and load to form

            /*for(int i = 0; i < 5; i++)
             * {
             *  Wall newWall = (Wall)file.Walls[i];
             *  Point point4 = new Point(newWall.Horizontal, newWall.Vertical);
             *  walls[i].Location = point4;
             *  walls[i].Size = new System.Drawing.Size(60,60);
             *  walls[i].Image = wallimage;
             *  this.Controls.Add(walls[i]);
             *  this.Refresh();
             * }
             */
            timer1.Start();
            this.Select();
        }
        public Form2(string playerOne, string playerTwo, string mapFile)
        {
            // Load data from previous form
            this.InitializeComponent();
            this.playerOneName = playerOne;
            this.playerTwoName = playerTwo;
            this.mapFile = mapFile;

            // Load MapMapFile data
            this.Size = new System.Drawing.Size(800, 600);
            MapFile file = new MapFile("C:\\Users\\Frankie\\Documents\\C#\\TankGame\\" + this.mapFile);
            file.LoadData();

            // Load tanks for MapMapFile
            this.tank1 = (Tank)file.Tanks[0];
            this.tank2 = (Tank)file.Tanks[1];

            // Create tanks --------------------------------------------------------------------------------

            // Set locations of tanks
            Point point1 = new Point(this.tank1.Horizontal, this.tank1.Vertical);
            this.greentank.Location = point1;
            Point point2 = new Point(this.tank2.Horizontal, this.tank2.Vertical);
            this.redtank.Location = point2;

            // Set sizes of tanks
            this.greentank.Size = new System.Drawing.Size(60, 60);
            this.redtank.Size = new System.Drawing.Size(60, 60);

            // Set image of greentank
            switch (this.tank1.Direction)
            {
                case 0:
                    this.greentank.Image = this.greenimage0;
                    break;
                case 1:
                    this.greentank.Image = this.greenimage1;
                    break;
                case 2:
                    this.greentank.Image = this.greenimage2;
                    break;
                case 3:
                    this.greentank.Image = this.greenimage3;
                    break;
            }

            // Set image of redtank
            switch (this.tank2.Direction)
            {
                case 0:
                    this.redtank.Image = this.redimage0;
                    break;
                case 1:
                    this.redtank.Image = this.redimage1;
                    break;
                case 2:
                    this.redtank.Image = this.redimage2;
                    break;
                case 3:
                    this.redtank.Image = this.redimage3;
                    break;
            }

            // Add tanks to form
            this.Controls.Add(this.greentank);
            this.Refresh();
            this.Controls.Add(this.redtank);
            this.Refresh();

            // Create bullets ------------------------------------------------------------------------------

            // Set locations of bullets
            Point point3 = new Point(-100, -100);
            this.bullet1.Location = point3;
            this.bullet2.Location = point3;

            // Set sizes of bullets
            this.bullet1.Size = new System.Drawing.Size(30, 30);
            this.bullet2.Size = new System.Drawing.Size(30, 30);

            // Set image of bullets
            this.bullet1.Image = this.bulletimage;
            this.bullet2.Image = this.bulletimage;

            // Add bullets to form
            this.Controls.Add(this.bullet1);
            this.Refresh();
            this.Controls.Add(this.bullet2);
            this.Refresh();

            // Create walls --------------------------------------------------------------------------------
            this.walls[0] = this.wall1;
            this.walls[1] = this.wall2;
            this.walls[2] = this.wall3;
            this.walls[3] = this.wall4;
            this.walls[4] = this.wall5;

            // Set wall attributes and load to form
            for (int i = 0; i < 5; i++)
            {
                Wall newWall = (Wall)file.Walls[i];
                Point point4 = new Point(newWall.Horizontal, newWall.Vertical);
                this.walls[i].Location = point4;
                this.walls[i].Size = new System.Drawing.Size(60,60);
                this.walls[i].Image = this.wallimage;
                this.Controls.Add(this.walls[i]);
                this.Refresh();
            }

            this.timer1.Start();
            this.Select();
        }