Exemplo n.º 1
0
            private void SetupTank(string info, Tank tnk)
            {
                //Splits the line into three paraemeters - x position, y position, facnig
                string[] splitter = info.Split(',');

                //Double check that there are enough parameters
                if (splitter.Length == 3)
                {
                    int pX;
                    int pY;
                    int face;
                    //attempts to parse the parameters
                    Boolean testF = int.TryParse(splitter[0], out pX);
                    Boolean testX = int.TryParse(splitter[1], out pY);
                    Boolean testY = int.TryParse(splitter[2], out face);
                    try
                    {
                        //assigns the parameters

                        tnk.rec.Location = new System.Drawing.Point (pX, pY);
                        tnk.Facing = face;
                    }
                    //Error catching
                    catch (System.ArgumentOutOfRangeException argRange)
                    {
                        MessageBox.Show("Please confine map.txt values to the window size (80 wide, 30 tall): " + argRange.Message);
                    }
                    catch (IOException ioe)
                    {
                        MessageBox.Show("IOException, please check map.txt formatting: " + ioe.Message);
                    }
                    catch (IndexOutOfRangeException indRange)
                    {
                        MessageBox.Show("Index out of range exception, double check map.txt formatting (lines 1 and 2 have 3 values, all other lines have 2 values: " + indRange.Message);
                    }
                    //For everything else, there's mastercard
                    catch (Exception generic)
                    {
                        MessageBox.Show("Exception: " + generic.Message);
                    }
                }
            }
Exemplo n.º 2
0
        //Basic constructor, simply places the walls, tanks and bullets on the "board"
        public GameForm(InfoForm i, string p1, string p2, string map)
        {
            info = i;
            player1Name = p1;
            player2Name = p2;
            mapText = map;
            InitializeComponent();

                //Any posX and posY values set here are just placeholder values before the map.txt is read
                //Walls are in the walle list because there can be any number of walls 
                walle = new List<Wall>();
                playerOne = new Player(player1Name, 1);
                playerTwo = new Player(player2Name, 2);

                //sets bullets, but starts them inactive to avoid instant death
                bullOne = new Bullet(1, 5, 5);
                bullOne.Active = false;
                bullTwo = new Bullet(1, 10, 10);
                bullTwo.Active = false;

                //sets tanks, with an assigned player and bullet
                //The placement is default if the map.txt file has no values
                tankOne = new Tank(playerOne, bullOne, 1, 10, 20, 1);
                tankTwo = new Tank(playerTwo, bullTwo, 3, 20, 20, 2);

                //Reads the map file in bin/debug
                ReadMap(mapText);  //this can be changed, and should be the map file.
                DrawGame();
                //The under-the-hood properties
                gameOver = false;
                //Console.CursorVisible = false;  //avoids a blinking cursor
                //sets window properties.  Uses default BufferWidth to avoid an error
                this.Width = GameVariables.GameWidth;
                this.Height = GameVariables.GameHeight;
                GameVariables.InnerHeight = this.ClientSize.Height;
                GameVariables.InnerWidth = this.ClientSize.Width;

                //Adds each piece of the game to the form's Controls directory
                this.Controls.Add(tankOne.PicBox);
                this.Controls.Add(tankTwo.PicBox);
                this.Controls.Add(bullOne.PicBox);
                this.Controls.Add(bullTwo.PicBox);
                foreach(Wall w in walle)
                {
                    this.Controls.Add(w.PicBox);
                }
                gameTimer.Start();
                //GameLoop();
            }