当前位置: 首页>>代码示例>>C#>>正文


C# Unit.getVillage方法代码示例

本文整理汇总了C#中Unit.getVillage方法的典型用法代码示例。如果您正苦于以下问题:C# Unit.getVillage方法的具体用法?C# Unit.getVillage怎么用?C# Unit.getVillage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Unit的用法示例。


在下文中一共展示了Unit.getVillage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: checkNeighboursForGuards

    public bool checkNeighboursForGuards(Tile center, Unit unit)
    {
        List<Tile> neighbours = center.getNeighbours ();
        UnitType unitType = unit.getUnitType();
        Village unitVillage = unit.getVillage ();
        Player unitVillagePlayer = unitVillage.getPlayer ();

        foreach (Tile n in neighbours)
        {
            Unit neighbouringUnit = n.getOccupyingUnit();
            if(neighbouringUnit != null)
            {
                UnitType neighbourUnitType = neighbouringUnit.getUnitType();
                Village neighbourVillage = neighbouringUnit.getVillage ();
                Player neighbourPlayer = neighbourVillage.getPlayer ();
                if(unitType <= neighbourUnitType && unitVillagePlayer != neighbourPlayer)
                {
                    return true;
                }
            }
            bool hasTower = n.checkTower ();
            if (hasTower && unitType > UnitType.INFANTRY){
                return true;
            }
        }
        return false;
    }
开发者ID:hysoftwareeng,项目名称:MedievalWarfare,代码行数:27,代码来源:TileManager.cs

示例2: fireCannon

    public void fireCannon(Unit cannon, Tile t)
    {
        Player you = cannon.getVillage ().controlledBy;
        Player them;
        if (t.getVillage () != null) { // stupid null checks to prevent errors
            them = t.getVillage ().controlledBy;
        } else { // check if neutral
            gameGUI.displayError (@"No need to fire on neutral land");
            return;
        }
        if (you == them) { // dont fire on yourself
            gameGUI.displayError (@"Dont shoot yourself!!");
            return;
        } else { // finally, give em hell!
            bool hasTower = t.checkTower ();
            Unit u = t.getOccupyingUnit();
            Village v = t.getVillage ();
            Tile l = v.getLocatedAt();
            if (hasTower == true){
        //				t.replace (null);
                t.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered);
                t.networkView.RPC ("setStructureNet",RPCMode.AllBuffered,false);
            }
            if (u!=null){
        //				v.removeUnit(u);
                v.networkView.RPC ("removeUnitNet",RPCMode.AllBuffered,u.networkView.viewID);
        //				t.setOccupyingUnit(null);
                t.networkView.RPC ("removeOccupyingUnitNet",RPCMode.AllBuffered);
        //				t.replace (null);
        //				t.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered);
        //				t.setLandType(LandType.Tombstone);
                t.gameObject.networkView.RPC ("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Tombstone);
                GameObject tomb = Network.Instantiate (tombPrefab, new Vector3 (t.point.x, 0.4f, t.point.y), tombPrefab.transform.rotation,0) as GameObject;
                t.networkView.RPC ("replaceTilePrefabNet",RPCMode.AllBuffered,tomb.networkView.viewID);
        //				Destroy (u.gameObject);
                gameObject.networkView.RPC ("destroyUnitNet",RPCMode.AllBuffered,u.networkView.viewID);
            }
            if (t==l){
                villageManager.takeCannonDamage(v);
            }

        }
    }
开发者ID:hysoftwareeng,项目名称:MedievalWarfare,代码行数:43,代码来源:UnitManager.cs

示例3: performMove

    private void performMove(Unit unit, Tile dest)
    {
        dest.gameObject.networkView.RPC ("setOccupyingUnitNet", RPCMode.AllBuffered, unit.gameObject.networkView.viewID);
        unit.gameObject.networkView.RPC ("setLocationNet", RPCMode.AllBuffered, dest.gameObject.networkView.viewID);
        Village srcVillage = unit.getVillage ();
        UnitType srcUnitType = unit.getUnitType();
        LandType destLandType = dest.getLandType ();

        if (destLandType == LandType.Meadow)
        {
            if (srcUnitType==UnitType.CANNON||srcUnitType==UnitType.SOLDIER||srcUnitType==UnitType.KNIGHT)
            {
                if (dest.hasRoad)
                {
                    unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.Moved);
                }
                else
                {
                    gameGUI.displayError (@"You have trampled the crops!");
                    dest.gameObject.networkView.RPC ("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Grass);
                    dest.gameObject.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered);
                }
                if (srcUnitType == UnitType.CANNON)
                {
                    unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.CannonMoved);
                }
            }
        }
        else if (destLandType == LandType.Trees)
        {
            dest.gameObject.networkView.RPC ("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Grass);
            unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.ChoppingTree);
            srcVillage.gameObject.networkView.RPC ("addWoodNet",RPCMode.AllBuffered,1);
            dest.gameObject.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered);
        }
        else if (destLandType == LandType.Tombstone)
        {
            dest.gameObject.networkView.RPC ("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Grass);
            unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.ClearingTombstone);
            dest.gameObject.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered);
        }
        //movePrefab (unit,new Vector3 (dest.point.x, 0.15f,dest.point.y));
        this.gameObject.networkView.RPC ("moveUnitPrefabNet", RPCMode.AllBuffered, unit.networkView.viewID, new Vector3 (dest.point.x, 0.15f, dest.point.y));
    }
