コード例 #1
0
        public void Implement()
        {
            // Learning a strategy Pattern
            Console.WriteLine("\nLearning Strategy Pattern\n");
            Soldier soldier1 = new Archerman(new Archer(), new WeaponBasedRefill(), new NoRepair());

            soldier1.Fight();
            soldier1.Refill();
            soldier1.Repair();

            Gunman soldier2 = new Gunman(new Gun(), new TimeBasedRefill(), new NoRepair());

            soldier2.Fight();
            soldier2.Refill();
            soldier2.Repair();

            //Superman can use any the weapon and is self repairable
            Soldier superman = new Superman(new Gun(), new TimeBasedRefill(), new SelfRepair());

            superman.Fight();
            superman.ChangeWeapon(new Archer());
            superman.ChangeRefill(new WeaponBasedRefill());
            superman.Fight();

            //Robot can use any the weapon and need human to repair
            Soldier robot = new Robot(new Archer(), new WeaponBasedRefill(), new ManualRepair());

            robot.Fight();
            robot.ChangeWeapon(new Gun());
            robot.ChangeRefill(new TimeBasedRefill());
            robot.Fight();
        }
コード例 #2
0
    /// <summary>
    /// Initialisiert alles und startet das Spiel
    /// </summary>
    /// <param name="spielmodus">Beschreibt welcher Spielmodus gespielt werden soll</param>
    public void Start(Spielmodus spielmodus)
    {
        this.spielmodus = spielmodus;
        timer.Start();
        superman   = new Superman(gr, new Size(GAME_WIDTH, GAME_HEIGHT));
        stars      = new Stars(gr, new Size(GAME_WIDTH, GAME_HEIGHT));
        kryptonite = new Kryptonite(gr, new Size(GAME_WIDTH, GAME_HEIGHT));
        powerups   = new Powerups(gr, new Size(GAME_WIDTH, GAME_HEIGHT));

        if (this.spielmodus == Spielmodus.Normal)
        {
            // Normalmodus etwas schneller machen damit es nicht zu langweilig wird
            this.speed = 3;
        }
        else if (this.spielmodus == Spielmodus.Endlos)
        {
            this.speed = 3;
        }
        else if (this.spielmodus == Spielmodus.Hardcore)
        {
            this.speed = 6;
        }

        stars.SpawnStars(this.speed, spielmodus);
        kryptonite.SpawnKryptonite(this.speed, this.level, this.spielmodus);
        powerups.SpawnPowerup();

        Draw();
    }
コード例 #3
0
        static void MakeHeroes()
        {
            var superman = new Superman();

            superman.MakeHero();
            superman.Introduce();
        }
コード例 #4
0
ファイル: _07ObjectController.cs プロジェクト: a6518470/test1
        // GET: _07Object
        public ActionResult Index()
        {
            Person jack = new Person();

            //jack.Name = "Jack Wang";
            jack.Age    = 18;
            jack.Gender = true;
            jack.Height = 175.5M;
            jack.Weight = 60;
            jack.Speak();
            jack.Jump();
            jack.Walk(10);

            Person mary = new Person();

            mary.Name   = "Jack Lee";
            mary.Age    = 17;
            mary.Gender = false;
            mary.Height = 155.5M;
            mary.Weight = 40;
            mary.Speak(5);
            mary.Jump(6, 3);

            var avg = (jack.Age + mary.Age) / 2;

            Person john = new Person("John Lin", 20, true, 170, 64);

            Superman Clock = new Superman();

            Clock.Walk(500);
            Clock.Fly();


            return(View());
        }
コード例 #5
0
    // Use this for initialization
    void Start()
    {
        IFlyer x = new Superman();

        x.doWork();

        // start camera streaming
        webCamTexture = new WebCamTexture();
        webCamTexture.Play();

        // instantiate network server to communicate with client phone
        clientSocket = new StreamSocket();
        serverIP     = new HostName("104.154.205.34");
        clientSocket.ConnectAsync(serverIP, serverPort);

        snapshotBytes   = new Buffer(4 * 1024 * 1024);
        friendNameBytes = new Buffer(64);

        /*
         * communicateThread = new Thread(t =>
         * {
         *  clientSocket.OutputStream.WriteAsync(snapshotBytes);
         *  // clientSocket.Send(snapshotBytes, snapshotBytes.Length, SocketFlags.None);
         *  // byte[] nameBytes = new byte[64];
         *  // int nameBytesLen = clientSocket.Receive(nameBytes);
         *  // string name = Encoding.ASCII.GetString(nameBytes, 0, nameBytesLen);
         *  // Debug.Log(name);
         *  // friendName = name;
         *  clientSocket.InputStream.ReadAsync(friendNameBytes, 64, InputStreamOptions.None);
         * });
         */
    }
