Exemplo n.º 1
0
        public event EventHandler FullOfFuelEvent;          // can just use EventHandler

        // Constructor
        public Ship(int shipSize, Rectangle boundsRectangle, Graphics shipCanvas, Random rGen)
        {
            this.shipSize        = shipSize;
            this.boundsRectangle = boundsRectangle;
            this.shipCanvas      = shipCanvas;

            shipColor = Color.Red;              // could perhaps change this to be passed in -- leave for now

            int velX = rGen.Next(MAX_VELOCITY); // randomly generate our velocity
            int velY = rGen.Next(MAX_VELOCITY);

            shipVelocity = new Point(velX, velY);

            petrol = rGen.Next(MAX_PETROL);    // randomly generate petrol

            // We will randomly generate the ship's starting location

            int x = rGen.Next(boundsRectangle.Width - shipSize);    // x needs to be within the width of our bounds rectangle
            int y = rGen.Next(boundsRectangle.Height - shipSize);   // and y needs to be within the height of it. We will

            // then minus shipSize so that it cannot overlap bounds
            // Then, we generate a point based on our two random numbers
            shipLocation   = new Point(x, y);
            petrolBotState = EPetrolBotState.docked;
        }
Exemplo n.º 2
0
        private void refuel()
        {
            OnOutOfFuelEvent(shipLocation);
            if (petrolBotState == EPetrolBotState.refuelling)
            {
                petrolBot.botCurrentLocation = shipLocation;
                if (petrol < 300)
                {
                    shipState = EShipState.refueling;

                    //shipVelocity = new Point(0, 0);

                    petrol += 10;
                }
                else // we have finished refueling
                {
                    //shipVelocity = oldVelocity;
                    shipState      = EShipState.wandering;
                    petrolBotState = EPetrolBotState.docked;
                    OnFullOfFuelEvent();
                }
            }
            else
            {
                checkIfPetrolBotHasArrived();
            }
        }
Exemplo n.º 3
0
        private void checkIfPetrolBotHasArrived()
        {
            Rectangle rect        = new Rectangle(shipLocation.X, shipLocation.Y, shipSize, shipSize);
            bool      doesContain = rect.Contains(petrolBot.botCurrentLocation);

            if (doesContain)
            {
                petrolBotState = EPetrolBotState.refuelling;
            }
            //else
            //petrolBot.
            //if (petrolBot.botCurrentLocation)
        }
Exemplo n.º 4
0
        // Constructor
        public PetrolBot(Ship botsShip, Graphics botsCanvas, int xPos, Random rGen)
        {
            this.botsShip = botsShip;
            this.botsCanvas = botsCanvas;
            shipLocation = botsShip.ShipLocation;
            botState = EPetrolBotState.docked;
            xPos = xPos * 30;
            botStartingLocation = new Point(xPos, 520);
            botCurrentLocation = botStartingLocation;

            int r = rGen.Next(255);
            int g = rGen.Next(255);
            int b = rGen.Next(255);
            botColor = Color.FromArgb(r, g, b);

            Ship.OutOfFuelEventHandler outOfFuelHandler = new Ship.OutOfFuelEventHandler(OutOfFuelEventHandler);
            this.botsShip.OutOfFuelEvent += outOfFuelHandler;

            EventHandler fullOfFuelHandler = new EventHandler(FullOfFuelEventHandler);
            this.botsShip.FullOfFuelEvent += fullOfFuelHandler;
        }
Exemplo n.º 5
0
        // Constructor
        public Ship(int shipSize, Rectangle boundsRectangle, Graphics shipCanvas, Random rGen)
        {
            this.shipSize = shipSize;
            this.boundsRectangle = boundsRectangle;
            this.shipCanvas = shipCanvas;

            shipColor = Color.Red;  // could perhaps change this to be passed in -- leave for now

            int velX = rGen.Next(MAX_VELOCITY);     // randomly generate our velocity
            int velY = rGen.Next(MAX_VELOCITY);
            shipVelocity = new Point(velX,velY);

            petrol = rGen.Next(MAX_PETROL);    // randomly generate petrol

            // We will randomly generate the ship's starting location

            int x = rGen.Next(boundsRectangle.Width - shipSize);    // x needs to be within the width of our bounds rectangle
            int y = rGen.Next(boundsRectangle.Height - shipSize);   // and y needs to be within the height of it. We will
                                                                    // then minus shipSize so that it cannot overlap bounds
            // Then, we generate a point based on our two random numbers
            shipLocation = new Point(x, y);
            petrolBotState = EPetrolBotState.docked;
        }
Exemplo n.º 6
0
        // Constructor
        public PetrolBot(Ship botsShip, Graphics botsCanvas, int xPos, Random rGen)
        {
            this.botsShip       = botsShip;
            this.botsCanvas     = botsCanvas;
            shipLocation        = botsShip.ShipLocation;
            botState            = EPetrolBotState.docked;
            xPos                = xPos * 30;
            botStartingLocation = new Point(xPos, 520);
            botCurrentLocation  = botStartingLocation;

            int r = rGen.Next(255);
            int g = rGen.Next(255);
            int b = rGen.Next(255);

            botColor = Color.FromArgb(r, g, b);

            Ship.OutOfFuelEventHandler outOfFuelHandler = new Ship.OutOfFuelEventHandler(OutOfFuelEventHandler);
            this.botsShip.OutOfFuelEvent += outOfFuelHandler;

            EventHandler fullOfFuelHandler = new EventHandler(FullOfFuelEventHandler);

            this.botsShip.FullOfFuelEvent += fullOfFuelHandler;
        }
Exemplo n.º 7
0
        private void refuel()
        {
            OnOutOfFuelEvent(shipLocation);
            if (petrolBotState == EPetrolBotState.refuelling)
            {
                petrolBot.botCurrentLocation = shipLocation;
                if (petrol < 300)
                {
                    shipState = EShipState.refueling;

                    //shipVelocity = new Point(0, 0);

                    petrol += 10;
                }
                else // we have finished refueling
                {
                    //shipVelocity = oldVelocity;
                    shipState = EShipState.wandering;
                    petrolBotState = EPetrolBotState.docked;
                    OnFullOfFuelEvent();
                }
            }
            else
                checkIfPetrolBotHasArrived();
        }
Exemplo n.º 8
0
        private void checkIfPetrolBotHasArrived()
        {
            Rectangle rect = new Rectangle(shipLocation.X, shipLocation.Y, shipSize, shipSize);
            bool doesContain = rect.Contains(petrolBot.botCurrentLocation);

            if (doesContain)
            {
                petrolBotState = EPetrolBotState.refuelling;
            }
            //else
                //petrolBot.
            //if (petrolBot.botCurrentLocation)
        }