开发者ID:hysoftwareeng,项目名称:MedievalWarfare,代码行数:44,代码来源:UnitManager.cs

示例4: canUnitMove

 private bool canUnitMove(Unit u, Tile t)
 {
     // castle check
     foreach (Tile n in t.getNeighbours()) {
         try{
             Village v = n.getVillage ();
             VillageType vt = v.getMyType();
             Player them = v.getPlayer ();
             Player you = u.getVillage().getPlayer ();
             if (them!=you && vt==VillageType.Castle){
                 gameGUI.displayError (@"I cant even get near to their castle!");
                 return false;
             }
         } catch {
             continue;
         }
     }
     // friendly checks
     if (t.getVillage ()==null || t.getVillage ().controlledBy == u.getVillage ().controlledBy) {
         if((t.getLandType () == LandType.Trees || t.getLandType () == LandType.Tombstone) && (u.getUnitType() == UnitType.KNIGHT || u.getUnitType() == UnitType.CANNON)){
             gameGUI.displayError (@"Knights are too fancy to do manual labour. ¯\(°_o)/¯");
             return false;
         } else if (t.checkTower ()){
             gameGUI.displayError (@"The tower doesn't want you to stand ontop of it. ¯\(°_o)/¯");
             return false;
         } else if (t.getOccupyingUnit () != null) {
             gameGUI.displayError (@"There is a unit already standing there!!! ¯\(°_o)/¯");
             return false;
         } else {
             return true;
         }
         // enemy checks
     } else if (t.getVillage ().controlledBy != u.getVillage ().controlledBy){
         if (u.getUnitType()==UnitType.PEASANT){
             gameGUI.displayError (@"Peasants cant attack! ¯\(°_o)/¯");
             return false;
         } else if (u.getUnitType()==UnitType.CANNON){
             gameGUI.displayError (@"Cannons cant move into enemy territory");
             return false;
         } else if((t.getLandType () == LandType.Trees || t.getLandType () == LandType.Tombstone) && u.getUnitType() == UnitType.KNIGHT){
             gameGUI.displayError (@"Knights are too fancy to do manual labour. ¯\(°_o)/¯");
             return false;
         } else if (t.checkTower () == true && (u.getUnitType()!= UnitType.KNIGHT || u.getUnitType () != UnitType.SOLDIER)){
             gameGUI.displayError (@"Only a soldiers and knights can destroy an enemy tower. ¯\(°_o)/¯");
             return false;
         } else if (t.getOccupyingUnit()!=null && u.getUnitType()<=t.getOccupyingUnit().getUnitType()){
             if (t.getOccupyingUnit().getUnitType()==UnitType.CANNON && u.getUnitType()<=UnitType.SOLDIER){
                 gameGUI.displayError (@"You need a knight to take out their cannon");
                 return false;
             }
             gameGUI.displayError (@"Your unit cant fight theirs. ¯\(°_o)/¯");
             return false;
         } else {
             return true;
         }
     }
     //default
     return false;
 }
开发者ID:hysoftwareeng,项目名称:MedievalWarfare,代码行数:59,代码来源:UnitManager.cs

