Exemple #1
0
        static void Main(string[] args)
        {
            var mike = new PlayerCharacter(new LeatherArmorDefense())
            {
                Name = "Mike"
            };

            var sara = new PlayerCharacter(new DragonArmorDefense())
            {
                Name = "Sara"
            };

            var aaron = new PlayerCharacter(new NullDefense())
            {
                Name = "Aaron"
            };

            var james = new PlayerCharacter(SpecialDefense.Null)
            {
                Name = "James"
            };

            var carol = new PlayerCharacter(SpecialDefense.Null)
            {
                Name = "Carol"
            };

            mike.Hit(30);
            sara.Hit(30);
            aaron.Hit(30);
            james.Hit(30);
            carol.Hit(30);

            Console.ReadLine();
        }
        public static void Write(PlayerCharacter player)
        {

            Console.WriteLine(string.IsNullOrWhiteSpace(player.Name)
                ? "Player name cannot be null or have only white space"
                : $"Name: {player.Name}");

            int days = player.DaysSinceLastLogin ?? -1;
            Console.WriteLine($"{days} days in last login");

            //Console.WriteLine(!player.DaysSinceLastLogin.HasValue
            //    ? "No value for DaysSinceLastLogin"
            //    : $"Days since last login: {player.DaysSinceLastLogin}");

            Console.WriteLine(!player.DateOfBirth.HasValue
                ? "No DateOfBirth has been specified"
                : $"Date of birth: {player.DateOfBirth.Value.ToShortDateString()}");

            Console.WriteLine(!player.IsNoob.HasValue
                ? "Player newbie status is unknown"
                : $"Is noob: {player.IsNoob}");


        }