public void addSubRegion(Region subRegion) { if (!SubRegions.Contains(subRegion)) { SubRegions.Add(subRegion); } }
/// <summary> /// Returns a copy of this map and all of its contents, with new instances of each object (Map, SuperRegions, Regions). /// </summary> /// <returns></returns> public Map GetMapCopy() { Map newMap = new Map(); foreach (SuperRegion sr in SuperRegions) { SuperRegion newSuperRegion = new SuperRegion(sr.ID, sr.ArmiesReward); newMap.AddSuperRegion(newSuperRegion); } foreach (Region r in Regions) { Region newRegion = new Region(r.ID, newMap.GetSuperRegionByID(r.SuperRegion.ID), r.PlayerName, r.Armies); newMap.AddRegion(newRegion); } foreach (Region r in Regions) { Region newRegion = newMap.GetRegionByID(r.ID); foreach (Region neighbor in r.Neighbors) { newRegion.AddNeighbor(newMap.GetRegionByID(neighbor.ID)); } } return newMap; }
public void AddNeighbor(Region neighbor) { if (!Neighbors.Contains(neighbor)) { Neighbors.Add(neighbor); neighbor.AddNeighbor(this); } }
public AttackTransferMove(String playerName, Region fromRegion, Region toRegion, Region actualTarget, int armies, MoveReason reason) { PlayerName = playerName; FromRegion = fromRegion; ToRegion = toRegion; Armies = armies; MoveReason = reason; ActualTarget = actualTarget; }
/** * add a Region to the map * @param region : Region to be added */ public void AddRegion(Region region) { var existing = GetRegionByID(region.ID); if (existing != null) { Console.Error.WriteLine("Region cannot be added: id already exists."); return; } Regions.Add(region); }
/// <summary> /// Evaluates whether an attack should happen on the given region. /// </summary> /// <param name="fromRegion"></param> /// <param name="toRegion"></param> /// <param name="possibleToRegions"></param> /// <param name="attackTransferMoves"></param> /// <returns>null if no move.</returns> private AttackTransferMove PerhapsGetAttackMove(Region fromRegion, Region toRegion, List<Region> possibleToRegions, List<AttackTransferMove> attackTransferMoves) { if (fromRegion.PlayerName != Name || fromRegion.Armies < 6 || toRegion.PlayerName == Name) { return null; } int difference = fromRegion.Armies - toRegion.Armies; if (difference < 0) { return null; } int armies = toRegion.Armies + (int)(difference * 1.5); armies = Math.Min(armies, fromRegion.Armies - 1); return new AttackTransferMove(Name, fromRegion, toRegion, toRegion, armies, MoveReason.Random); }
/// <summary> /// Evaluates whether a move should occur between to the given region. /// </summary> /// <param name="fromRegion"></param> /// <param name="toRegion"></param> /// <param name="possibleToRegions"></param> /// <param name="attackTransferMoves"></param> /// <returns>null if no move.</returns> private AttackTransferMove PerhapsGetMoveMove(Region fromRegion, Region toRegion, List<Region> possibleToRegions, List<AttackTransferMove> attackTransferMoves) { if (!toRegion.PlayerName.Equals(Name) || fromRegion.Armies <= 1) { return null; } int armies = 5; return new AttackTransferMove(Name, fromRegion, toRegion, toRegion, Math.Min(fromRegion.Armies - 1, armies), MoveReason.Random); }
public bool IsNeighbor(Region region) { return Neighbors.Contains(region); }
protected virtual void MoveArmies(string playerName, Region fromRegion, Region toRegion, int armies, MoveReason moveReason) { ConsoleExtensions.WriteColoredLine(ConsoleColor.Yellow, "Player '{0}' moves {1} armies from region {2} to {3} for {4}.", playerName, armies, fromRegion.ID, toRegion.ID, moveReason); fromRegion.Armies -= armies; fromRegion.ArmiesAvailable -= armies; toRegion.Armies += armies; }
public PlaceArmiesMove(String playerName, Region region, int armies) { Armies = armies; Region = region; PlayerName = playerName; }