示例5: upgradeUnit

    public void upgradeUnit(Unit u, UnitType newLevel)
    {
        Village unitVillage = u.getVillage();
        VillageType unitVillageLevel = unitVillage.getMyType();
        UnitType unitType = u.getUnitType();
        UnitActionType unitAction = u.getAction();
        int goldAvailable = unitVillage.getGold();
        int goldRequired = (newLevel - unitType) * TEN;
        if (unitType == UnitType.KNIGHT) {
            gameGUI.displayError (@"The Knight is already your strongest warrior! ¯\(°_o)/¯");
        }
        else if((goldAvailable >= goldRequired)&&(newLevel > unitType)&&(unitAction == UnitActionType.ReadyForOrders || unitAction == UnitActionType.Moved))
        {
            if(newLevel == UnitType.SOLDIER && unitVillageLevel < VillageType.Town)
            {
                gameGUI.displayError (@"Please upgrade your village to a Town first. ¯\(°_o)/¯");
            }
            else if(newLevel == UnitType.KNIGHT && unitVillageLevel < VillageType.Fort)
            {
                gameGUI.displayError (@"Please upgrade your village to a Fort first. ¯\(°_o)/¯");
            }
            else
            {
                u.networkView.RPC("switchUnitPrefabNet",RPCMode.AllBuffered,(int)newLevel);
                u.networkView.RPC("setUnitTypeNet",RPCMode.AllBuffered,(int)newLevel);
                u.networkView.RPC ("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.UpgradingCombining);
                unitVillage.networkView.RPC ("setGoldNet",RPCMode.AllBuffered,(goldAvailable - goldRequired));
        //				u.upgrade(newLevel);

            }
        }
    }
开发者ID:hysoftwareeng,项目名称:MedievalWarfare,代码行数:32,代码来源:UnitManager.cs

示例6: moveUnit

    public void moveUnit(Unit unit, Tile dest)
    {
        Village destVillage = dest.getVillage ();
        Village srcVillage = unit.getVillage ();

        Unit destUnit = dest.getOccupyingUnit ();
        UnitType srcUnitType = unit.getUnitType();

        bool unitPermitted = canUnitMove (unit, dest);

        //if the move is allowed to move onto the tile
        if (unitPermitted == true)
        {
            Tile originalLocation = unit.getLocation ();
            // moving within your region
            if (srcVillage == destVillage)
            {
                performMove(unit,dest);
                originalLocation.gameObject.networkView.RPC ("removeOccupyingUnitNet",RPCMode.AllBuffered);
                //TODO STOPPED HERE
            }
            else if (srcVillage != destVillage)
            {
                // taking over neutral tiles
                if (destVillage == null)
                {
                    //srcVillage.addTile(dest);
                    srcVillage.gameObject.networkView.RPC ("addTileNet",RPCMode.AllBuffered,dest.gameObject.networkView.viewID);
                    dest.gameObject.networkView.RPC ("setVillageNet",RPCMode.AllBuffered,srcVillage.gameObject.networkView.viewID);
                    int color = srcVillage.getPlayer().getColor();
                    dest.gameObject.networkView.RPC ("setAndColor",RPCMode.AllBuffered,color);

                    performMove(unit,dest);
                    villageManager.MergeAlliedRegions(dest);
                    unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.CapturingNeutral);
                    originalLocation.gameObject.networkView.RPC ("removeOccupyingUnitNet",RPCMode.AllBuffered);
                }

                else if (srcUnitType == UnitType.PEASANT)
                {
                    gameGUI.displayError (@"A peasant is too weak to invade!");
                    return;
                }
                else
                {
                    // quit if tile is guarded by unit or tower
                    bool guarded = tileManager.checkNeighboursForGuards(dest, unit);
                    if (guarded){
                        gameGUI.displayError (@"That area is being protected");
                        return;
                    }
                    // unit on unit combat!!
                    if (destUnit!=null){
                        if(srcUnitType>destUnit.getUnitType()){
                            // kill enemy unit, remove it from tile, remove it from village, perform move gets called after.
                            destVillage.gameObject.networkView.RPC ("removeUnitNet",RPCMode.AllBuffered,destUnit.gameObject.networkView.viewID);
                            dest.gameObject.networkView.RPC ("setOccupyingUnitNet",RPCMode.AllBuffered,unit.gameObject.networkView.viewID);
                            gameObject.networkView.RPC ("destroyUnitNet",RPCMode.AllBuffered,destUnit.gameObject.networkView.viewID);

                        } else {
                            gameGUI.displayError (@"The enemy is too strong! I dont want to die!");
                            return;
                        }
                    }
                    // if the tile contains the enemy village
                    // pillage, then move the hovel
                    if (destVillage.getLocatedAt()==dest){
                        if (srcUnitType > UnitType.INFANTRY){
                            // plunder village will handle stealing resources
                            villageManager.plunderVillage (srcVillage, destVillage, dest);
                            // it also calls respawn hovel and creating a meadow
                        } else {
                            gameGUI.displayError (@"This unit is too weak to plunder villages");
                            return;
                        }
                    }
                    // destroy towers
                    if (dest.checkTower() == true && srcUnitType>UnitType.INFANTRY){
                        //dest.setStructure(null);
                        dest.gameObject.networkView.RPC ("setStructureNet",RPCMode.AllBuffered,false);
                        //dest.replace (null);
                        //dest.gameObject.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered);
                    }

                    villageManager.takeoverTile(srcVillage,dest); //also splits region
                    villageManager.MergeAlliedRegions(dest);
                    performMove(unit,dest);
                    unit.gameObject.networkView.RPC("setActionNet",RPCMode.AllBuffered,(int)UnitActionType.CapturingEnemy);
                    originalLocation.gameObject.networkView.RPC ("removeOccupyingUnitNet",RPCMode.AllBuffered);

                }
            }
        }
    }
开发者ID:hysoftwareeng,项目名称:MedievalWarfare,代码行数:94,代码来源:UnitManager.cs


注:本文中的Unit.getVillage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。