Пример #1
0
 /// <summary>
 /// this thread method renders and displays block in the gdi window
 /// </summary>
 private void ShowThread()
 {
     while (true)
     {
         Pic.Clear();
         lock (blocks)
         {
             foreach (Block item in blocks)
             {
                 item.ShowBlock(Pic);
             }
         }
         Pic.Render();
         Thread.Sleep(100);
     }
 }
Пример #2
0
        /// <summary>
        /// timer tick event to get the balls to move around in gdi window area(stays in bounds)
        /// as well as register collisions between green and blue balls to new collision list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _timer_Tick(object sender, EventArgs e)
        {
            //collide list
            List <Ball> colideBG = new List <Ball>();

            //add balls in colided list to gdi window
            foreach (Ball item in _collidedBalls)
            {
                item.Move(_collidedGDI);
            }

            //main cdrawer with green and blue balls
            foreach (Ball item in _blueList)
            {
                item.Move(_greenBlueGDI);
            }
            foreach (Ball item in _greenList)
            {
                item.Move(_greenBlueGDI);
            }

            //take collided green and blue balls and add them to the colided list
            colideBG = _greenList.Intersect(_blueList).ToList();

            //remove collided green and blue balls
            foreach (Ball item in colideBG)
            {
                _blueList.RemoveAll(blue => blue.Equals(item));
                _greenList.RemoveAll(green => green.Equals(item));
                //set colided balls color to red
                item._BallColor = Color.Red;
            }

            // set temp collide list to with exsisting collide list
            //using one or more of Concat(),Union(), Distinct()
            _collidedBalls = new List <Ball>(_collidedBalls.Union(colideBG));

            //clear gdi windows and add background text
            _greenBlueGDI.Clear();
            _collidedGDI.Clear();
            _greenBlueGDI.AddText($"Blue: {_blueList.Count} Green: {_greenList.Count}", 40, Color.White);

            //color colid number when colisions happen
            //have the count background text “lightup” and fade back to normal over a few timer cycles
            //Collided(Red ) CDrawer, if a collision occurred,
            //have the count background text “lightup” and fade back to normal over a few timer cycles –
            //figure out what looks good.You may not modify the Ball class.
            //show a fade for when a collision happens
            if (colideBG.Count > 0)
            {
                _collidedGDI.AddText($"{_collidedBalls.Count}", 60, Color.Yellow);
                fade = 255;//global int
            }
            else
            {
                fade -= 25;
                if (fade < 0)
                {
                    fade = 0;
                }
                _collidedGDI.AddText($"{_collidedBalls.Count}", 60, Color.FromArgb(fade, 255, 255, 0));// to white from yellow
            }

            //for loop from each green/blue balls lists, showing them in gdi window. same for collison list-call show method
            for (int i = 0; i < _blueList.Count; i++)
            {
                _blueList[i].Show(_greenBlueGDI, i);
                _greenBlueGDI.Render();
            }
            for (int i = 0; i < _greenList.Count; i++)
            {
                _greenList[i].Show(_greenBlueGDI, i);
                _greenBlueGDI.Render();
            }
            for (int i = 0; i < _collidedBalls.Count; i++)
            {
                _collidedBalls[i].Show(_collidedGDI, i);
                _collidedGDI.Render();
            }
        }