Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            FlyingCar car = new FlyingCar();

            car.Run();
            car.Fly();
            car.Company = "현대";

            IRunnable runnable = car as IRunnable;

            runnable.Run();

            IFlyable flyable = car as IFlyable;

            flyable.Fly();

            TestClass t = new TestClass();

            t.Run();

            IWalkable w = t as IWalkable;

            w.Run();

            IRunnable r = t as IRunnable;

            r.Run();
        }
Ejemplo n.º 2
0
 public AnimalBase(string name)
 {
     _name            = name;
     walkingBehavior  = new NoWalk();
     swimmingBehavior = new NoSwim();
     flyingBehavior   = new NoFly();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// ctor, initialize ai structures
        /// </summary>
        /// <param name="character">character of npc</param>
        /// <param name="position">position on which npc stands</param>
        /// <param name="terrain">terrain, where npc moves</param>
        /// <param name="entity">pointer on graphical representation of npc, used for changing position, making effects, ...</param>
        public NPC(CharacterNPC character, Vector3 position, IWalkable terrain, IControlable entity)
        {
            this.position3D = position;
            System.Drawing.Point xy = terrain.Get2DMapPosition(position);
            this.x         = xy.X;
            this.y         = xy.Y;
            this.character = character;

            this.visualRange = this.character.visualRange;

            this.currentStatus             = new Status();
            this.currentStatus.hp          = character.hp;
            this.currentStatus.mana        = character.mana;
            this.currentStatus.energy      = 100;
            this.currentStatus.position    = this.GetPosition2D();
            this.currentStatus.enemySeen   = 0;
            this.currentStatus.alive       = true;
            this.currentStatus.nearEnemies = new List <IActing>();

            this.entity    = entity;
            this.terrain   = terrain;
            this.taskStack = new Stack <NpcTask>();

            this.taskMove  = new Traveling(new Astar());
            this.fightMove = new Traveling(new Astar());

            this.targetCell = new System.Drawing.Point(x, y);
            this.aiMap      = Map.GetInstance();

            pathFinding = new Astar();

            this.entity.ChangePosition(position);
        }
Ejemplo n.º 4
0
        public GeneralNPC(CharacterNPC character, Vector3 position, IWalkable terrain, IControlable entity)
        {
            this.character  = character;
            this.terrain    = terrain;
            this.entity     = entity;
            this.position3D = position;
            this.position2D = terrain.Get2DMapPosition(this.position3D);
            this.taskStack  = new Stack <NpcTask>();
            this.taskMove   = new Traveling(new Astar());
            this.fightMove  = new Traveling(new Astar());

            //init start status
            this.currentStatus             = new Status();
            this.currentStatus.hp          = character.hp;
            this.currentStatus.mana        = character.mana;
            this.currentStatus.energy      = 100;
            this.currentStatus.position    = this.position2D;
            this.currentStatus.enemySeen   = 0;
            this.currentStatus.alive       = true;
            this.currentStatus.nearEnemies = new List <IActing>();

            this.targetCell = this.position2D;
            aiMap           = Map.GetInstance();
            this.npcMap     = aiMap.getRelatedMap(this.position2D, this.visualRange);
        }
Ejemplo n.º 5
0
    void Start()
    {
        IArchor[] archors = new IArchor[2];

        Orc  orc  = new Orc("오크 궁수", "옼!", 100);
        Hero hero = new Hero();

        archors[0] = orc;
        archors[1] = hero;

        foreach (var a in archors)
        {
            a.ShootBow();
        }

        IWalkable[] walkers = new IWalkable[2];
        Troll       troll   = new Troll("걷는 트롤", 150);

        walkers[0] = hero;
        walkers[1] = troll;

        foreach (var w in walkers)
        {
            w.Walk();
            Debug.Log("걸어온 거리 : " + w.walkedDistance);
        }
    }
Ejemplo n.º 6
0
        private static void IsInvalid(IWalkable element)
        {
            var errors    = new List <ParseError>();
            var validator = new ValidationTreeWalker(errors);

            element.Accept(validator);
            Assert.IsTrue(errors.Count > 0);
        }
Ejemplo n.º 7
0
 private void WriteItem(IWalkable item)
 {
     Intent();
     _writer.Write("- ");
     _level++;
     item.Accept(this);
     _level--;
 }
Ejemplo n.º 8
0
 public Cell(GameEngine game, Vector2 p, IWalkable w, IActivableComponent ac, IEnterExitComponent ee, string spriteName)
     : base(p)
 {
     this.walkableComponent = w;
     this.ac          = ac;
     this.eeComponent = ee;
     this.AttachDrawingComponant(game, spriteName, 1F);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Get instance of map, if this is not initializes, calls ctor()
 /// </summary>
 /// <param name="terrain">terrain, its, needed to create new instance</param>
 /// <returns></returns>
 public static Map GetInstance(IWalkable terrain)
 {
     if (instance == null)
     {
         instance = new Map(terrain);
     }
     return(instance);
 }
Ejemplo n.º 10
0
 private void WriteProperty(String name, IWalkable item)
 {
     Intent();
     _writer.Write("- ");
     _writer.Write(name);
     _writer.Write(": ");
     _level++;
     item.Accept(this);
     _level--;
 }
Ejemplo n.º 11
0
        public AICore(IWalkable terrain)
        {
            npcs         = new List <NPC>();
            fsms         = new List <Type>();
            this.terrain = terrain;
            control      = new ControlNPC();

            this.last = DateTime.Now;

            map = Map.GetInstance(terrain);

            LoadFsmPlugins("Plug-ins\\");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// private ctor - singleton
        /// </summary>
        /// <param name="terrain"></param>
        private Map(IWalkable terrain)
        {
            if (terrain == null)
            {
                return;
            }

            this.terrain   = terrain;
            this.heightMap = terrain.GetMap();

            cellMap             = new MapCellInfo[heightMap.GetLength(0), heightMap.GetLength(1)];
            size                = new System.Drawing.Point(this.heightMap.GetLength(0), this.heightMap.GetLength(1));
            this.playerPosition = terrain.GetPlayerPosition();
            npcsPosition        = new List <Point>();
            List <Point> blocked = terrain.GetBlockedPositions();

            Logging.Logger.AddInfo("Teren ma " + blocked.Count.ToString() + " blokovanych pozic");

            int x, y;

            x = cellMap.GetLength(0);
            y = cellMap.GetLength(1);
            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    bool bPlayer      = (terrain.GetPlayerPosition() == new System.Drawing.Point(i, j));
                    bool bFriendlyNPC = false;
                    bool bBlocked     = false; //(terrain.GetBlockedPositions()[i] == new System.Drawing.Point(i, j));
                    foreach (System.Drawing.Point p in blocked)
                    {
                        if (p == new System.Drawing.Point(i, j))
                        {
                            bBlocked = true;
                            blocked.Remove(p);
                            break;
                        }
                    }
                    if (heightMap[i, j] > this.maxHeight)
                    {
                        this.maxHeight = heightMap[i, j];
                    }
                    cellMap[i, j] = new MapCellInfo(heightMap[i, j], bPlayer, bFriendlyNPC, false, bBlocked, new System.Drawing.Point(i, j));
                }
            }
            bmp = new Bitmap(this.MapSize.X, this.MapSize.Y);
            Logging.Logger.AddInfo("AI: Nactena mapa");
        }
Ejemplo n.º 13
0
        public IEnumerator <IEdge <HexNode> > GetEnumerator()
        {
            List <IEdge <HexNode> > edges = new List <IEdge <HexNode> >();
            float   terrainMod            = movingUnit.GetTerrainWalkability(tile.Terrain).Modifier;
            float   rotateCost            = movingUnit.RotateCost * terrainMod;
            HexEdge turnLeft  = new HexEdge(rotateCost, new HexNode(GetValidDirection(direction, -1), tile, movingUnit, hexControl));
            HexEdge turnRight = new HexEdge(rotateCost, new HexNode(GetValidDirection(direction, 1), tile, movingUnit, hexControl));

            HexNode back    = null;
            HexNode forward = hexControl.GetNodeInFront(this);

            if (movingUnit.CanWalkBackwards)
            {
                back = hexControl.GetNodeBehind(this);
            }

            edges.Add(turnLeft);
            edges.Add(turnRight);
            if (forward != null)
            {
                IWalkable walkable = movingUnit.GetTerrainWalkability(forward.Tile.Terrain);
                float     cost     = ((terrainMod + walkable.Modifier) / 2);
                if (movingUnit.Flying && forward.Tile.AirUnitOnTile == null && walkable.Passable)
                {
                    edges.Add(new HexEdge(cost, forward));
                }
                else if (!movingUnit.Flying && forward.Tile.UnitOnTile == null && walkable.Passable)
                {
                    edges.Add(new HexEdge(cost, forward));
                }
            }
            if (back != null)
            {
                IWalkable walkable = movingUnit.GetTerrainWalkability(back.Tile.Terrain);
                float     cost     = ((terrainMod + walkable.Modifier) / 1.7f);
                if (movingUnit.Flying && back.Tile.AirUnitOnTile == null && walkable.Passable)
                {
                    edges.Add(new HexEdge(cost, back));
                }
                else if (!movingUnit.Flying && back.Tile.UnitOnTile == null && walkable.Passable)
                {
                    edges.Add(new HexEdge(cost, back));
                }
            }

            return(edges.GetEnumerator());
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            FlyingCar car = new FlyingCar();

            car.Run();
            car.Fly();
            car.Company = "현대";

            IRunnable runnable = car as IRunnable;  //형변환 안되면 null값 들어감

            runnable.Run();

            IFlyable flyable = car as IFlyable;

            flyable.Fly();

            IWalkable walkable = car as IWalkable;

            walkable.Run();
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            Duck    duck    = new Duck();
            Penguin penguin = new Penguin();
            Dolphin dolphin = new Dolphin();

            duck.Move();
            duck.Eat();

            penguin.Move();
            penguin.Eat();

            dolphin.Move();
            dolphin.Eat();


            IFlyable duck2 = duck as IFlyable;

            duck2.Fly();

            IWalkable penguin2 = penguin as IWalkable;

            penguin2.Walk();

            ISwimable dolphin2 = dolphin as ISwimable;

            dolphin2.Swim();


            string direction = Direction.down.ToString();

            duck.Move(direction);

            direction = Direction.up.ToString();
            penguin.Move(direction);


            Console.ReadKey();
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            //FlyingCar car = new FlyingCar();
            //car.Run();
            //car.Fly();
            //car.Company = "현대";

            //IRunnable runnable = car as IRunnable;
            //runnable.Run();

            //IFlyable flyable = car as IFlyable;
            //flyable.Fly();

            TestClass test = new TestClass();

            test.Run();

            IWalkable w = test as IWalkable;

            w.Run(30);
            IRunnable t = test as IRunnable;

            t.Run();
        }
Ejemplo n.º 17
0
 Animal(IWalkable walkableProvider = null, IHuntable huntableProvider = null, IHibernatable hibernatableProvider = null)
 {
     this.walkableProvider     = walkableProvider;
     this.hibernatableProvider = hibernatableProvider;
     this.huntableProvider     = huntableProvider;
 }
Ejemplo n.º 18
0
 // We declare the parameter as IWalkable,
 // so any object that implements IWalkable can be passed in
 static void WalkInMeters(IWalkable o, int meters)
 {
     o.Walk(meters);
 }