Ejemplo n.º 1
0
 public void OutOfFuelCalled(Ship subject, EventArgs ea)
 {
     //Move to location
     this.location = subject.location;
     //Increment the fuel a bit
     subject.reFuel(3);
 }
Ejemplo n.º 2
0
 public PetrolBot(Graphics canvas, Point startingLocation, Ship botShip)
 {
     botCanvas = canvas;
     botColor = Color.Purple;
     botStartingLocation = startingLocation;
     botCurrentLocation = botStartingLocation;
     this.botShip = botShip;
     this.shipLocation = botShip.ShipLocation;
     botShip.FullOfFuelEvent += new EventHandler(FullOfFuelEventHandler);
     botShip.OutOfFuelEvent += new OutOfFuelEventHandler(OutOfFuelEventHandler);
 }
Ejemplo n.º 3
0
        public PetrolBot(Graphics canvas, Color colour, Ship shipSubject, int botNumber, int harbourHeight)
        {
            this.canvas = canvas;
            this.colour = colour;
            brush = new SolidBrush(colour);
            size = new Size(BOT_SIZE, BOT_SIZE);
            startLocation = calculateStartLocation(botNumber, harbourHeight);
            currentLocation = startLocation;

            // Setup the subject
            this.shipSubject = shipSubject;
            shipSubject.OnOutOfFuelEvent += new Ship.EmptyFuelEventHandler(FillShip);
            shipSubject.OnFullOfFuelEvent += new EventHandler(FinishFillingShip);
        }
Ejemplo n.º 4
0
        public Bot(Point startPosition, Point world_size, int size, Graphics g, Ship subject, Color botColor)
            : base(startPosition, world_size, size, g)
        {
            //Keep reference to subject/color
            this.subject = subject;
            this.botColor = botColor;
            this.startPosition = startPosition;

            //Create a new handlers
            Ship.OutOfFuelEventHandler OutOfFuelHandle = new Ship.OutOfFuelEventHandler(OutOfFuelCalled);
            Ship.FullOfFuelEventHandler FullOfFuelHandle = new Ship.FullOfFuelEventHandler(FullOfFuelCalled);

            //Register handlers
            subject.OutOfFuelEvent += OutOfFuelHandle;
            subject.FullOfFuelEvent += FullOfFuelHandle;
        }
Ejemplo n.º 5
0
        //ctor
        public PetrolBot(Graphics parentCanvas, Color colour, Point startLoc, int botSize, Ship tetheredShip)
        {
            this.botSize = botSize;
            this.parentCanvas = parentCanvas;
            botColour = colour;
            botShip = tetheredShip;

            //Set the starting location  & the current location as the initially passed in location.
            botStartingLocation = startLoc; //This will not change
            botCurrentLocation = botStartingLocation; //This will change a lot.

            //Bind event handler
            Ship.OutOfFuelEventHandler outOfFuelHandler = new Ship.OutOfFuelEventHandler(OutOfFuelEventHandler);
            botShip.OutOfFuelEvent += outOfFuelHandler;

            Ship.FullOfFuelEventHandler fullOfFuelHandler = new Ship.FullOfFuelEventHandler(FullOfFuelEventHandler);
            botShip.FullOfFuelEvent += fullOfFuelHandler;
        }
Ejemplo n.º 6
0
        public Form1()
        {
            InitializeComponent();

            //Init things
            mainCanvas = CreateGraphics();
            backgroundBrush = new SolidBrush(Color.LightBlue);
            foregroundPanelBrush = new SolidBrush(Color.Black);

            botList = new List<PetrolBot>();
            shipList = new List<Ship>();

            r = new Random();

            //Instantiate some ships
            Ship s1 = new Ship(SHIP_SIZE, mainCanvas,r);
            Ship s2 = new Ship(SHIP_SIZE, mainCanvas,r);
            Ship s3 = new Ship(SHIP_SIZE, mainCanvas,r);
            Ship s4 = new Ship(SHIP_SIZE, mainCanvas,r);
            Ship s5 = new Ship(SHIP_SIZE, mainCanvas,r);

            //Add ships to the list
            shipList.Add(s1);
            shipList.Add(s2);
            shipList.Add(s3);
            shipList.Add(s4);
            shipList.Add(s5);

            //Instantiate some petrolBots
            PetrolBot pb1 = new PetrolBot(mainCanvas, Color.Lime, new Point(25, 425), BOT_SIZE, s1);
            PetrolBot pb2 = new PetrolBot(mainCanvas, Color.Orange, new Point(75, 425), BOT_SIZE,s2);
            PetrolBot pb3 = new PetrolBot(mainCanvas, Color.Purple, new Point(125, 425), BOT_SIZE,s3);
            PetrolBot pb4 = new PetrolBot(mainCanvas, Color.Teal, new Point(175, 425), BOT_SIZE,s4);
            PetrolBot pb5 = new PetrolBot(mainCanvas, Color.Yellow, new Point(225, 425), BOT_SIZE,s5);

            //Add bot to its list
            botList.Add(pb1);
            botList.Add(pb2);
            botList.Add(pb3);
            botList.Add(pb4);
            botList.Add(pb5);
        }
Ejemplo n.º 7
0
        public Form1()
        {
            InitializeComponent();

            canvas = CreateGraphics();
            randomGenerator = new Random();
            harbourBackgroundColour = Color.FromArgb(127, 127, 127);
            harbourBrush = new SolidBrush(harbourBackgroundColour);
            ships = new List<Ship>();
            petrolBots = new List<PetrolBot>();

            // Create Ships and their Petrol Bots
            for (int i = 0; i < NUMBER_OF_PETROL_BOTS; i++)
            {
                Ship newShip = new Ship(canvas, new Rectangle(0, 0, HARBOUR_WIDTH, HARBOUR_HEIGHT), randomGenerator);
                PetrolBot newPretrolBot = new PetrolBot(canvas, generateRandomColour(), newShip, i, HARBOUR_HEIGHT);

                ships.Add(newShip);
                petrolBots.Add(newPretrolBot);
            }

            runTheSimulations();
        }
Ejemplo n.º 8
0
 public void FullOfFuelCalled(Ship subject, EventArgs ea)
 {
     //Move home
     this.location = startPosition;
 }
Ejemplo n.º 9
0
        private void createShips()
        {
            int shipSize=50;
            ships = new Ship[NUMSHIPS];
            for (int i = 0; i < ships.Length; i++)
            {
                //Create start position

               Point startPoint=new Point(rng.Next(shipSize,world_size.X-shipSize+1),
                                          rng.Next(shipSize,world_size.Y-shipSize+1));
                //Create delta
                Point delta = new Point(rng.Next(-MAXSPEED, MAXSPEED + 1),
                                        rng.Next(-MAXSPEED, MAXSPEED + 1));
                //Create new ship
                ships[i] = new Ship(startPoint, world_size, shipSize, delta, g);
            }
        }