Esempio n. 1
0
        /// <summary>
        /// moves the tank to fall down one tile is possible
        /// </summary>
        /// <returns>true if tank has fallen one tile down , otherwise false</returns>
        public bool ProcessGravity()
        {
            bool        tankMoved;
            Battlefield currentFight;
            int         fallingDamage = 1;

            // check to see if tank is still alive
            if (!TankExists())
            {
                // if destroyed
                tankMoved = false;
                return(tankMoved);
            }
            else
            {
                //find current battefield
                currentFight = tankInGame.GetLevel();
                //test location below tank for terrain
                if (currentFight.TankFits(tankPosX, tankPosY + 1))
                {
                    // if terrain is found then tank doesnt move
                    tankMoved = false;
                    return(tankMoved);
                }
                else
                {
                    //tank falls and takes damage
                    tankPosY++;
                    DamagePlayer(fallingDamage);
                    //check to see if tank has fallen to the bottom of map
                    if (tankPosY >= (Battlefield.HEIGHT - TankModel.HEIGHT))
                    {
                        //destroy tank as it has fallen off the map
                        tankDurbility = -1;
                    }
                    // tank has moved so change bool and return
                    tankMoved = true;
                    return(tankMoved);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// draws the terrain of the battle in its current state.
        /// </summary>
        private void DrawBackground()
        {
            //set variables needed to draw terrain
            Graphics graphics   = backgroundGraphics.Graphics;
            Image    background = backgroundImage;

            graphics.DrawImage(backgroundImage, new Rectangle(0, 0, displayPanel.Width, displayPanel.Height));
            Random      myRandom    = new Random();
            Battlefield battlefield = currentGame.GetLevel();
            //create a brush for the color of terrain
            Brush brush = new SolidBrush(Color.WhiteSmoke);
            int   random; // stores randomize colour choice

            //test for terrain inside the battle
            for (int y = 0; y < Battlefield.HEIGHT; y++)
            {
                // go along each row looking for giving each block a colour
                for (int x = 0; x < Battlefield.WIDTH; x++)
                {
                    //top of the terrain should be white for skyscrappers
                    if (y <= 10)
                    {
                        brush = new SolidBrush(Color.WhiteSmoke);
                    }
                    //following the skyscrappers tops , their should be lights and other colour to represent window glare
                    if (Battlefield.HEIGHT / 3.6 > y && y > 10)
                    {
                        random = myRandom.Next(0, 16);
                        switch (random)
                        {
                        default:
                            brush = new SolidBrush(Color.Silver);
                            break;

                        case (1):
                            brush = new SolidBrush(Color.SlateGray);
                            break;

                        case (2):
                            brush = new SolidBrush(Color.LightYellow);
                            break;
                        }
                    }
                    //following the body of a building their should be a green landing to be the base of a building
                    if (y >= Battlefield.HEIGHT / 3.6 && y < Battlefield.HEIGHT / 3.3)
                    {
                        random = myRandom.Next(0, 15);
                        switch (random)
                        {
                        default:
                            brush = new SolidBrush(Color.ForestGreen);
                            break;

                        case (1):
                            brush = new SolidBrush(Color.Silver);
                            break;

                        case (2):
                            brush = new SolidBrush(Color.SaddleBrown);
                            break;
                        }
                    }
                    // now the terrain in below ground level , shows diffferent mineral desposits and roots growing underground
                    if (y > Battlefield.HEIGHT / 3.3 && Battlefield.HEIGHT / 2 > y)
                    {
                        random = myRandom.Next(0, 25);
                        switch (random)
                        {
                        default:
                            brush = new SolidBrush(Color.SaddleBrown);
                            break;

                        case (1):
                            brush = new SolidBrush(Color.LightGray);
                            break;

                        case (2):
                            brush = new SolidBrush(Color.SlateGray);
                            break;

                        case (3):
                            brush = new SolidBrush(Color.DarkSlateGray);
                            break;

                        case (4):
                            brush = new SolidBrush(Color.ForestGreen);
                            break;
                        }
                    }

                    // this terrain is deep in the ground and should be only ground and hard desposits
                    if (Battlefield.HEIGHT / 2 <= y && y < Battlefield.HEIGHT * .80)
                    {
                        random = myRandom.Next(1, 25);
                        switch (random)
                        {
                        default:
                            brush = new SolidBrush(Color.SaddleBrown);
                            break;

                        case (2):
                            brush = new SolidBrush(Color.DarkSlateGray);
                            break;

                        case (3):
                            brush = new SolidBrush(Color.SlateGray);
                            break;
                        }
                    }
                    // terrain is nearing the bottom of the map and black should be introduced
                    if (y >= Battlefield.HEIGHT * .80 && y < Battlefield.HEIGHT * .91)
                    {
                        random = myRandom.Next(1, 5);
                        switch (random)
                        {
                        default:
                            brush = new SolidBrush(Color.DarkSlateGray);
                            break;

                        case (2):
                            brush = new SolidBrush(Color.SaddleBrown);
                            break;

                        case (1):
                            brush = new SolidBrush(Color.SaddleBrown);
                            break;

                        case (3):
                            brush = new SolidBrush(Color.Black);
                            break;
                        }
                    }
                    // at the bottom of the map , should only be blackness and a bit of hard desposits
                    if (y >= Battlefield.HEIGHT * .91)
                    {
                        random = myRandom.Next(1, 10);
                        switch (random)
                        {
                        default:
                            brush = new SolidBrush(Color.Black);
                            break;

                        //case (1):
                        //    brush = new SolidBrush(Color.SaddleBrown);
                        //    break;
                        case (3):
                            brush = new SolidBrush(Color.DarkSlateGray);
                            break;
                        }
                    }
                    // draw the block to the graphics to be rendered on the screen
                    if (battlefield.Get(x, y))
                    {
                        // find the points of the block scaled to the displayPanel size
                        int drawX1 = displayPanel.Width * x / Battlefield.WIDTH;
                        int drawY1 = displayPanel.Height * y / Battlefield.HEIGHT;
                        int drawX2 = displayPanel.Width * (x + 1) / Battlefield.WIDTH;
                        int drawY2 = displayPanel.Height * (y + 1) / Battlefield.HEIGHT;
                        //draw block
                        graphics.FillRectangle(brush, drawX1, drawY1, drawX2 - drawX1, drawY2 - drawY1);
                    }
                }
            }
        }