Пример #1
0
        static void Main(string[] args)
        {
            var stream = new StreamReader("../../1.txt");

            var forest = new Forest();

            var mapLoader = new MapLoader();
            mapLoader.Download(stream, out forest.map);

            var visualizer = new Visualizer(forest);

            var cr1 = new Creature('A', "Alice", 4, 5,3,7);
            //Console.WriteLine("{0} {1} {2}", cr1.X, cr1.Y, cr1.Lifes);

            var cr2 = new Creature('B', "BoBa", 4, 5,1,1);
            //var cr3 = new Creature('C',3,4,2);

            forest.AddCreature(cr1);
            //forest.AddCreature(cr2);

            //forest.TryToMove(cr1, new Left());
            //forest.TryToMove(cr1, new Left());
            //forest.TryToMove(cr1, new Up());

            //forest.TryToMove(cr2, new Left());
            //forest.TryToMove(cr2, new Left());
            //forest.TryToMove(cr2, new Up());

            //Console.WriteLine("{0} {1} {2}", cr1.X, cr1.Y, cr1.Lifes);
            var bot1 = new Bot(cr1, forest);
            bot1.GoToEnd();
        }
Пример #2
0
 public override bool CanStand(Creature creature, Direction direction)
 {
     creature.X += direction.dx;
     creature.Y += direction.dy;
     creature.Lifes++;
     return true;
 }
Пример #3
0
 public void Test2()
 {
     var stream = new StreamReader("../../2.txt");
     var forest = new Forest();
     var mapLoader = new MapLoader();
     mapLoader.Download(stream, out forest.map);
     var creature = new Creature('A', "Alice", 4, 5, 3, 7);
     forest.AddCreature(creature);
     var bot = new Bot(creature, forest);
     bot.GoToEnd();
     Assert.AreEqual(false, creature.IsAlive());
 }
Пример #4
0
        public bool AddCreature(Creature cr)
        {
            if (map[cr.EndX, cr.EndY].Name() == ' ')
            {
                var result = map[cr.X, cr.Y].TryCreate(cr);

                if (result)
                    OnChanged(EventArgs.Empty);

                return result;
            }
            return false;
        }
Пример #5
0
        public bool TryToMove(Creature creature, Direction direction)
        {
            while(creature.IsAlive())
            {
                var result = map[creature.X + direction.dx, creature.Y + direction.dy].CanStand(creature, direction);

                if (result)
                    OnChanged(EventArgs.Empty);

                return result;
            }
            Console.WriteLine("Move is impossible. {0} is dead", creature.Name);
            return false;
        }
Пример #6
0
 public override bool TryCreate(Creature creature)
 {
     Forest.AllCreatures.Add(creature);
     return true;
 }
Пример #7
0
 public override bool TryCreate(Creature creature)
 {
     return false;
 }
Пример #8
0
 public abstract bool TryCreate(Creature creature);
Пример #9
0
 public abstract bool CanStand(Creature creature, Direction direction);
Пример #10
0
 public override bool CanStand(Creature creature, Direction direction)
 {
     return false;
 }
Пример #11
0
 public Bot(Creature cr, Forest forest)
 {
     Creature = cr;
     OldLifes = cr.Lifes;
     Forest = forest;
 }