コード例 #6
0
        public void SupermanHasPowerFlight()
        {
            var superman = new Superman();

            var power = superman.Powers.FirstOrDefault(p => p.Name == PowerConstants.FLIGHT);

            Assert.That(power.Name, Contains.Substring(PowerConstants.FLIGHT));
        }
コード例 #7
0
        public void SupermanHasPowerFlight10()
        {
            var superman = new Superman();

            var power = superman.Powers.FirstOrDefault(p => p.Name == PowerConstants.FLIGHT);

            Assert.That(power.Level, Is.EqualTo(10));
        }
コード例 #8
0
            public void should_put_item()
            {
                //act
                var superman = new Superman();

                Container.Put(Binding.Use <ISuper>(superman));

                //assert
                Container.Get <ISuper>().Should().NotBeNull();
            }
コード例 #9
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="LevelOne" /> class.
        /// </summary>
        public LevelOne()
        {
            // Backgrounds
            FileName = @"Assets\LevelOne.png";

            // Enemies
            for (int i = 0; i < 7; i++)
            {
                var ship      = new Ship(this);
                int positionY = ship.Height + 10;
                int positionX = 150 + i * (ship.Width + 50);
                ship.Position = new Point(positionX, positionY);


                Actors.Add(ship);
            }
            // Enemies2
            for (int i = 0; i < 5; i++)
            {
                var ship2      = new Ship2(this);
                int positionY1 = ship2.Height + 30;
                int positionX1 = 180 + i * (ship2.Width + 50);

                ship2.Position = new Point(positionX1, positionY1);

                Actors.Add(ship2);
            }
            for (int i = 0; i < 4; i++)
            {
                var ship3     = new Ship3(this);
                int positionY = ship3.Height + 70;
                int positionX = 180 + i * (ship3.Width + 50);
                ship3.Position = new Point(positionX, positionY);

                //присваиваем значение Ship куда он должен лететь true false

                ship3.Movement = i < 2;
                Actors.Add(ship3);
            }

            // Player
            Player = new PlayerShip(this);
            int playerPositionX = Size.Width / 2 - Player.Width / 2;
            int playerPositionY = Size.Height - Player.Height - 50;

            Player.Position = new Point(playerPositionX, playerPositionY);
            Actors.Add(Player);

            var superm     = new Superman(this);
            int positionYS = superm.Height + 10;
            int positionXS = superm.Width + 10;

            superm.Position = new Point(positionXS, positionYS);
            Actors.Add(superm);
        }
コード例 #10
0
            public void should_return_item()
            {
                //arrange
                var superman = new Superman();

                Container.Put(Binding.Use <ISuper>(superman));

                //act
                var result = Container.Get(typeof(ISuper));

                //assert
                result.Should().NotBeNull();
            }
コード例 #11
0
        public void PatternMatchingTestObjectType()
        {
            Hero hero = new Superman();

            var message = GetHeroHelloMessageWithIf(hero);

            Assert.Equal("I'm Superman", message);


            var message2 = GetHeroHelloMessageWithCase(hero);

            Assert.Equal("I'm Superman", message2);
        }
コード例 #12
0
            public void should_release_item()
            {
                //arrange
                var superman = new Superman();

                Container.Put(Binding.Use <ISuper>(superman).Named("bale"));

                //act
                Container.Release(superman.Clone());

                //assert
                Container.Get <ISuper>("bale").Should().BeNull();
            }
コード例 #13
0
            public void should_return_true()
            {
                //arrange
                var superman = new Superman();

                Container.Put(Binding.Use <ISuper>(superman));

                //act
                var result = Container.Has(typeof(ISuper));

                //assert
                result.Should().BeTrue();
            }
コード例 #14
0
ファイル: Program.cs プロジェクト: FacetOfVerity/learn_csharp
        static void Main(string[] args)
        {
            var superman = new Superman("SuperMan");
            var vader    = new DarthVader("DarthVader");

            superman.DealDamage(vader);
            var gopnic = new Gopnic("Vasya");

            //gopnic.DealDamage(superman); Superman не реализует интерфейс получения урона
            gopnic.DealDamage(vader);

            Console.ReadKey();
        }
