Beispiel #1
0
        public void TestInitialize()
        {
            var botFactory   = new BotFactory();
            var humanFactory = new HumanFactory();

            this.database = new Database(botFactory, humanFactory);
        }
        protected override void GenerateDetails(ProtoArray <Chunk> map, Random random)
        {
            int chunkWidth  = map.Width;
            int chunkHeight = map.Height;

            int chunkX = StaticRandom.Rand(0, chunkWidth);
            int chunkY = StaticRandom.Rand(0, chunkHeight);

            int x = StaticRandom.Rand(0, Chunk.Width);
            int y = StaticRandom.Rand(0, Chunk.Height);

            while (map[chunkX, chunkY].Tiles[x, y].Resources != null)
            {
                chunkX = StaticRandom.Rand(0, chunkWidth);
                chunkY = StaticRandom.Rand(0, chunkHeight);

                x = StaticRandom.Rand(0, Chunk.Width);
                y = StaticRandom.Rand(0, Chunk.Height);
            }

            HumanFactory hFactory       = new HumanFactory();
            Point2D      entityLocation = new Point2D(((chunkX * Chunk.Width) + x), (chunkY * Chunk.Height) + y);
            Human        human          = hFactory.GenerateHuman(entityLocation, this.Dimension);

            map[chunkX, chunkY].Creatures.Add(human);
        }
Beispiel #3
0
        void OnEnqueueTimerElapsed(Object O, ElapsedEventArgs EventArguments)
        {
            if (PatientsLeftCount == 0)
            {
                _EnqueueTimer.Elapsed -= new ElapsedEventHandler(OnEnqueueTimerElapsed);
                return;
            }
            _RandomSourceLocker.WaitOne();
            var AddingPatient = _RandomSource.Next(10) < 4;

            _RandomSourceLocker.ReleaseMutex();
            if (AddingPatient)
            {
                var NewPatientInQueue = HumanFactory.SpawnPatient();
                PatientsLeftCount--;
                _QueueLocker.WaitOne();
                _Queue.Add(NewPatientInQueue);
                QueueChanged(_Queue);
                _QueueLocker.ReleaseMutex();
                _HistoryLocker.WaitOne();
                HistoryUpdated($"Patien {NewPatientInQueue} got in queue.");
                _HistoryLocker.ReleaseMutex();
                Thread.Sleep(10);
            }
        }
Beispiel #4
0
 public InfectiousDiseaseDepartment(UInt32 LookoutCapacity, UInt32 DoctorsCount, UInt32 TotalCountOfPacients, UInt32 TimeSpeed)
 {
     this._RandomSource     = new Random();
     this.LookoutCapacity   = LookoutCapacity;
     this.PatientsLeftCount = TotalCountOfPacients;
     this._Lookout          = new List <Patient>();
     this._Queue            = new List <Patient>();
     this._Doctors          = new Doctor[DoctorsCount];
     for (var Index = 0; Index < DoctorsCount; Index++)
     {
         _Doctors[Index] = HumanFactory.SpawnDoctor();
         _Doctors[Index].FinishedAppointment += OnDoctorFinishedAppointment;
         _Doctors[Index].RequiredAssistance  += OnDoctorRequiresAssistance;
     }
     #region Initializing timers
     _EnqueueTimer               = new System.Timers.Timer(TimeSpeed);
     _EnqueueTimer.Elapsed      += new ElapsedEventHandler(OnEnqueueTimerElapsed);
     _AddToLookoutTimer          = new System.Timers.Timer(TimeSpeed);
     _AddToLookoutTimer.Elapsed += new ElapsedEventHandler(OnAddToLookoutTimerElapsed);
     _InfectQueueTimer           = new System.Timers.Timer(TimeSpeed);
     _InfectQueueTimer.Elapsed  += new ElapsedEventHandler(OnInfectQueueTimerElapsed);
     #endregion
     #region Initializing mutexes
     _QueueLocker        = new Mutex();
     _LookoutLocker      = new Mutex();
     _HistoryLocker      = new Mutex();
     _RandomSourceLocker = new Mutex();
     #endregion
 }
