示例#1
0
        public Form1()
        {
            InitializeComponent();
            FormBorderStyle = FormBorderStyle.FixedSingle;
            mainCanvas = this.CreateGraphics();
            offScreenBitmap = new Bitmap(this.Width, this.Height);
            offScreenGraphics = Graphics.FromImage(offScreenBitmap);

            timer1.Enabled = true;
            shipList = new List<Ship>();
            botList = new List<PetrolBot>();
            numShips = 6;
            rGen = new Random();

            mainBrush = new SolidBrush(Color.LightBlue);
            blackBrush = new SolidBrush(Color.Black);

            for (int i = 0; i < numShips; i++ )
            {
                Ship ship = new Ship(offScreenGraphics, SHIP_SIZE, rGen);
                PetrolBot bot = new PetrolBot(offScreenGraphics, ship, new Point(50 * (i + 1), 500), rGen);
                shipList.Add(ship);
                botList.Add(bot);
            }
        }
示例#2
0
        public PetrolBot(Ship BotShip, Graphics BotCanvas, Random Rand, Point InitalLocation)
        {
            rand = Rand;

               //passed in ship\subject
               botShip = BotShip;

               botCanvas = BotCanvas;
               botColour = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));
               botStartingLocation = InitalLocation;
               botCurrentlocation = InitalLocation;
               double radiansToship = 0;
               botVelovity = 10;

               botState = BotState.waiting;

               //Create delegate to assign a method we want to run when the assigned ship (to this petrol bot) rasies an event. Then Assign a
               //method to this delegate.(this event uses a system provided event handler.)
               EventHandler shipfull = new EventHandler(FullOfFuelEventhandler);

               //Create  delegate for our custom event handler that can pass a data bucket, when run the assigned ship event (to this petrol bot) rasies an event. Then Assign
               //method to this delegate.(this event uses a system provided event handler.)
               Ship.outOfFuelEventHandler shipempty = new Ship.outOfFuelEventHandler(OutOfFuelEventHandler);

               //Assigning delegate to event
               botShip.FullOfFuelEvent += shipfull;
               //Assigning delegate to event
               botShip.OutOfFuelEvent += shipempty;
        }
示例#3
0
文件: Bot.cs 项目: rNdm74/C-
        /// <summary>
        /// Initiate the send home after the fueling is complete
        /// </summary>
        public void SendHome()
        {
            refuelingShip = null;
            isRefueling = false;
            isHome = true;

            location = homeLocation;
        }
示例#4
0
文件: Bot.cs 项目: rNdm74/C-
        /// <summary>
        /// Dispatches the bot when a ship fires the refuel event
        /// </summary>
        /// <param name="ship">Ship the fired the event</param>
        /// <param name="location">Location of the ship that fired the event</param>
        public void Dispatch(Ship ship, PointF location)
        {
            state = EObjectState.REFUELING;

            refuelingShip = ship;
            isRefueling = true;
            isHome = false;

            this.location = location;
        }
示例#5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            canvas = CreateGraphics();
            shipPosition = new Point(50, 50);
            botPosition = new Point(50, 420);

            ship = new Ship(canvas, Color.Red, shipPosition, 50);
            bot = new PetrolBot(canvas, Color.Blue, botPosition, 20, ship);
            timer1.Enabled = true;
        }
示例#6
0
        public PetrolBot(Graphics botCanvas, Ship botShip, Point botStartingLocation, Random rGen)
        {
            this.botCanvas = botCanvas;
            this.botShip = botShip;
            this.botStartingLocation = botStartingLocation;
            botColour = Color.FromArgb(rGen.Next(255), rGen.Next(255), rGen.Next(255));
            botCurrentLocation = botStartingLocation;

            Ship.OutOfFuelEventHandler outOfFuelHandler = new Ship.OutOfFuelEventHandler(OutOfFuelEventHandler);
            botShip.OutOfFuelEvent += outOfFuelHandler;

            Ship.FullOfFuelEventHandler fullOfFuelHandler = new Ship.FullOfFuelEventHandler(FullOfFuelEventHandler);
            botShip.FullOfFuelEvent += fullOfFuelHandler;
        }
示例#7
0
        public PetrolBot(Ship BotShip, Graphics BotCanvas, Random Rand, Point InitalLocation)
        {
            rand = Rand;
               botShip = BotShip;
               botCanvas = BotCanvas;
               botColour = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));
               botStartingLocation = InitalLocation;
               botCurrentlocation = InitalLocation;

               EventHandler shipfull = new EventHandler(FullOfFuelEventhandler);
               Ship.outOfFuelEventHandler shipempty = new Ship.outOfFuelEventHandler(OutOfFuelEventHandler);

               botShip.FullOfFuelEvent += shipfull;
               botShip.OutOfFuelEvent += shipempty;
        }
示例#8
0
        public PetrolBot(Graphics botCanvas, Color botColour, Point botLocation, int botSize, Ship ship)
        {
            this.botCanvas = botCanvas;
            this.botColour = botColour;
            this.botLocation = botLocation;
            this.waitingLocation = botLocation;
            this.botSize = botSize;

            botBrush = new SolidBrush(botColour);

            this.botShip = ship;

            Ship.OutOfFuelEvent outOfFuelHandler = new Ship.OutOfFuelEvent(OutOfFuelHandler);
            Ship.FullOfFuelEvent fullOfFuelHandler = new Ship.FullOfFuelEvent(FullOfFuelHandler);

            ship.outOfFuel += outOfFuelHandler;
            ship.fullOfFuel += fullOfFuelHandler;
        }
示例#9
0
        public PetrolBot(Ship botShip, Graphics botCanvas, int startXPos, int startYPos)
        {
            this.botShip = botShip;
            this.botCanvas = botCanvas;
            shipXPos = botShip.XPos;
            shipYPos = botShip.YPos;
            this.startXPos = startXPos;
            this.startYPos = startYPos;
            xPos = startXPos;
            yPos = startYPos;
            botDiameter = 10;
            botColour = new SolidBrush(Color.Blue);

            Ship.ShipEventHandler fullHandler = new Ship.ShipEventHandler(FullOfFuelEvent);
            botShip.FullOfFuelEvent += fullHandler;

            Ship.ShipEventHandler outHandler = new Ship.ShipEventHandler(OutOfFuelEvent);
            botShip.OutOfFuelEvent += outHandler;
        }
示例#10
0
        public Form1()
        {
            InitializeComponent();

            canvas = CreateGraphics();
            rGen = new Random();
            shipList = new List<Ship>();
            botList = new List<PetrolBot>();

            for (int i = 0; i < 5; i++)
            {
                Ship ship = new Ship(rGen.Next(CANVAS_WIDTH), rGen.Next(CANVAS_WIDTH), canvas, rGen);
                shipList.Add(ship);
            }

            for (int i = 0; i < shipList.Count; i++)
            {
                PetrolBot bot = new PetrolBot(shipList[i], canvas, 80 * (i + 1), CANVAS_WIDTH);
                botList.Add(bot);
            }
        }