Пример #1
0
        public PetrolBot(Graphics botCanvas, Ship botShip, Point botStartingLocation, Random rGen)
        {
            this.botCanvas = botCanvas;
            botColor = Color.FromArgb(rGen.Next(255), rGen.Next(255), rGen.Next(255));
            this.botStartingLocation = botStartingLocation;
            this.botCurrentLocation = botStartingLocation;
            this.botShip = botShip;

            EventHandler fullOfFuelHandler = new EventHandler(FullOfFuelEventHandlerMethod);
            Ship.OutOfFuelEventHandler outOfFuelHandler = new Ship.OutOfFuelEventHandler(OutOfFuelEventHandlerMethod);
            botShip.fullOfFuelEvent += fullOfFuelHandler;
            botShip.outOfFuelEvent += outOfFuelHandler;
            drawBot();
        }
Пример #2
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.OnOutOfFuel += new Ship.OutOfFuelEventHandler(FillShip);
            shipSubject.OnFullOfFuel += new EventHandler(FinishFillingShip);
        }
Пример #3
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(randomGenerator, canvas, new Rectangle(0, 0, HARBOUR_WIDTH, HARBOUR_HEIGHT));
                PetrolBot newPretrolBot = new PetrolBot(canvas, generateRandomColour(), newShip, i, HARBOUR_HEIGHT);

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

            runTheSimulations();
        }