示例#1
0
 public CreatureFactoryDecoratorTests()
 {
     _world   = new World(10, 10);
     _world2  = new World(10, 10);
     _logger  = new JsonTraceListener("UnitTestLog.json");
     _factory = new CreatureFactory(_world, _logger);
 }
        /// <summary>
        /// Instantiates a TraceSource and creates and adds listeners to the it.
        /// See Configuration.xml to change the level at which to log.
        /// </summary>
        private static TraceSource InitialiseTraceListener()
        {
            TraceSource theTraceSource = new TraceSource("2DTurnBasedGameFramework", LoadConfig.SourceLevel());

            theTraceSource.Switch = new SourceSwitch("2DTurnBasedGameFramework", LoadConfig.SourceLevel().ToString());

            // Text listener
            string loggerFilePath = Directory.GetCurrentDirectory() + "/Log.txt";

            using StreamWriter sw = new StreamWriter(File.Create(loggerFilePath))
                  {
                      AutoFlush = true
                  };
            TraceListener textListener = new TextWriterTraceListener(sw);

            theTraceSource.Listeners.Add(textListener);
            // BUG: Make textListener work... It generates the file, but does not seem to write to it.

            // Json listener
            string        jsonLoggerFilePath = Directory.GetCurrentDirectory() + "/Log.json";
            TraceListener jsonListener       = new JsonTraceListener(jsonLoggerFilePath);

            theTraceSource.Listeners.Add(jsonListener);

            return(theTraceSource);
        }
示例#3
0
 public Game(int worldMaxX, int worldMaxY)
 {
     Logger          = new JsonTraceListener();
     World           = new World(worldMaxX, worldMaxY);
     ItemFactory     = new ItemFactory();
     CreatureFactory = new CreatureFactory(World, Logger);
     Controller      = new Controller(ref World);
     rnd             = new Random();
     _draw           = new WorldDrawing(World);
 }
示例#4
0
 public CreatureFactory(World world, JsonTraceListener logger)
 {
     config  = XMLReader.ReadGameConfiguration <XmlConfigurations>();
     _logger = logger;
     _world  = world;
     if (config is null || config.EnemyNamesList.Count == 0)
     {
         NameArr = new List <string>()
         {
             "Orc", "Troll", "Dark Elf"
         };
     }
示例#5
0
 public CreatureAttackTests()
 {
     _logger     = new JsonTraceListener();
     _world      = new World(5, 5);
     _crtFactory = new CreatureFactory(_world, _logger);
     _itmFactory = new ItemFactory();
     _enemy      = _crtFactory.CreateEnemyCreature("boss", new Position(1, 1)) as EnemyCreature;
     _player     = _crtFactory.CreatePlayerCreature("Bilbo", new Position(2, 1)) as PlayerCreature;
     _world.WorldPlayGround[_enemy.Position.X, _enemy.Position.Y].Creature   = _enemy;
     _world.WorldPlayGround[_player.Position.X, _player.Position.Y].Creature = _player;
     _player.AttackItems.AddAttackItem(new Sword(40, "Sting"));
     _player.AttackItems.AddAttackItem(new Sword(40, "Sting"));
 }