Esempio n. 1
0
        public string NotifyMessage(string language = null)//Message message)
        {
            INotifier notifier     = new ConsoleNotifier();
            string    notifierType = "none";

            try
            {
                notifierType = ConfigurationManager.AppSettings["NotifierType"];
            }
            catch (Exception) { }

            Message message = GetNotificationMessage();// Language.GetFromResourceFile("BaseHelloMessage");// "Hello World";


            if (notifierType.ToUpper().Trim() == "CONSOLE")
            {
                notifier = new ConsoleNotifier();
            }
            else if (notifierType.ToUpper().Trim() == "FILE")
            {
                notifier = new FileNotifier();
            }
            else if (notifierType.ToUpper().Trim() == "DB")
            {
                notifier = new DBNotifier();
            }
            else
            {
                notifier = new Notifier();
            }
            return(NotifyMessage(message, notifier));
        }
Esempio n. 2
0
        private static Hero GenerateHero(ConsoleNotifier myConsole, Random myRandom)
        {
            Hero hero;
            var  heroName   = GenerateName(myRandom);
            var  heroHealth = myRandom.Next(50, 151);
            var  heroSpeed  = myRandom.Next(0, 101);

            var heroType = myRandom.Next(1, 4);

            switch (heroType)
            {
            case 1:
                var heroPrecision = myRandom.Next(10, 51);
                hero = new Warrior(myConsole, heroName, heroHealth, heroSpeed, heroPrecision);
                break;

            case 2:
                var heroPower = myRandom.Next(25, 76);
                hero = new Wizard(myConsole, heroName, heroHealth, heroSpeed, heroPower);
                break;

            case 3:
                var heroStrength = myRandom.Next(5, 26);
                hero = new Ork(myConsole, heroName, heroHealth, heroSpeed, heroStrength);
                break;

            default:
                throw new NotImplementedException();
            }

            return(hero);
        }
Esempio n. 3
0
        public async Task Basic()
        {
            var writer = new StringWriter();

            Console.SetOut(writer);

            var notifier = new ConsoleNotifier(TestFormatter.Instance);
            await notifier.NotifyCounterexampleAsync(new Counterexample(Mock.Of <MethodInfo>(), new List <Argument>()));

            var output = writer.ToString();

            Assert.IsTrue(output.Contains(TestFormatter.GeneratedString));
        }
Esempio n. 4
0
        private static List <Hero> GenerateHorde(ConsoleNotifier myConsole)
        {
            var myRandom = new Random();
            var myHorde  = new List <Hero>();

            var numberOfHeroes = myRandom.Next(2, 11); // genero un numero casuale di eroi tra 2 e 10

            for (int i = 1; i <= numberOfHeroes; i++)
            {
                Hero hero = GenerateHero(myConsole, myRandom);
                myHorde.Add(hero);
            }

            return(myHorde);
        }