コード例 #15
0
        static void Main(string[] args)
        {
            Batman    batman    = new Batman("Batman", "Dark Stuff");
            Wolverine wolverine = new Wolverine("wolverine", "regenerative power");
            Superman  superman  = new Superman("superman", "fly");
            Spiderman spiderman = new Spiderman("Spiderman", "throw spider web");


            //Encapsulation .....
            Console.WriteLine(wolverine.ToString());
            Console.WriteLine(superman);
            Console.WriteLine(spiderman);
            Console.WriteLine(batman);
        }
コード例 #16
0
        static void Heroes()
        {
            var mediator = new TowerOfJustice();
            var batman   = new Batman(mediator);
            var superman = new Superman(mediator);
            var robin    = new Robin(mediator);

            superman.send(new HeroMessage("Help needed in Metropolis!", batman, robin));
            batman.send(new HeroMessage("On the way to Metropolis!", superman));

            batman.send(new HeroMessage("Help needed in Gotham City!", superman, robin));
            superman.send(new HeroMessage("On the way to Gotham City!", batman));
            robin.send(new HeroMessage("On the way!", batman));
        }
コード例 #17
0
ファイル: Program.cs プロジェクト: boogermanus/dotnet
        static void Fight()
        {
            Hero superman = new Superman();
            Hero darkseid = new Darkseid();

            superman.Attack(darkseid);
            darkseid.Attack(superman);
            superman.Attack(darkseid);
            darkseid.Attack(superman);
            darkseid.Attack(superman);
            superman.Heal();
            superman.Heal();
            superman.Attack(darkseid);
            superman.Attack(darkseid);
            darkseid.Heal();
        }
コード例 #18
0
        public static void MainTest()
        {
            // Cannot resolve symbol 'Fly'
            // new Superman().Fly();

            IFly fly = new Superman();

            fly.Fly();

            fly = new MonkeyKing();
            fly.Fly();

            // Cannot access protected method 'GetDefaultName' here
            // IFly.GetDefaultName().Dump();

            IFly.GetPublicName().Dump();
        }
コード例 #19
0
            public void should_clear_all_items_in_container()
            {
                //arrange
                var superman = new Superman();

                Container.Put(Binding.Use <ISuper>(superman));
                var joker = new Joker();

                Container.Put(Binding.Use <IVillain>(joker).Named("joker"));

                //act
                Container.Dispose();

                //assert
                Container.Has(typeof(ISuper)).Should().BeFalse();
                Container.Has(typeof(IVillain), "joker").Should().BeFalse();
            }
コード例 #20
0
ファイル: Game.cs プロジェクト: IvoKnevil/IvoUppgift3
        private void InitializeMonsters() //initializes monsters and adds them to a list
        {
            NiceOldLady niceOldLady = new NiceOldLady();
            Greta       greta       = new Greta();
            Ghandi      ghandi      = new Ghandi();
            MLK         mLK         = new MLK();
            ObiWan      obiWan      = new ObiWan();
            Superman    superman    = new Superman();
            Frodo       frodo       = new Frodo();
            Batman      batman      = new Batman();
            McFly       mcFly       = new McFly();
            HarryPotter harryPotter = new HarryPotter();
            TrashMob    trashMob    = new TrashMob();

            listOfSpecialMonsters.AddRange(new Monster[]
            {
                greta, niceOldLady, ghandi, mLK, obiWan, superman, frodo, batman, mcFly, harryPotter
            });

            List <Monster> listToShuffle = new List <Monster>()
            {
                greta, niceOldLady, ghandi, mLK, obiWan, superman, frodo, batman, mcFly, harryPotter
            };

            //randomizes monsters to a new list so that the player doesnt always meet them in the same order
            int i = listToShuffle.Count;

            while (i > 0)
            {
                if (random.Next(10) <= 7)
                {
                    listOfMonsters.Add(trashMob);
                }
                else
                {
                    i--;
                    int listIndex = random.Next(i + 1);
                    listOfMonsters.Add(listToShuffle[listIndex]);
                    listToShuffle.RemoveAt(listIndex);
                }
            }
        }
コード例 #21
0
 public static void GetMoreHeroData(ISuperHero hero)
  {
      if(hero is Flash)
      {
          Flash f = hero as Flash;
          Console.WriteLine("Flash voltage:{0}\n", f.Voltage);
      }
      else if(hero is Superman)
      {
          Superman s = hero as Superman;
          Console.WriteLine("Superman speed:{0}\n", s.Speed);
      }
      else
      {
          if(hero is Spiderman)
          {
              Spiderman sp = hero as Spiderman;
              Console.WriteLine("Spiderman web left:{0}\n", sp.WebLeft);
          }
      }
  }
