Пример #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 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);
            }
        }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
0
        public Form1()
        {
            InitializeComponent();

            //Inititalise them
            mainCanvas       = CreateGraphics();
            rand             = new Random();
            backgroundBrush  = new SolidBrush(Color.Gray);
            petrolBackground = new SolidBrush(Color.Black);
            boundsRectangle  = new Rectangle(0, 0, Width, 500);
            shipList         = new List <Ship>();
            petrolList       = new List <PetrolBot>();

            //Inititalise Ships
            Ship s1 = new Ship(mainCanvas, rand);
            Ship s2 = new Ship(mainCanvas, rand);
            Ship s3 = new Ship(mainCanvas, rand);
            Ship s4 = new Ship(mainCanvas, rand);
            Ship s5 = new Ship(mainCanvas, rand);

            //Add to Ship List
            shipList.Add(s1);
            shipList.Add(s2);
            shipList.Add(s3);
            shipList.Add(s4);
            shipList.Add(s5);

            //Inititalise PetrolBot
            PetrolBot b1 = new PetrolBot(mainCanvas, Color.Blue, new Point(50, 525), s1);
            PetrolBot b2 = new PetrolBot(mainCanvas, Color.Pink, new Point(100, 525), s2);
            PetrolBot b3 = new PetrolBot(mainCanvas, Color.Green, new Point(150, 525), s3);
            PetrolBot b4 = new PetrolBot(mainCanvas, Color.Yellow, new Point(200, 525), s4);
            PetrolBot b5 = new PetrolBot(mainCanvas, Color.Brown, new Point(250, 525), s5);

            //Add to PetrolBot List
            petrolList.Add(b1);
            petrolList.Add(b2);
            petrolList.Add(b3);
            petrolList.Add(b4);
            petrolList.Add(b5);

            // Start the timer
            timer1.Start();
        }
Пример #6
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);
            }
        }
Пример #7
0
        //Custom method to add petrolbot to ship propeties, so that the bot can rases an  event and the hsi knows when t start refueling.
        public void addPetrolbot(PetrolBot ReferenceToBot)
        {
            petrolBot = ReferenceToBot;

            //creting new event handler delegate , to run ships method "waitingFor Ship" when the pertorl bot arrives
            EventHandler petBotAtShipDeledate = new EventHandler(WaitingForShip);

            //subscribe methof to runn when petrolbot raises event.
            petrolBot.AtShipLocation += petBotAtShipDeledate;
        }