本文整理汇总了C#中Tile.getNeighbours方法的典型用法代码示例。如果您正苦于以下问题:C# Tile.getNeighbours方法的具体用法?C# Tile.getNeighbours怎么用?C# Tile.getNeighbours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tile
的用法示例。
在下文中一共展示了Tile.getNeighbours方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: CreateComponent
//constructor
public static Unit CreateComponent( UnitType unitType, Tile location, Village v, GameObject PeasantPrefab )
{
Tile toplace = null;
foreach (Tile a in location.getNeighbours())
{
if(a.prefab == null && a.getOccupyingUnit() == null && a.getColor() == location.getColor())
{
toplace = a;
}
}
if(toplace == null)
{
toplace = location;
}
GameObject o = Instantiate(PeasantPrefab, new Vector3(toplace.point.x, 0.15f, toplace.point.y), toplace.transform.rotation) as GameObject;
Unit theUnit = o.AddComponent<Unit>();
theUnit.locatedAt = toplace;
theUnit.myType = unitType;
theUnit.myVillage = v;
theUnit.myAction = UnitActionType.ReadyForOrders;
location.setOccupyingUnit (theUnit);
return theUnit;
}
示例3: searchVillagesLoad
// public void loadVillage(){
// string id = "1";
// string name = "savedName";
// string pID = "PlayerID";
// string pNum = "NumberOfPlayers";
// string clr = "Color";
//
// //village data names
// string vID = "VillageID";
// string vNum = "NumberOfVillage";
// string gold = "Gold";
// string wood = "Wood";
// string health = "Health";
//
// string locationx= "Locationx";
// string locationy= "Locationy";
//
// //get number of villages per player:
//
//
//
// }
//Searching for tiles that belong to this village: copied from MapGenerator
public void searchVillagesLoad(Tile toSearch, List<Tile> TilesToReturn, int color )
{
foreach( Tile n in toSearch.getNeighbours() )
{
if(n.getVisited() == false && n.getColor() == color)
{
n.setVisited( true );
TilesToReturn.Add(n);
searchVillagesLoad(n, TilesToReturn, color);
}
}
}
示例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;
}
示例5: splitRegion
private void splitRegion(Tile splitTile, Village villageToSplit)
{
List<List<Tile>> lstRegions = new List<List<Tile>>();
int oldWood = villageToSplit.getWood ();
int oldGold = villageToSplit.getGold ();
Tile oldLocation = villageToSplit.getLocatedAt ();
Player p = villageToSplit.getPlayer();
// prep for BFS
foreach (Tile t in villageToSplit.getControlledRegion()) {
t.setVisited(false);
}
// build connected regions
foreach (Tile t in splitTile.getNeighbours()) {
if (t.getVillage()==villageToSplit && !t.getVisited()){
List<Tile> newRegion = new List<Tile>();
t.setVisited(true);
newRegion.Add (t);
splitBFS (t,villageToSplit,newRegion);
if (newRegion.Count<3){
Neutralize (newRegion);
} else{
lstRegions.Add (newRegion);
}
}
}
print ("after the bfs");
if (lstRegions.Count <= 0) {
Debug.Log ("Inside Regions <= 0");
oldLocation.gameObject.networkView.RPC ("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Meadow);
GameObject meadow = Network.Instantiate (meadowPrefab, new Vector3 (oldLocation.point.x, 0, oldLocation.point.y), meadowPrefab.transform.rotation,0) as GameObject;
villageToSplit.retireAllUnits();
Debug.Log ("after retire all units");
p.networkView.RPC ("removeVillageNet",RPCMode.AllBuffered,villageToSplit.networkView.viewID,p.getColor());
oldLocation.networkView.RPC ("replaceTilePrefabNet",RPCMode.AllBuffered,meadow.networkView.viewID);
Debug.Log ("after lstRegions <= 0");
return; //stop here if no region is big enough
}
int splitWood = oldWood/lstRegions.Count;
int splitGold = oldGold/lstRegions.Count;
//create new villages
foreach(List<Tile> region in lstRegions)
{
print ("creating new village");
Vector3 hovelLocation;
Tile tileLocation;
if (region.Contains (oldLocation)){
tileLocation = oldLocation;
hovelLocation = new Vector3(tileLocation.point.x, 0.1f, tileLocation.point.y);
} else {
tileLocation = getTileForRespawn(region);
hovelLocation = new Vector3(tileLocation.point.x, 0.1f, tileLocation.point.y);
}
GameObject newTown = Network.Instantiate(hovelPrefab, hovelLocation, hovelPrefab.transform.rotation, 0) as GameObject;
Village v = newTown.GetComponent<Village>();
//tileLocation.replace (newTown);
tileLocation.networkView.RPC ("switchTilePrefabNet",RPCMode.AllBuffered,newTown.networkView.viewID);
v.addRegion (region); //adds T<>V and any U<>V
// v.setLocation (tileLocation);
v.gameObject.networkView.RPC ("setLocationNet",RPCMode.AllBuffered,tileLocation.networkView.viewID);
// p.addVillage(v);
p.gameObject.networkView.RPC ("addVillageNet",RPCMode.AllBuffered,v.networkView.viewID,p.getColor ());
// v.setControlledBy(p);
GameManager GM = GameObject.Find ("preserveGM").GetComponent<GameManager>();
int playerIndex = GM.findPlayerIndex(p);
v.gameObject.networkView.RPC ("setControlledByNet",RPCMode.AllBuffered,playerIndex);
if (region.Contains (oldLocation)){
VillageType vType = villageToSplit.getMyType();
//v.setMyType(vType);
v.gameObject.networkView.RPC ("setVillageTypeNet",RPCMode.AllBuffered,(int)vType);
if (vType == VillageType.Hovel)
{
// newTown.transform.FindChild("Hovel").gameObject.SetActive (true);
// newTown.transform.FindChild("Town").gameObject.SetActive (false);
// newTown.transform.FindChild("Fort").gameObject.SetActive (false);
// newTown.transform.FindChild("Castle").gameObject.SetActive (false);
newTown.gameObject.networkView.RPC ("switchPrefabNet",RPCMode.AllBuffered,(int)vType);
}
else if (vType == VillageType.Town)
{
// newTown.transform.FindChild("Hovel").gameObject.SetActive (false);
// newTown.transform.FindChild("Town").gameObject.SetActive (true);
// newTown.transform.FindChild("Fort").gameObject.SetActive (false);
// newTown.transform.FindChild("Castle").gameObject.SetActive (false);
newTown.gameObject.networkView.RPC ("switchPrefabNet",RPCMode.AllBuffered,(int)vType);
}
else if (vType == VillageType.Fort)
{
// newTown.transform.FindChild("Hovel").gameObject.SetActive (false);
// newTown.transform.FindChild("Town").gameObject.SetActive (false);
// newTown.transform.FindChild("Fort").gameObject.SetActive (true);
// newTown.transform.FindChild("Castle").gameObject.SetActive (false);
//.........这里部分代码省略.........
示例6: splitBFS
// takes in a list, and builds it up with connected tiles
private void splitBFS(Tile tiletoSearch, Village villageToSplit, List<Tile> tilesToReturn)
{
foreach (Tile n in tiletoSearch.getNeighbours()){
if (n.getVillage()==villageToSplit && !n.getVisited()){
n.setVisited( true );
tilesToReturn.Add(n);
splitBFS (n, villageToSplit, tilesToReturn);
}
}
}
示例7: MergeAlliedRegions
public void MergeAlliedRegions(Tile newTile)
{
Village myVillage = newTile.getVillage ();
List<Tile> neighbours = newTile.getNeighbours();
//int mySize = myVillage.getRegionSize ();
Player myPlayer = myVillage.getPlayer ();
List<Village> villagesToMerge = new List<Village>();
villagesToMerge.Add (myVillage);
Village biggestVillage = myVillage;
//VillageType biggestType = biggestVillage.getMyType ();
foreach (Tile neighbour in neighbours)
{
Village neighbourVillage = neighbour.getVillage ();
if( neighbourVillage != null )
{
Player neighbourPlayer = neighbourVillage.getPlayer ();
if((myPlayer == neighbourPlayer) && !(villagesToMerge.Contains(neighbourVillage)))
{
villagesToMerge.Add(neighbourVillage);
VillageType neighbourType = neighbourVillage.getMyType();
int neighbourSize = neighbourVillage.getRegionSize();
if (neighbourType>biggestVillage.getMyType())
{
biggestVillage = neighbourVillage;
}
else if (neighbourType==biggestVillage.getMyType()&&neighbourSize>biggestVillage.getRegionSize())
{
biggestVillage = neighbourVillage;
}
}
}
}
foreach (Village village in villagesToMerge) {
if (village != biggestVillage) {
// biggestVillage.addGold (village.getGold ());
biggestVillage.gameObject.networkView.RPC ("addGoldNet",RPCMode.AllBuffered,village.getGold ());
// biggestVillage.addWood (village.getWood ());
biggestVillage.gameObject.networkView.RPC ("addWoodNet",RPCMode.AllBuffered,village.getGold ());
biggestVillage.addRegion(village.getControlledRegion ());
//foreach (Unit u in village.getControlledUnits ()){
// biggestVillage.addUnit (u);
//}
// remove prefab
Tile villageLocation = village.getLocatedAt();
//Destroy (villageLocation.prefab);
//villageLocation.gameObject.networkView.RPC ("destroyPrefab",RPCMode.AllBuffered);
//villageLocation.setLandType (LandType.Meadow);
myPlayer.gameObject.networkView.RPC("removeVillageNet",RPCMode.AllBuffered, village.gameObject.networkView.viewID, myPlayer.getColor ());
villageLocation.gameObject.networkView.RPC("setLandTypeNet",RPCMode.AllBuffered,(int)LandType.Meadow);
GameObject meadow = Network.Instantiate (meadowPrefab, new Vector3 (villageLocation.point.x, 0.1f, villageLocation.point.y), meadowPrefab.transform.rotation,0) as GameObject;
villageLocation.gameObject.networkView.RPC("replaceTilePrefabNet",RPCMode.AllBuffered,meadow.networkView.viewID);
//villageLocation.prefab = Instantiate (meadowPrefab, new Vector3 (villageLocation.point.x, 0.1f, villageLocation.point.y), meadowPrefab.transform.rotation) as GameObject;
//myPlayer.myVillages.Remove (village);
//Destroy (village.gameObject.networkView.viewID);
//gameObject.networkView.RPC ("destroyVillageNet",RPCMode.AllBuffered,village.gameObject.networkView.viewID);
}
}
}