示例#1
0
文件: Test.cs 项目: ArturRush/Game
        public static void RunTests()
        {
            GunBullet b  = new GunBullet("BULLETNAME", "fdfd", 4);
            GunBullet bb = new GunBullet("BB", "fdfd", 4);
            GunClip   c  = new GunClip("C10", "ddddd", 10, new List <string>()
            {
                "BULLETNAME", "B"
            });
            VampireGun g = new VampireGun("GUNNAME", "DFDF", 1, 2, 50, 1, new List <string>()
            {
                "C8", "C10"
            });

            g.OnShoot += G_OnShoot;

            g.PutClip(c);
            Console.WriteLine(g.Shoot());
            var clip = g.TakeOutClip();

            clip.ChargeClip(bb);
            var bullets = new List <IShootable>();

            for (int i = 0; i < 5; i++)
            {
                bullets.Add(b);
            }
            clip.ChargeClip(bullets);
            g.PutClip(clip);

            Console.WriteLine(g.BulletsLeft());
            g.Shoot();
            Console.WriteLine(g.BulletsLeft());
        }
        static void Main(string[] args)
        {
            Gun mGun               = new MachineGun();
            Gun sGun               = new ShotGun();
            Gun mGunWithClip       = new GunClip(mGun, 40);
            Gun mGunWithTwoClips   = new GunClip(mGunWithClip, 60);
            Gun mGunWithEverything = new GunSilencer(mGunWithTwoClips, 0.9f);

            Console.Write("MachineGun:\n\t");
            mGun.Fire();
            Console.Write("ShotGun:\n\t");
            sGun.Fire();
            Console.Write("MachineGun with clip:\n\t");
            mGunWithClip.Fire();
            Console.Write("MachineGun with two clips:\n\t");
            mGunWithTwoClips.Fire();
            Console.Write("MachineGun with everything:\n\t");
            mGunWithEverything.Fire();

            try
            {
                new GunSilencer(mGun, 1.2f);
            }
            catch (InvalidOperationException ioe)
            {
                Console.WriteLine(ioe.Message);
            }
            finally
            {
                Console.WriteLine("Thanks for shooting!!");
            }
        }