Esempio n. 5
0
        // ## 13.1 - ARENA - simpler version
        // We have an arena with different characters fighting one against the other.
        //
        // Every character has an epic name, an amount of health-points, and a speed.When he is attacked, he loses a certain amount of health-point.
        //
        // There are 3 types of character:
        // 1) `Warrior`: has a property `DamagePercentage`, that tells which percentage of health-points is removed from the adversary: if the adversary has 80 hp and the percentage is 10%, the attack will subtract 8 hp.Is the hp to remove are less than 5, the attack removes exactly 5 hp.
        // 2) `Wizard`: has a property `MaximumPower`, that tells the max magical power available, ma magic is a mistery, so the hp to remove are calculated every time multiplying the max power with a random number between 0 and 1.
        // 3) `Ork`: has a property `Strength`, that tells how many fixed hp are removed from the adversary.
        //
        // The game is divided in turns.At every turn, every character has the possibility to fight.
        //
        // The characters attack in order of speed: the faster obviously attacks first.The game select a target randomly between the other fighters(a character cannot attack himself or a dead character).
        //
        // When a character finishes its health - points, he dies.
        //
        // The last living character wins.
        //
        // The Arena class receives a list of characters, and has a method `StartFight` in which it handles the turns and calculates the winner.
        //
        // Create a list of characters, with different types, names, strength, etc.
        //
        // Create an instance of the Arena, passing the list of characters, and start the game.
        //
        // Every time something happens(a character strikes, a character dies, a character wins, ...) a message is printed on the Console(ex: `"The Ork Gurg attacked Gandalf il Grigio taking 20 hp"`).
        //
        // The characters can print on the Console, and so can the Arena.
        //
        //
        // ## 13.2 ARENA - more object oriented *
        // As 13.1, but we want to decouple the operations from the printing on the Console.
        //
        // Every class (the classes for the fighters and the Arena) receive in the constructor an instance of an `INotifier`, an interface with a method `Notify(string message)`. Every time an object has something to notify(ex: a warrior died), the `Notify()` method is called.
        //
        // Since it's just an interface, the other objects don't know where these messages are going.
        //
        // Create a class `ConsoleNotifier` that implements `INotifier` and prints on the Console the messages.
        //
        // Instantiate this class in the `Main()`, and pass it to all the other objects.
        //
        // Then start the game.
        //
        #endregion

        // Ho scelto questo come terzo esercizio perché ha un po' tutto quello che abbiamo visto finora: ereditarietà,
        // polimorfismo, classi astratte, interfacce...
        // E anche perché sono nerd nell'animo.

        // Ho fatto un uso molto empirico dei random, ho capito in teoria come funzionano ma non sono molto sicura nell'applicazione

        static void Main(string[] args)
        {
            var myConsole = new ConsoleNotifier();              // creo il mio notificatore

            myConsole.SetName("Arena");                         // assegno il nome al notificatore
            var myArena = new Arena(myConsole);                 // creo l'arena (vuota), indicandole a chi deve inviare le notifiche

            while (true)                                        // non ho implementato metodi per accettare un input, per ora lo lascio in ciclo infinito
            {
                myConsole.Refresh();                            // svuoto il notificatore per un nuovo combattimento

                List <Hero> myHorde = GenerateHorde(myConsole); // Creo una lista casuale di eroi; tutti faranno riferimento al notificatore myConsole
                myArena.Horde = myHorde;                        // assegno l'orda all'arena

                myArena.StartToFight();                         // inizio il cobattimento
                myConsole.Wait();                               // alla fine, metto il notificatore in wait prima di iniziare un nuovo combattimento
            }
        }
Esempio n. 6
0
        public string Notify(IConfigurationManager configurationManager)
        {
            if (configurationManager == null)
            {
                throw new ArgumentNullException("configurationManager");
            }

            INotifier notifier     = new ConsoleNotifier();
            string    notifierType = "none";

            try
            {
                notifierType = configurationManager.GetAppSetting("NotifierType");
                // notifierType =  ConfigurationManager.AppSettings["NotifierType"];
            }
            catch (Exception) { }

            Message message = new Message();

            message.messageText = Language.GetFromResourceFile("BaseHelloMessage");// "Hello World";


            if (notifierType.ToUpper().Trim() == "CONSOLE")
            {
                notifier = new ConsoleNotifier();
            }
            else if (notifierType.ToUpper().Trim() == "FILE")
            {
                notifier = new FileNotifier();
            }
            else if (notifierType.ToUpper().Trim() == "DB")
            {
                notifier = new DBNotifier();
            }
            else
            {
                notifier = new Notifier();
            }
            return(NotifyMessage(message, notifier));
        }
Esempio n. 7
0
 public CommandLineOptionsWithLog(ILogWriter writer, ILogTableRequestResponse logTableRequestResponse, params string[] args) : base(args)
 {
     this.log        = new ConsoleNotifier(this.verboseLoggingEnabled(), writer);
     this.trafficLog = new TrafficLog(args.Contains("--print-all-network-traffic"), writer, logTableRequestResponse);
 }