コード例 #22
0
        // GET: _07Object
        public ActionResult Index()
        {
            Person Jack = new Person();

            Jack.Name   = "Jack Wang";
            Jack.Age    = 18;
            Jack.Gender = true;
            Jack.Height = 180.5M;
            Jack.Weight = 62;
            Jack.Speak();
            Jack.Jump();
            Jack.Walk(10);


            Person Mary = new Person();

            Mary.Age    = 18;
            Mary.Gender = false;
            Mary.Height = 160;
            Mary.Weight = 49.9M;
            Mary.Speak(5);
            Mary.Jump();

            var avg = (Jack.Age + Mary.Age) / 2;


            //有做建構子 就可以用一行結束 不用像上面寫這麼多行
            Person John = new Person("John Lin", 20, true, 170, 65);



            //繼承superman的東西
            Superman Clock = new Superman();

            Clock.Walk(100);
            Clock.Fly();
            Clock.Fly(3);

            return(View());
        }
コード例 #23
0
        static void AddHero()
        {
            CyanWriteLine("Enter your Hero's name.");
            string heroName = Console.ReadLine();

            if (!HeroInList(heroName))
            {
                Hero hero;
                switch (heroName)
                {
                case "Superman":
                    hero = new Superman();
                    break;

                case "Batman":
                    hero = new Batman();
                    break;

                case "Wonderwoman":
                    hero = new Wonderwoman();
                    break;

                case "Deadpool":
                    hero = new Deadpool();
                    break;

                default:
                    CyanWriteLine("What's your hero's secret identity?");
                    hero = new CustomHero(heroName, Console.ReadLine());
                    break;
                }
                Heroes.Add(hero);
            }
            else
            {
                throw new Exception("Hero already exists.");
            }
        }
コード例 #24
0
ファイル: Program.cs プロジェクト: Sudo-Ale/ExamManager
        static void Main(string[] args)
        {
            //var dbSource = new DBDataSource();
            //var proc = new DataProcessor(dbSource);

            Person p = new Superman();

            p.Run();
            Superhero sh = new Superman();

            sh.Run();
            Superman sp = new Superman();

            sp.Run();



            //var path = @"C:\data\Studenti.csv";
            ////var UI = new UserInterface(proc);
            ////var  UI = new UserInterface(new DataProcessor(new FileDataSource(path)));
            //var UI = new UserInterface(new DataProcessor(new DBDataSource()));
            //UI.MainMenu();
        }
コード例 #25
0
            public void should_return_item()
            {
                //arrange
                var superman = new Superman();
                Container.Put(Binding.Use<ISuper>(superman));

                //act
                var result = Container.Get<ISuper>();

                //assert
                result.Should().NotBeNull();
            }
コード例 #26
0
            public void should_clear_all_items_in_container()
            {
                //arrange
                var superman = new Superman();
                Container.Put(Binding.Use<ISuper>(superman));
                var joker = new Joker();
                Container.Put(Binding.Use<IVillain>(joker).Named("joker"));

                //act
                Container.Dispose();

                //assert
                Container.Has(typeof (ISuper)).Should().BeFalse();
                Container.Has(typeof (IVillain), "joker").Should().BeFalse();
            }
コード例 #27
0
        public void SupermanHasAliasClarkKent()
        {
            var superman = new Superman();

            Assert.That(superman.Alias, Is.EqualTo(JusticeLeagueConstants.ALIAS_SUPERMAN));
        }
コード例 #28
0
        public void SupermanHasCityMetropolis()
        {
            var superman = new Superman();

            Assert.That(superman.City, Is.EqualTo(JusticeLeagueConstants.CITY_METROPOLIS));
        }
コード例 #29
0
        public void SupermanHasNameSuperman()
        {
            var superman = new Superman();

            Assert.That(superman.Name, Is.EqualTo(nameof(Superman)));
        }
コード例 #30
0
            public void should_return_true()
            {
                //arrange
                var superman = new Superman();
                Container.Put(Binding.Use<ISuper>(superman));

                //act
                var result = Container.Has(typeof (ISuper));

                //assert
                result.Should().BeTrue();
            }
コード例 #31
0
            public void should_release_item()
            {
                //arrange
                var superman = new Superman();
                Container.Put(Binding.Use<ISuper>(superman).Named("bale"));

                //act
                Container.Release(superman.Clone());

                //assert
                Container.Get<ISuper>("bale").Should().BeNull();
            }
コード例 #32
0
            public void should_put_item()
            {
                //act
                var superman = new Superman();
                Container.Put(Binding.Use<ISuper>(superman));

                //assert
                Container.Get<ISuper>().Should().NotBeNull();
            }