Beispiel #5
0
        private static void FactoryTest()
        {
            AbstractHumanFactory factory = new HumanFactory();

            Console.WriteLine(new string('*', 20));
            Console.WriteLine("Create White human:");
            var hummanWhite = factory.CreateHuman <WhiteHuman>();

            hummanWhite.GetColor();
            hummanWhite.Talk();

            Console.WriteLine(new string('*', 20));
            Console.WriteLine("Create Yellow human:");
            var hummanYellow = factory.CreateHuman <YellowHuman>();

            hummanYellow.GetColor();
            hummanYellow.Talk();

            Console.WriteLine(new string('*', 20));
            Console.WriteLine("Create Black human:");
            var hummanBlack = factory.CreateHuman <BlackHuman>();

            hummanBlack.GetColor();
            hummanBlack.Talk();
        }
Beispiel #6
0
 public override void Test(Action<Task[]> callBack)
 {
     IFactoryMethod factory = new HumanFactory();
     IRace race = factory.CreateInstance();
     race.ShowKing();
     callBack.Invoke(null);
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            try
            {
                var builder = new ConfigurationBuilder();
                var config  = builder.AddJsonFile("appsettings.json", false, true).Build();


                Player player = new Player(); //1. 到处都是细节
                {
                    Console.WriteLine("***********************Normal*****************");
                    Human human = new Human();
                    player.PlayWar3(human);
                }

                {
                    Console.WriteLine("***********************Using Interface*****************");
                    IRace human = new Human(); // 2. 左边是抽象, 右边是细节
                    player.PlayWar3(human);
                }

                {
                    Console.WriteLine("***********************Simple Factory*****************");
                    // 我们希望去掉右边的细节,咱们就封装一下 转移一下

                    IRace human = SimpleFactory.CreateRace(RaceType.Undead); // 3 没有细节 细节被转移
                    player.PlayWar3(human);
                }
                {
                    Console.WriteLine("***********************Simple Factory by Configuration*****************");
                    // 利用配置文件读取种族

                    IRace human = SimpleFactory.CreateRace(config); // 3 没有细节 细节被转移
                    player.PlayWar3(human);
                }

                {
                    Console.WriteLine("***********************Simple Factory Reflection*****************");
                    IRace human = SimpleFactory.CreateRaceConfigReflection(config);
                    player.PlayWar3(human);
                }

                {
                    // 工厂方法就是把每个new 对象的操作单独作为一个工厂
                    IFactory factory = new HumanFactory();
                    IRace    race    = factory.CreateRace();
                    // 何苦 搞了这么多工厂 还不是创建对象
                    // 以前依赖的是Human 现在换成了 HumanFactory

                    // 1. 工厂可以增加一些创建逻辑 屏蔽对象实例化的复杂度 比如增加多种参数
                    // 2. 对象创建的过程中 可能扩展(IOC)
                }
                Console.ReadKey();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public void Init()
        {
            humanFactory = new HumanFactory();
            var    requestor = WikiDataRequestor.Create();
            string response  = File.ReadAllText(TestFile);

            wikiDataResponse = requestor.ResultFromString(response);
        }
Beispiel #9
0
    public Meeting(int number)
    {
        var humanFactory = new HumanFactory();

        Visitors = Enumerable.Range(1, number)
                   .Select(x => humanFactory.Create <T>())
                   .ToArray();
    }
Beispiel #10
0
        public static void Main()
        {
            IHumanFactory humanFactory = new HumanFactory();
            IBotFactory   botFactory   = new BotFactory();
            IDatabase     database     = new Database(botFactory, humanFactory);
            IEngine       engine       = new Engine(database);

            engine.Run();
        }
        public void Init()
        {
            fixture = new Fixture();

            //If I give IHuman interface give the Man Class
            fixture.Register <IHuman>(() => new Man());
            //create HumanFactory mock class
            mockHumanFactory = fixture.Build <HumanFactory>().Create();
        }
Beispiel #12
0
        public void T2_create_human_by_factory()
        {
            HumanFactory humanFactory = new HumanFactory();
            ICharacter   iCharacter   = humanFactory.Create("Jedusor", "Tom");

            iCharacter.Walk().Should().Be("Je marche !");
            iCharacter.GetLastName().Should().Be("Jedusor");
            iCharacter.GetFirstName().Should().Be("Tom");
        }
Beispiel #13
0
 static void Main(string[] args)
 {
     try
     {
         {
             Human human = new Human();
             human.ShowKing();
         }
         {
             IRace iRace = new Human();//面向抽象
             iRace.ShowKing();
         }
         #region MyRegion
         {
             IRace iRace = SimpleFactory.CreateInstance(SimpleFactory.RaceType.Human);// new Human();//怎么样更面向抽象
             iRace.ShowKing();
         }
         {
             //可配置
             IRace iRace = SimpleFactory.CreateInstanceConfig();
             iRace.ShowKing();
         }
         {
             //可配置可扩展
             IRace iRace = SimpleFactory.CreateInstanceConfigReflection();
             iRace.ShowKing();
         }
         //走一步看一步
         {
             IRace iRace = SimpleFactory.CreateInstance(SimpleFactory.RaceType.Undead);
         }
         #endregion
         {
             IFactory factory = new HumanFactory();
             //就是为了扩展(mvc扩展IOC就知道了)  为了屏蔽细节
             IRace race = factory.CreateInstance();
         }
         {
             //工厂方法+ 抽象--是必须全部实现的:方便扩展种族 但是不能扩展产品簇--倾斜性可扩展性设计
             AbstractFactoryBase factory = new HumanFactoryAbstract();
             IRace     race     = factory.CreatRace();
             IArmy     army     = factory.CreateArmy();
             IResource resource = factory.CreateResource();
         }
         {
             AbstractFactoryBase factory = new UndeadFactoryAbstract();
             IRace     race     = factory.CreatRace();
             IArmy     army     = factory.CreateArmy();
             IResource resource = factory.CreateResource();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     Console.ReadLine();
 }
Beispiel #14
0
        /// <summary>
        /// 工厂方法
        /// </summary>
        /// <returns></returns>
        // GET: FactoryMethod
        public ActionResult Index()
        {
            //  HumanFactory humanfactory = new HumanFactory();
            IRace irace = HumanFactory.CreateHumanFactory();
            //使用接口
            IFartoryMehod humamfactory = new HumanFactory();
            IRace         iraces       = humamfactory.CreateFactoy();

            return(View());
        }
Beispiel #15
0
        //首先有一个抽象的工厂,然后具体的工厂继承抽象工厂,实现
        //每一个工厂只用来生产一种产物
        //虽然上层还是new了对象 但是屏蔽了底层的业务类
        public static void Show()
        {
            IFactory human = new HumanFactory();

            human.Create();

            IFactory car = new CarFactory();

            car.Create();
        }
Beispiel #16
0
        public void TestIfCleanerFactoryIsWorking()
        {
            //arrange
            Cleaner cleaner;

            //act
            cleaner = (Cleaner)HumanFactory.CreateHuman(EHumanType.Cleaner);

            //assert
            Assert.IsNotNull(cleaner);
        }
Beispiel #17
0
        public void TestIfCustomerFactoryIsWorking()
        {
            //arrange
            Customer customer;

            //act
            customer = (Customer)HumanFactory.CreateHuman(EHumanType.Customer);

            //assert
            Assert.IsNotNull(customer);
        }
Beispiel #18
0
        public void HumanFactoryDemo()
        {
            AbstractHumanFactory factory = new HumanFactory();
            var human = factory.CreateHuman <WhiteHuman>();

            human.Talk();
            human = factory.CreateHuman <BlackHuman>();
            human.Talk();
            human = factory.CreateHuman <YellowHuman>();
            human.Talk();
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            IHumanFactory humanFactory = new HumanFactory();
            var           people       = humanFactory.Bind().ToList();

            foreach (var human in people)
            {
                Console.WriteLine($"{human.FirstName} {human.LastName}");
            }

            people.GenerateRandomWeight(60, 120).GenerateRandomBirthDate();
        }
Beispiel #20
0
        static public void emulation()
        {
            IUnitFactory factory;

            Console.WriteLine("Enter race\n1 Humans\n2 Undead");
            string factoryInput = Console.ReadLine();

            if (factoryInput == "1")
            {
                factory = new HumanFactory();
            }
            else if (factoryInput == "2")
            {
                factory = new UndeadFactory();
            }
            else
            {
                throw new Exception();
            }
            Application app = new Application(factory);

            bool isChoosing = true;

            while (isChoosing)
            {
                Console.WriteLine("1 Create workers\n2 Create light units\n3 Create hero unit\n4 Exit");
                string unitInput = Console.ReadLine();
                switch (unitInput)
                {
                case "1":
                    app.CreateWorkerUnits(UnitsEnter());
                    break;

                case "2":
                    app.CreateLightUnits(UnitsEnter());
                    break;

                case "3":
                    app.CreateHero();
                    break;

                case "4":
                    isChoosing = false;
                    break;
                }
            }

            app.HeroSpeak();
            app.HeroUserAbility();
            app.LighTUnitAttack(20);
        }
Beispiel #21
0
        public override ProtoArray <Tile> GenerateDetails(ProtoArray <Tile> map, Random r)
        {
            int xSize = map.Width;
            int ySize = map.Height;

            int x = StaticRandom.Rand(0, xSize);
            int y = StaticRandom.Rand(0, ySize);

            HumanFactory hFactory = new HumanFactory();

            map[x, y].Living = (hFactory.GenerateHuman(new Point(x, y)));

            return(map);
        }
Beispiel #22
0
        /// <summary>
        /// Spawns a character at a random position in the map without spawning the character in the same space as another character.
        /// </summary>
        /// <param name="playerID"></param>
        public static void SpawnRandomCharacter(Guid playerID, int dimension)
        {
            Point2D randomLocation = FindRandomLocation(dimension);

            HumanFactory humanFactory = new HumanFactory();
            Human        human        = humanFactory.GenerateHuman(randomLocation, dimension, playerID);

            World.Data.World.GetChunkByTile(dimension, randomLocation.X, randomLocation.Y).Creatures.Add(human.ID, human);

            if (World.Data.World.Mode == Networking.EngineMode.ServerOnly)
            {
                ServerSendRecieve.SendAll(new WorldModifierMessage(new LivingCreatedModifier(human)));
            }
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            AbstractFactory.AbstractFactory abstractFactoryHuman = new HumanFactory();
            abstractFactoryHuman.CreateArmy();
            abstractFactoryHuman.CreateRace();
            abstractFactoryHuman.CreateResource();



            AbstractFactory.AbstractFactory abstractFactoryUndead = new UndeadFactory();
            abstractFactoryUndead.CreateArmy();
            abstractFactoryUndead.CreateRace();
            abstractFactoryUndead.CreateResource();
        }
Beispiel #24
0
    public static AbstractFactory GetFactory(FactoryType factoryType)
    {
        switch (factoryType)
        {
        case FactoryType.Human:
            AbstractFactory humanFactory = new HumanFactory();
            return(humanFactory);

        case FactoryType.Animal:
            AbstractFactory animalFactory = new AnimalFactory();
            return(animalFactory);
        }
        return(null);
    }
Beispiel #25
0
        public static void GetAllPersons()
        {
            var humans       = new List <Human>();
            var errors       = new List <Tuple <int, Exception> >();
            var responseBody = File.ReadAllText(WdqResponse);
            var wdqRequestor = new WdqRequestor();

            Console.WriteLine("Getting human instance references.");
            var wdqResult = wdqRequestor.ResultFromString(responseBody);

            Console.WriteLine("Found {0} human instances.", wdqResult.items.Length);

            var humanFactory = new HumanFactory();

            foreach (var id in wdqResult.items)
            {
                try
                {
                    if (humans.Count % 10 == 0)
                    {
                        Console.Write("\r{0}/{1} completed.", humans.Count, wdqResult.items.Count());
                    }
                    var human = humanFactory.FromEntityId(id);
                    humans.Add(human);
                }
                catch (Exception ex)
                {
                    var t = new Tuple <int, Exception>(id, ex);
                    errors.Add(t);
                }
            }
            Console.WriteLine();
            Console.WriteLine("{0} humans found.", humans.Count);
            Console.WriteLine("Writing reports.");

            var livingSb = new StringBuilder();

            livingSb.AppendFormat("Name\tDoB\tAge\tLink");
            livingSb.AppendLine();
            var living = humans.Where(h => h.DateOfBirth != null && h.DateOfDeath == null).OrderByDescending(h => h.Age());

            foreach (var l in living)
            {
                livingSb.AppendFormat("{0}\t{1}\t{2}\t{3}", l.Label, l.DateOfBirth, l.Age(), l.WikiLink);
                livingSb.AppendLine();
            }
            File.WriteAllText("Living.txt", livingSb.ToString());
            Console.WriteLine("Reports finished.");
        }
Beispiel #26
0
    public Meeting(Gender gender, int number)
    {
        visitors = new Human[number];

        var factory = new HumanFactory();

        for (int i = 0; i < number; i++)
        {
            visitors[i] = humanFactory.Create(gender);
        }
        // Shorter:
        // visitors = Enumerable.Range(1, number)
        //     .Select(x => humanFactory.Create(gender))
        //     .ToArray();
    }
Beispiel #27
0
        public void TestJobSerialization()
        {
            this.Setup();
            MineJob job = new MineJob(new MagicalLifeAPI.DataTypes.Point2D(3, 6));

            HumanFactory humanFactory = new HumanFactory();
            Human        human        = humanFactory.GenerateHuman(new MagicalLifeAPI.DataTypes.Point2D(1, 3), 0, Guid.NewGuid());

            JobAssignedMessage message = new JobAssignedMessage(human, job);

            byte[] data = ProtoUtil.Serialize(message);
            Assert.IsNotNull(data);

            JobAssignedMessage result = (JobAssignedMessage)ProtoUtil.Deserialize(data);
        }
Beispiel #28
0
        protected override void GenerateDetails(ProtoArray <Chunk> map, Random r)
        {
            int chunkWidth  = map.Width;
            int chunkHeight = map.Height;

            int chunkX = StaticRandom.Rand(0, chunkWidth);
            int chunkY = StaticRandom.Rand(0, chunkHeight);

            int x = StaticRandom.Rand(0, Chunk.Width);
            int y = StaticRandom.Rand(0, Chunk.Height);

            HumanFactory hFactory = new HumanFactory();
            Point2D      location = new Point2D(((chunkX * Chunk.Width) + x), (chunkY * Chunk.Height) + y);

            map[chunkX, chunkY].Creatures.Add(hFactory.GenerateHuman(location, this.Dimension));
        }
Beispiel #29
0
        public void Init(int Humans, int Assassins)
        {
            var agentFactory = new AgentFactory();
            var humanFactory = new HumanFactory();

            for (int i = 0; i < Humans; i++)
            {
                humans.Add(humanFactory.CreateHuman());
            }

            for (int i = 0; i < Assassins; i++)
            {
                humans.Add(agentFactory.CreateHuman(humans));
            }

            field.Update(this.humans);
        }
Beispiel #30
0
        protected override ProtoArray <Chunk> GenerateDetails(ProtoArray <Chunk> map, Random r)
        {
            int chunkWidth  = map.Width;
            int chunkHeight = map.Height;

            int chunkX = StaticRandom.Rand(0, chunkWidth);
            int chunkY = StaticRandom.Rand(0, chunkHeight);

            int x = StaticRandom.Rand(0, Chunk.Width);
            int y = StaticRandom.Rand(0, Chunk.Height);

            HumanFactory hFactory = new HumanFactory();

            map[chunkX, chunkY].Creatures.Add(hFactory.GenerateHuman(new Point((chunkX * Chunk.Width) + x), (chunkY * Chunk.Height) + y));

            return(map);
        }
Beispiel #31
0
        static void Main(string[] args)
        {
            Human human = new Human("Louco", 24);

            Console.WriteLine(human.getString());

            Human copyhuman = (Human)human.Copy();

            Console.WriteLine(copyhuman.getString());

            HumanFactory factory = new HumanFactory(copyhuman);
            Human        h1      = factory.CopyHums();

            Console.WriteLine(h1.getString());

            Console.ReadLine();
        }