private void CreateVertices(int size) { for (var row = 0; row < size; row++) { for (var column = 0; column < size; column++) { var hex = new Vertex(row, column); if (row == 0) { ConnectVertices(hex, Top); } if (row == Size - 1) { ConnectVertices(hex, Bottom); } if (column == 0) { ConnectVertices(hex, Left); } if (column == Size - 1) { ConnectVertices(hex, Right); } Hexes.Add(hex); } } }
private void RaiseVertex(Vector3 vertex, int dy) { var comparer = new Vector3Comparer(); var affectedHexes = Hexes.Where(h => h.Geometry.Points.Values.Any(v => comparer.Equals(v, vertex))) .Select(h => new { hex = h, point = h.Geometry.Points.First(p => comparer.Equals(p.Value, vertex)).Key }).ToList(); if (!affectedHexes.All(h => h.hex.CanRaisePoint(h.point, dy))) { return; } foreach (var affectedHex in affectedHexes) { if (dy > 0) { affectedHex.hex.Raise(affectedHex.point); } else if (dy < 0) { affectedHex.hex.Lower(affectedHex.point); } else { return; } } affectedHexes.Select(h => h.hex.PatchID).Distinct().ToList().ForEach(i => DirtyPatches.Add(i)); }
static bool IsFoundHexesData(Hexes needHexes, Hexes hexes) { if (needHexes.Pointer == hexes.Data) { return(true); } if (needHexes.Pointer == hexes.Data2) { return(true); } if (needHexes.Data != 0) { if (needHexes.Data == hexes.Pointer) { return(true); } } if (needHexes.Data2 != 0) { if (needHexes.Data2 == hexes.Pointer) { return(true); } } return(false); }
void UpdateRelatedLine() { this.AddressList.ClearAllSetRelatedLine(); int index = this.AddressList.SelectedIndex; if (index < 0) { return; } if (index >= this.LineDataList.Count) { return; } Hexes needHexes = LineDataList[index]; for (int i = 0; i < this.AddressList.Items.Count; i++) { if (i == index) {//自分自身を調べても意味がない continue; } Hexes hexes = LineDataList[i]; //check if (IsFoundHexesData(needHexes, hexes)) { this.AddressList.SetRelatedLine(i); } } }
// add hex and its neighbours to list public void AddHex(Hex hex) { hex.City = this; //ResourceBalance = ResourceBalance + tile.Resources; //foreach (NaturalGood resource in hexes.Resources) //{ // //ResourceBalance.NormalResourcesQuantity[resource.Info.Name] += resource.ResourceQuantity; //} Hexes.Add(hex); }
public string GetHash() { var code = ""; foreach (var hex in Hexes.OrderBy(x => x.Row).ThenBy(x => x.Column)) { code = code + "[" + hex.Row + hex.Column + hex.Owner + "]"; } return(code); }
/// <summary> /// Spawns 7 tiles around the index passed in and then places a throne building the index hex /// </summary> /// <param name="index">The middle hex index</param> private void SetStartTiles(int index = 302) { Hexes.ElementAt(index).IsCreep = true; RaycastHit hit; Physics.Raycast(FindHexObject(Hexes.ElementAt(index).hex.cubeCoords).transform.position - Vector3.up, Vector3.down, out hit, 2f); GameObject throne = Instantiate(thronePrefab); throne.transform.position = new Vector3(FindHexObject(Hexes.ElementAt(index).hex.cubeCoords).transform.position.x, hit.point.y, FindHexObject(Hexes.ElementAt(index).hex.cubeCoords).transform.position.z); Hex.Neighbours(Hexes.ElementAt(index).hex).ToList().ForEach(h => FindHexObject(h.cubeCoords).IsCreep = true); }
private void CreateRivers(MapSettingsData data) { System.Random prng = new System.Random(data.noiseSetting.seed); var terrainOnlyHexes = Hexes.ToList().Where(h => h.Elevation > 0); for (int i = 0; i < data.riverCount; i++) { int riverLength = prng.Next((int)data.riverLengthMinMax[0], (int)data.riverLengthMinMax[1]); // Start the river HexObject currentHex = terrainOnlyHexes.ToArray()[prng.Next(0, terrainOnlyHexes.Count())]; // Get neighbour to connect to HexObject nextLowestNeighbour = Instance.FindHexObject(Hex.Neighbours(currentHex.Hex).OrderBy(n => Instance.FindHexObject(n.cubeCoords).Elevation).FirstOrDefault().cubeCoords); for (int l = 0; l < riverLength; l++) { if (currentHex.Elevation == 0) { break; } if (currentHex == nextLowestNeighbour) { continue; } currentHex.SetOutgoingRiver(Hex.Direction(currentHex.Hex, nextLowestNeighbour.Hex)); if (nextLowestNeighbour == null) { break; } currentHex = nextLowestNeighbour; if (currentHex == null) { break; } try { var neighbours = Hex.Neighbours(currentHex.Hex); var hexObjectToFind = neighbours.OrderBy(n => Instance.FindHexObject(n.cubeCoords).Elevation).FirstOrDefault(); nextLowestNeighbour = Instance.FindHexObject(hexObjectToFind.cubeCoords); } catch { continue; } } } }
private Coordinate[] GetNeighbours(Coordinate coordinate) { var result = new List <Coordinate>(6); var coord1 = new Coordinate(coordinate.Q, coordinate.R - 1); if (Hexes.ContainsKey(coord1)) { result.Add(coord1); } var coord2 = new Coordinate(coordinate.Q + 1, coordinate.R - 1); if (Hexes.ContainsKey(coord2)) { result.Add(coord2); } var coord3 = new Coordinate(coordinate.Q - 1, coordinate.R); if (Hexes.ContainsKey(coord3)) { result.Add(coord3); } var coord4 = new Coordinate(coordinate.Q + 1, coordinate.R); if (Hexes.ContainsKey(coord4)) { result.Add(coord4); } var coord5 = new Coordinate(coordinate.Q - 1, coordinate.R + 1); if (Hexes.ContainsKey(coord5)) { result.Add(coord5); } var coord6 = new Coordinate(coordinate.Q, coordinate.R + 1); if (Hexes.ContainsKey(coord6)) { result.Add(coord6); } return(result.ToArray()); }
public Hex GetHexAt(int q, int r) { if (Hexes == null) { Debug.LogError("Hex Array is Null"); return(null); } if (horizWrapping) { q = q % Columns; if (q < 0) { q += Columns; } if (q > Columns) { q -= Columns; } } if (vertWrapping) { r = r % Rows; if (r < 0) { r += Rows; } if (r > Rows) { r -= Rows; } } if (q >= Hexes.GetLength(0) || q < 0) { return(null); } if (r >= Hexes.GetLength(1) || r < 0) { return(null); } return(Hexes[q, r]); }
Size DrawASMHexes(ListBox lb, int index, Graphics g, Rectangle listbounds, bool isWithDraw) { if (index < 0 || index >= this.LineDataList.Count) { return(new Size(listbounds.X, listbounds.Y)); } Hexes h = this.LineDataList[index]; SolidBrush brush = new SolidBrush(lb.ForeColor); Font normalFont = lb.Font; Rectangle bounds = listbounds; int lineHeight = (int)lb.Font.Height; int fontWidth = lineHeight / 2 + 1; //ますは自下げする bounds.X += (fontWidth * 2) * h.Jisage; //アドレスを書く U.DrawText(h.Pointer.ToString("X08"), g, normalFont, brush, isWithDraw, bounds); bounds.X += (fontWidth) * 8; //スペース1つほど bounds.X += (fontWidth * 1); //OPコードを書く U.DrawText(h.OPDumpString, g, normalFont, brush, isWithDraw, bounds); bounds.X += (fontWidth * h.OPDumpString.Length); //スペース2つほど bounds.X += (fontWidth * 2); //メインとなるコードを書く bounds.X += U.DrawText(h.CodeString, g, normalFont, brush, isWithDraw, bounds); //スペース2つほど bounds.X += (fontWidth * 2); //コメントを書く bounds.X += U.DrawText(h.Comment, g, normalFont, brush, isWithDraw, bounds); brush.Dispose(); bounds.Y += lineHeight; return(new Size(bounds.X, bounds.Y)); }
public override void Update(GameManager gameManager, int deltaTime) { var realPoint = gameManager.Input.PointerPosition.ToVector2() + gameManager.Camera.Offset; Coordinate = GetCoordinate(realPoint); if (gameManager.Input.IsLeftButtonPressed) { if (!Hexes.ContainsKey(Coordinate)) { return; } var pawn = Hexes[Coordinate].Pawn; if (pawn == null) { if (_selectedPawn != null) { _selectedPawn.Selected = false; _selectedPawn = null; PossibleMoves.Clear(); } return; } pawn.Selected = true; _selectedPawn = pawn; var moveQueue = new Queue <Move>(); var openingMoves = GetNeighbours(Coordinate); foreach (var openingMove in openingMoves) { var hex = Hexes[openingMove]; if (!hex.Passable) { continue; } moveQueue.Enqueue(new Move(hex)); } var possibleMoves = new List <Coordinate>(); var visitedCoordinates = new HashSet <Coordinate>(); while (moveQueue.Count > 0) { var move = moveQueue.Dequeue(); if (visitedCoordinates.Contains(move.Hex.Coordinate)) { continue; } visitedCoordinates.Add(move.Hex.Coordinate); if (move.TotalMoveCost > pawn.MoveSpeed) { continue; } possibleMoves.Add(move.Hex.Coordinate); var newMoves = GetNeighbours(move.Hex.Coordinate); foreach (var newMove in newMoves) { if (visitedCoordinates.Contains(newMove)) { continue; } var hex = Hexes[newMove]; if (!hex.Passable) { continue; } moveQueue.Enqueue(new Move(move, hex)); } } PossibleMoves = possibleMoves; } if (gameManager.Input.IsRightButtonPressed && _selectedPawn != null) { if (PossibleMoves.Contains(Coordinate)) { _selectedPawn.Hex.Pawn = null; _selectedPawn.Hex = Hexes[Coordinate]; _selectedPawn.Hex.Pawn = _selectedPawn; _selectedPawn.Selected = false; PossibleMoves.Clear(); } } }
public HexObject GetHexObjectAt(Vector3 position) { var coord = GetCubeCoordAt(position); return(Hexes.ElementAt((int)(coord.X + coord.Z * Width))); }
public string Draw(int width, int height) { //var b = new Bitmap(width, height); var hexWidth = Math.Floor((double)(width / (Columns * 1.75))); var hexHeight = Math.Floor((double)(height / (Rows + 1))) * 2; hexWidth = hexHeight = Math.Min(hexWidth, hexHeight); var svgDoc = new SvgDocument { Width = width, Height = height, ViewBox = new SvgViewBox(0, 0, width, height), }; var group = new SvgGroup(); svgDoc.Children.Add(group); for (var r = 0; r < Hexes.GetLength(0); r++) { for (var q = 0; q < Hexes.GetLength(1); q++) { int offsetRow = !(r % 2 == 0) ? 1 : 0; var originX = (q * hexWidth * 1.5) + (hexWidth / 2) + (offsetRow * hexWidth * 0.75); var originY = (r * hexHeight / 2) + (hexHeight / 2); var ax = originX - (hexWidth / 4); var ay = originY - (hexHeight / 2); var bx = originX + (hexWidth / 4); var by = originY - (hexHeight / 2); var cx = originX + (hexWidth / 2); var cy = originY; var dx = originX + (hexWidth / 4); var dy = originY + (hexHeight / 2); var ex = originX - (hexWidth / 4); var ey = originY + (hexHeight / 2); var fx = originX - (hexWidth / 2); var fy = originY; var p = new SvgPolygon(); p.Points = new SvgPointCollection(); p.Points.Add(new SvgUnit((float)ax)); p.Points.Add(new SvgUnit((float)ay)); p.Points.Add(new SvgUnit((float)bx)); p.Points.Add(new SvgUnit((float)by)); p.Points.Add(new SvgUnit((float)cx)); p.Points.Add(new SvgUnit((float)cy)); p.Points.Add(new SvgUnit((float)dx)); p.Points.Add(new SvgUnit((float)dy)); p.Points.Add(new SvgUnit((float)ex)); p.Points.Add(new SvgUnit((float)ey)); p.Points.Add(new SvgUnit((float)fx)); p.Points.Add(new SvgUnit((float)fy)); p.Stroke = new SvgColourServer(Color.Black); p.Fill = new SvgColourServer(r % 2 == 0 ? Color.White : Color.AliceBlue); group.Children.Add(p); //DrawLine(b, ax, ay, bx, by); //DrawLine(b, bx, by, cx, cy); //DrawLine(b, cx, cy, dx, dy); //DrawLine(b, dx, dy, ex, ey); //DrawLine(b, ex, ey, fx, fy); //DrawLine(b, fx, fy, ax, ay); //DrawText(b, ax, ay, q, r); } } //b.Save(@"c:\temp\output.jpg"); //svgDoc.Write(@"c:\temp\output.svg"); using (var stream = new MemoryStream()) { svgDoc.Write(stream); return(Encoding.UTF8.GetString(stream.GetBuffer())); } }
/// <summary>Paint the base layer of the display, graphics that changes rarely between refreshes.</summary> /// <param name="this">Type: MapDisplay{THex} - The map to be painted.</param> /// <param name="graphics">Type: Graphics - Object representing the canvas being painted.</param> /// <remarks>For each visible hex: perform <c>paintAction</c> and then draw its hexgrid outline.</remarks> public static void PaintMap <THex>(this MapDisplay <THex> @this, DrawingContext dc, bool showHexgrid, Hexes boardHexes, ILandmarks landmarks) where THex : class, IHex { ; }
public Hex HexAt(int row, int column) { return(Hexes.FirstOrDefault(x => x.Row == row && x.Column == column)); }