public Unit(PlayerState owner, int id, UnitConfiguration configuration, Server server) { Owner = owner; Id = id; Faction = server.GetFaction(configuration.FactionId); Type = Faction.GetUnitType(configuration.UnitTypeId); Upgrades = new List<UnitUpgrade>(); _Points = Type.Points; UpgradeSlotsOccupied = new HashSet<int>(); foreach (var upgradeId in configuration.UpgradeIds) AddUpgrade(GetUpgrade(upgradeId)); Hex = null; Strength = GameConstants.FullUnitStrength; Entrenched = false; AttritionDuration = 0; UpdateStats(); ResetUnitForNewTurn(); // Only air units are automatically "deployed" since they don't need to be placed on the map Deployed = Stats.Flags.Contains(UnitFlag.Air); }
public StealCardForm(World world) { this.world = world; this.robberHex = world.getRobberHex(); InitializeComponent(); updateLabels(); }
public void TestAddOwner() { var target = new Hex("grain", GRAIN_COLOR); target.addOwner(new Player("Joe", Color.Black, new World())); Assert.IsTrue(target.owners[0].getName().Equals("Joe")); Assert.IsTrue(target.owners[0].getColor().Equals(Color.Black)); }
public void removeRobberText() { this.robberHex = this.world.getRobberHex(); for (int i = 0; i < 5; i++) { for (int j = 1; j < 4; j++) { if (this.hexGrid[i][j].getHex() != this.world.getRobberHex()) { this.hexGrid[i][j].setHasRobber(false); } } } // check outliers: [1][0], [2][0], [3][0], [2][4] for (int i = 1; i < 4; i++) { if (this.hexGrid[i][0].getHex() != this.world.getRobberHex()) { this.hexGrid[i][0].setHasRobber(false); } } if (this.hexGrid[2][4].getHasRobber()) { if (this.hexGrid[2][4].getHex() != this.world.getRobberHex()) { this.hexGrid[2][4].setHasRobber(false); } } //this.Refresh(); }
public static List<Hex> FindPath(IDictionary<Hex, Tile> data, Hex start, Hex end) { var frontier = new Queue<Hex>(); frontier.Enqueue(start); var trace = new Dictionary<Hex, Hex>(); trace[start] = start; while (frontier.Count > 0) { var current = frontier.Dequeue(); if (current == end) { break; } foreach (var next in Near(data, current).Where(n => !trace.ContainsKey(n))) { frontier.Enqueue(next); trace[next] = current; } } var path = new List<Hex> { end }; while (end != start) { end = trace[end]; path.Add(end); } path.Reverse(); return path; }
public static int GetHexOffsetIndex(Hex hex1, Hex hex2) { Position difference = hex2.Position - hex2.Position; int index = Array.FindIndex(HexOffsets, (Position x) => x.SamePosition(difference)); if (index < 0) throw new Exception("Encountered an invalid hex offset difference in a river edge pair"); return index; }
public static Hex CreateCenterHex() { var hex = new Hex(); hex.AddPinkPlanet(2, 1); hex.AddBrownPlanet(2, 1); hex.AddGrayPlanet(2); return hex; }
// public TempMenu[] MoveFromMenus { get; set; } public MoveUI() { Hexes = new Hex[2]; var board = HexBoard.GetInstance(); Hexes[0] = board.LastMoveFromHex; Hexes[1] = board.LastSelectedHex; // MoveFromMenus = board.GetMoveFromHexes().Select(x => new TempMenu("Move from", x)).ToArray(); }
//i must start with 1. public HexSide(int i, Hex owner ) { RadiansAngle = GetRadiansAngle(i); HasWormHole = false; PointDirection = GetDirection(i); WormholeCanvasLocation = owner.CanvasLocation.GetRelativePoint(CanvasHelper.GetHexHeight(), RadiansAngle); WormholeStartAngle = RadiansAngle - 0.5 * Math.PI; WormholeEndAngle = WormholeStartAngle + Math.PI; }
public void AddCrosshairs(Hex hex) { Canvas canvas = new Canvas(); canvas.Name = "CrosshairCanvas"; Path path = new Path(); CreatePathOutline(path, "HexsidesPath"); AddImage(path, Game.ImageFactory.HexsidesImage, Constants.CrosshairsXCoordinate, Constants.CrosshairsYCoordinate); canvas.Children.Add(path); hex.MainCanvas.Children.Add(canvas); }
public void AddExplosion(Hex hex, int sequenceNumber) { Canvas canvas = new Canvas(); canvas.Name = "ExplodeCanvas"; Path path = new Path(); CreatePathOutline(path, "ExplodePath"); AddImage(path, Game.ImageFactory.ExplosionImage, sequenceNumber*-60, 0); canvas.Children.Add(path); hex.MainCanvas.Children.Add(canvas); }
public ResourceHexPictureBox(Hex hex, World world) : this() { resourceType = hex.getResourceType(); this.BackColor = hex.getColor(); this.token = hex.getToken(); this.world = world; this.hex = hex; doubleClickTimer.Interval = 100; checkDesert(); }
public static Point HexToCanvasPoint(Hex hex) { var point = GetCenterCanvasPoint(); var R = GetHexRadius(); var H = GetHexHeight(); point.X += (int) (1.5 * hex.AxialCoordinates.X * R); point.Y += (int)(1 * H * hex.AxialCoordinates.X); point.Y += (int)(2 * H * hex.AxialCoordinates.Y); return point; }
public HexSectorSelector(ResourceManager resourceManager, Sector sector, Hex coords, int jump) { if (resourceManager == null) throw new ArgumentNullException("resourceManager"); if (sector == null) throw new ArgumentNullException("sector"); this.sector = sector; this.resourceManager = resourceManager; this.coords = coords; this.jump = jump; }
/// <summary>Assign a move command to a unit. The unit is not moved. Units to be placed on the from cell are also candidates for the move command.</summary> public void AddMoveCommand(string playerColor, Hex fromHex, Hex toHex) { Cell fromCell = NextTurn.GetCell(fromHex); Unit unit = fromCell.Units.FirstOrDefault(u => u.Player.Color == playerColor && u.MoveCommand == null); // If there wasn't an availble unit on the cell, check if a unit is to be placed on the cell. if (unit == null) { unit = NextTurn.NewUnits.First(u => u.Player.Color == playerColor && u.PlaceCommand != null && u.PlaceCommand.On == fromCell); } Cell toCell = NextTurn.GetCell(toHex); unit.SetMoveCommand(fromCell, toCell); }
public Wall(int start, byte[] bytes, Hex[] hexes, string[] wallNames, string[] itemsProtoNames, out int newStart) { MapObjectType = MapObjectType.Wall; TextureName = wallNames[HelperFuncts.SumTwoBytes(bytes[start + 34], bytes[start + 35])].Trim(); int hexNumber = HelperFuncts.SumTwoBytes(bytes[start + 6], bytes[start + 7]); HexPosition = hexNumber; _objDirection = bytes[start + 31]; string frmName = _repo + "art/walls/" + TextureName; _texture = new FRM(frmName, (int)hexes[hexNumber]._vertexes[0].X, (int)hexes[hexNumber]._vertexes[0].Y); _texture.CurrentDirection = _objDirection; _protoId = HelperFuncts.SumTwoBytes(bytes[start + 46], bytes[start + 47]); ; newStart = start += 88; }
public List<Hex> GetIndirectlyCapturedRegion(Hex seed, PlayerIdentifier conqueror) { if (seed.Owner == conqueror) { // This can't be the seed of an empty region as it is already owned by the player return null; } List<Hex> capturedRegion = new List<Hex>(); // Initially only the seed is virtually captured capturedRegion.Add(seed); HashSet<Hex> scannedHexes = new HashSet<Hex>(new HexComparer()); // Perform depth-first search to determine the size of the region if (IsValidIndirectCapture(seed, conqueror, capturedRegion, scannedHexes)) return capturedRegion; else return null; }
public void AddColor(Hex hex, Color color) { hex.Dispatcher.BeginInvoke(() => { Canvas canvas = new Canvas(); canvas.Name = "ColorCanvas"; canvas.SetValue(Canvas.ZIndexProperty, 9); canvas.Opacity = .5; Path path = new Path(); CreatePathOutline(path, "ColorPath"); SolidColorBrush colorBrush = new SolidColorBrush(); colorBrush.Color = color; ScaleTransform scaleTransform = new ScaleTransform(); scaleTransform.ScaleX = Game.CurrentViewLevel; scaleTransform.ScaleY = Game.CurrentViewLevel; colorBrush.Transform = scaleTransform; path.Fill = colorBrush; canvas.Children.Add(path); hex.MainCanvas.Children.Add(canvas); }); }
public Misc(int start, byte[] bytes, Hex[] hexes, string[] miscNames, string[] itemsProtoNames, out int newStart) { MapObjectType = MapObjectType.Misc; TextureName = miscNames[HelperFuncts.SumTwoBytes(bytes[start + 34], bytes[start + 35])].Trim(); int hexNumber = HelperFuncts.SumTwoBytes(bytes[start + 6], bytes[start + 7]); HexPosition = hexNumber; _objDirection = bytes[start + 31]; string frmName = _repo + "art/misc/" + TextureName; _texture = new FRM(frmName, (int)hexes[hexNumber]._vertexes[0].X, (int)hexes[hexNumber]._vertexes[0].Y); _texture.CurrentDirection = _objDirection; _protoId = HelperFuncts.SumTwoBytes(bytes[start + 46], bytes[start + 47]); ; if (bytes[start + 47] == 12) //Screen Blocker { newStart = start += 88; } else { newStart = start += 104; //Exit Grids - 104 } }
public Critter(int start, byte[] bytes, Hex[] hexes, string[] criNames, string[] itemsProtoNames, out int newStart) { MapObjectType = MapObjectType.Critter; TextureName = criNames[bytes[start + 35]].Split(',')[0] + WeaponEquipped + CurrentAnimation + ".frm"; int hexNumber = HelperFuncts.SumTwoBytes(bytes[start + 6], bytes[start + 7]); HexPosition = hexNumber; _objDirection = bytes[start + 31]; string frmName = _repo + "art/critters/" + TextureName; _texture = new FRM(frmName, (int)hexes[hexNumber]._vertexes[0].X, (int)hexes[hexNumber]._vertexes[0].Y); _texture.CurrentDirection = _objDirection; _frameNumer = bytes[start + 27]; _protoId = HelperFuncts.SumTwoBytes(bytes[start + 46], bytes[start + 47]); ; _numberOfSubItems = bytes[start + 75]; _hitPoints = bytes[start + 119]; if (_numberOfSubItems > 0) { GetSubItems(_numberOfSubItems, start, bytes, itemsProtoNames, out start); } else { start += 128; } newStart = start; }
public void TestHexInitializesProperly() { var target = new Hex("lumber", LUMBER_COLOR); Assert.NotNull(target); }
public void TestHexHasCorrectResourceType() { var target = new Hex("ore", ORE_COLOR); Assert.AreEqual("ore", target.getResourceType()); }
public void TestHexHasCorrectColor() { var target = new Hex("lumber", LUMBER_COLOR); Assert.AreEqual(LUMBER_COLOR, target.getColor()); }
public void TestHexSetsToken() { var target = new Hex("brick", BRICK_COLOR); target.setToken(5); Assert.NotNull(typeof (Hex).GetField("token", BindingFlags.NonPublic | BindingFlags.Instance)); }
public void TestThatHexSetsFields() { var target = new Hex("wool", GRAIN_COLOR); Assert.NotNull(target.getResourceType()); Assert.NotNull(target.getColor()); }
public Path(Path currentPath, Hex newHex, int movementPointsLeft) { Hexes = new List<Hex>(); Hexes.AddRange(currentPath.Hexes); Hexes.Add(newHex); MovementPointsLeft = movementPointsLeft; }
public void TestHexSetsTokenCorrectly() { var target = new Hex("brick", BRICK_COLOR); target.setToken(5); Assert.AreEqual(5, target.getToken()); }
bool IsValidIndirectCapture(Hex currentHex, PlayerIdentifier conqueror, List<Hex> capturedRegion, HashSet<Hex> scannedHexes) { foreach (var neighbour in GetNeighbours(currentHex)) { if (scannedHexes.Contains(neighbour)) { // This hex has already been scanned continue; } scannedHexes.Add(neighbour); if (neighbour.Owner == conqueror) { // This hex is already owned by the player continue; } if (neighbour.Unit != null) { // An enemy unit is occupying a hex in this region so it can't be captured return false; } if (scannedHexes.Count >= GameConstants.IndirectCaptureLimit) { // This hex passed the criteria but the region is already too large to be captured indirectly return false; } capturedRegion.Add(neighbour); bool isEmptyRegion = IsValidIndirectCapture(neighbour, conqueror, capturedRegion, scannedHexes); if (!isEmptyRegion) return false; } return true; }
private DataList<ImageInfo> getImages(string artistName, string albumName, Int64? fileId, Boolean getOneImage) { try { DataList<ImageInfo> returnList = new DataList<ImageInfo>(); if (canCallAmazon(artistName, albumName)) { AmazonECS service = new AmazonECSQuery(accessKeyId, ""); byte[] returnArr = null; ItemSearchRequest request = new ItemSearchRequest(); request.SearchIndex = "Music"; request.ResponseGroup = new List<String>(new String[] { "Images" }); request.Artist = artistName; request.Title = albumName; ItemSearchResponse response = service.ItemSearch(request); if (response.Items.Count == 1) { DataList<Item> items = new DataList<Item>(response.Items[0].Item); foreach (Item itm in items) { if (itm.MediumImage != null) { String url = itm.MediumImage.URL; String extension = Static.GetFileExtension(itm.MediumImage.URL); String md5Hash; using (WebClient Client = new WebClient()) { returnArr = Client.DownloadData(url); md5Hash = new Hex(MD5Stream.GetHash(returnArr)); returnList.Add(new ImageInfo { Data = returnArr, Extension = extension, webUrl = url, md5Hash = md5Hash }); } if (getOneImage) break; } } if (returnList.Count > 0) calledAmazon(artistName, albumName, true); Logging.Info(typeof(AmazonAssociatesImageProvider), String.Format("Amazon Search for {0} ({1}) {2} results", artistName, albumName, returnList.Count)); } else if (response.Items.Count > 1) Logging.Warn(typeof(AmazonAssociatesImageProvider), "More than one search result"); else Logging.Warn(typeof(AmazonAssociatesImageProvider), String.Format("No search result ({0}, {1})", artistName, albumName)); } else { Logging.Debug(typeof(AmazonAssociatesImageProvider), String.Format("Will not call Amazon, because of last calls: {0}, {1}, {2}", artistName, albumName, fileId)); } return returnList; } catch (Exception e) { Logging.Error(typeof(AmazonAssociatesImageProvider), e); calledAmazon(artistName, albumName, false); return null; } }
void SetHexRiverData(Hex target, Hex neighbour, RiverEdge edge) { int index = GetHexOffsetIndex(target, neighbour); target.RiverEdges[index] = edge; }