Пример #1
0
    public void CheckAdjacentHexes(int diceRoll)
    {
        for (int i = 0; i < Hexes.Count; i++)
        {
            if (Hexes[i].GetComponent <ScriptBoardHex>().hexDieValue == diceRoll)
            {
                HexType resource = Hexes[i].GetComponent <ScriptBoardHex>().resource;
                switch (resource)
                {
                case HexType.BRICK:
                    player.AddBricks(1);
                    break;

                case HexType.GRAIN:
                    player.AddWheat(1);
                    break;

                case HexType.WOOD:
                    player.AddLumber(1);
                    break;

                case HexType.WOOL:
                    player.AddWool(1);
                    break;
                }
            }
        }
    }
Пример #2
0
        private Canvas GetPieceInHandCanvas(Piece piece, double size, HexOrientation hexOrientation, bool disabled)
        {
            Point center = new Point(size, size);

            HexType hexType = (piece.Color == Core.Color.White) ? HexType.WhitePiece : HexType.BlackPiece;

            Shape     hex     = GetHex(center, size, hexType, hexOrientation);
            UIElement hexText = GetHexText(center, size, piece.PieceName, disabled);

            Canvas pieceCanvas = new Canvas
            {
                Height     = size * 2,
                Width      = size * 2,
                Margin     = new Thickness(PieceCanvasMargin),
                Background = (piece.Color == Core.Color.White) ? WhiteHandStackPanel.Background : BlackHandStackPanel.Background,

                Name = EnumUtils.GetShortName(piece.PieceName)
            };

            pieceCanvas.Children.Add(hex);
            pieceCanvas.Children.Add(hexText);

            // Add highlight if the piece is selected
            if (VM.AppVM.EngineWrapper.TargetPiece == piece.PieceName)
            {
                Shape highlightHex = GetHex(center, size, HexType.SelectedPiece, hexOrientation);
                pieceCanvas.Children.Add(highlightHex);
            }

            pieceCanvas.MouseLeftButtonUp  += PieceCanvas_MouseLeftButtonUp;
            pieceCanvas.MouseRightButtonUp += CancelClick;

            return(pieceCanvas);
        }
Пример #3
0
    /// <summary>
    /// Adds cells to array based on metrics, max width & max height
    /// </summary>
    /// <param name="x">X coord of cell in array</param>
    /// <param name="z">Z coord of cell in array</param>
    /// <param name="type"></param>
    /// <param name="isHill"></param>
    void CreateCell(int x, int z, HexType type, bool isHill)
    {
        Vector3 pos;

        pos.x = (x + z * 0.5f - z / 2) * (HexMetrics.innerRad * 2f);
        pos.y = 0f;
        pos.z = z * HexMetrics.outerRad * 1.5f;

        HexCell cell = cells[x, z] = Instantiate <HexCell>(cellPrefab);

        cell.transform.localPosition = pos;
        cell.coordinates             = HexCoordinates.FromOffsetCoordinates(x, z);
        cell.name = "Hex Cell " + cell.coordinates.ToString();
        if (type != null)
        {
            cell.Type = type;
        }
        else
        {
            cell.Type = HexType.types[HexType.typeKeys.ocean];
        }
        cell.isHill = isHill;

        /*if (showCoords)
         * {
         *  Text label = Instantiate<Text>(labelPrefab);
         *  //label.rectTransform.SetParent(gridCanvas.transform, false);
         *  label.rectTransform.anchoredPosition = new Vector2(pos.x, pos.z);
         *  label.text = cell.coordinates.ToStringOnSeparateLines();
         * }*/

        AddCellToChunk(x, z, cell);
    }
Пример #4
0
 public void SetNextType()
 {
     if (++Type >= HexType.Count)
     {
         Type = 0;
     }
 }
Пример #5
0
    // Create hexmap indicator attached to hexcell
    public void GenerateHexType(HexCell cell, HexType type)
    {
        cell.hexType = type;
        // hexTypes[x+mapWidth*z] = type;
        if (type != HexType.Plain)
        {
            HexTypeInfo gm = null;
            if (type == HexType.Forest)
            {
                gm = Instantiate(hexPrefab_forest);
            }
            else if (type == HexType.Swamp)
            {
                gm = Instantiate(hexPrefab_swamp);
            }
            else if (type == HexType.Mountain)
            {
                gm = Instantiate(hexPrefab_mountain);
            }
            else if (type == HexType.Stones)
            {
                gm = Instantiate(hexPrefab_stones);
            }

            /*else if (type==HexType.Thorns)
             *      gm = Instantiate(hexPrefab_thorns);*/

            if (gm != null)
            {
                gm.ChangeType(type);
                gm.gameObject.transform.SetParent(cell.transform);
                gm.gameObject.transform.localPosition = Vector3.zero;
            }
        }
    }
Пример #6
0
    public Hex ChangeHexes(int a, Hex hex)
    {
        int   xHex = hex.x;
        int   yHex = hex.y;
        float xPos = xHex * xOffset;

        if (yHex % 2 == 1)
        {
            xPos += xOffset / 2f;
        }

        hexes [xHex, yHex] = a;
        Destroy(hex.gameObject);
        HexType    tt     = hextypes [hexes [xHex, yHex]];
        GameObject hex_go = Instantiate(tt.hexVisualPrefab, new Vector3(xPos, 0, yHex * zOffset), Quaternion.identity) as GameObject;

        hex_go.name = "Hex_" + xHex + "_" + yHex;

        hex_go.GetComponent <Hex> ().x       = xHex;
        hex_go.GetComponent <Hex> ().y       = yHex;
        hex_go.GetComponent <Hex> ().hexType = a;
        hex_go.GetComponent <Hex> ().CalculateResources();

        hex_go.transform.SetParent(this.transform);

        hex_go.isStatic = true;

        return(hex_go.GetComponent <Hex> ());
    }
Пример #7
0
    public void CreateClump()
    {
        if (_clumpGrid == null)
        {
            InitializeGrid();
        }

        _clumpGrid.ResetGrid();

        _isLaser           = false;
        _pieces            = new List <HexPiece>();
        _startingPositions = new Dictionary <HexPiece, Vector3>();

        HexType clumpType = (HexType)Random.Range((int)HexType.Basic1, (int)HexType.Basic5 + 1); // Random.Range is Max _exclusive_ for ints
        int     clumpSize = Random.Range(MinClumpSize, MaxClumpSize + 1);

        if (ClumpShape == ClumpShape.Random)
        {
            CreateRandomShapedClump(clumpType, clumpSize);
        }
        else if (ClumpShape == ClumpShape.Triangular)
        {
            CreateTriangularShapedClump(clumpType, clumpSize);
        }
    }
Пример #8
0
    void GenerateMapVisual()
    {
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                float xPos = x * xOffset;

                //Are we on an odd row?
                if (y % 2 == 1)
                {
                    xPos += xOffset / 2f;
                }

                HexType tt = hextypes [hexes [x, y]];

                GameObject hex_go = Instantiate(tt.hexVisualPrefab, new Vector3(xPos, 0, y * zOffset), Quaternion.identity) as GameObject;

                hex_go.name = "Hex_" + x + "_" + y;

                hex_go.GetComponent <Hex> ().x = x;
                hex_go.GetComponent <Hex> ().y = y;

                hex_go.transform.SetParent(this.transform);

                hex_go.isStatic = true;
            }
        }
    }
Пример #9
0
    public int x, y;      // index on the board

    public Hex(GameObject go, HexType type, int x, int y)
    {
        this.go   = go;
        this.type = type;
        this.x    = x;
        this.y    = y;
    }
Пример #10
0
    public Hex BuildingHex(int a, Hex hex)
    {
        int   xHex = hex.x;
        int   yHex = hex.y;
        float xPos = xHex * xOffset;

        if (yHex % 2 == 1)
        {
            xPos += xOffset / 2f;
        }

        hexes [xHex, yHex] = a;
        Destroy(hex.gameObject);
        HexType    tt     = hextypes [hexes [xHex, yHex]];
        GameObject hex_go = Instantiate(tt.hexVisualPrefab, new Vector3(xPos, 0, yHex * zOffset), Quaternion.identity) as GameObject;

        hex_go.name = "Hex_" + xHex + "_" + yHex;

        hex_go.GetComponent <Hex> ().x = xHex;
        hex_go.GetComponent <Hex> ().y = yHex;

        hex_go.transform.SetParent(this.transform);

        hex_go.isStatic = true;

        GameObject.Find("MouseManager").GetComponent <NextTurnManager> ().AddBuilding(hex_go);

        return(hex_go.GetComponent <Hex> ());
    }
Пример #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="type"></param>
        /// <param name="val"></param>
        /// <param name="isHighFirst"></param>
        /// <returns></returns>
        public static string ToHexLine(long addr, HexType type, byte[] val, bool isHighFirst = false)
        {
            string _return  = ":";
            byte   checkSum = (byte)(val.Length);

            _return  += checkSum.ToString("X2");
            checkSum += (byte)(addr >> 8);
            checkSum += (byte)(addr);
            _return  += addr.ToString("X4");
            checkSum += (byte)(type);
            _return  += ((byte)type).ToString("X2");
            for (int i = 0; i < val.Length; i += 2)
            {
                if (isHighFirst)
                {
                    _return += string.Format("{0:X2}{1:X2}", val[i + 1], val[i]);
                }
                else
                {
                    _return += string.Format("{0:X2}{1:X2}", val[i], val[i + 1]);
                }
                checkSum += val[i];
                checkSum += val[i + 1];
            }
            checkSum = (byte)(0x100 - checkSum);
            _return += checkSum.ToString("X2");
            _return += "\r\n";
            return(_return);
        }
Пример #12
0
        /// <summary>
        /// 将数据转换成HexLine
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="type"></param>
        /// <param name="buffer"></param>
        /// <param name="isHighFirst"></param>
        /// <returns></returns>
        public static string ToHexLine(long addr, HexType type, byte[] buffer, bool isHighFirst = false)
        {
            string _return = ":";
            byte   crc     = (byte)(buffer.Length);

            _return += crc.ToString("X2");
            crc     += (byte)(addr >> 8);
            crc     += (byte)(addr);
            _return += addr.ToString("X4");
            crc     += (byte)(type);
            _return += ((byte)type).ToString("X2");
            for (int i = 0; i < buffer.Length; i += 2)
            {
                if (isHighFirst)
                {
                    _return += string.Format("{0:X2}{1:X2}", buffer[i + 1], buffer[i]);
                }
                else
                {
                    _return += string.Format("{0:X2}{1:X2}", buffer[i], buffer[i + 1]);
                }
                crc += buffer[i];
                crc += buffer[i + 1];
            }
            crc      = (byte)(0x100 - crc);
            _return += crc.ToString("X2");
            _return += "\r\n";
            return(_return);
        }
Пример #13
0
    public static Color color(this HexType hexType)
    {
        switch (hexType)
        {
        case HexType.FOREST:
            return(new Color(56 / 255f, 142 / 255f, 60 / 255f, 1));

        case HexType.PASTURE:
            return(new Color(139 / 255f, 195 / 255f, 74 / 255f, 1));

        case HexType.DESERT:
            return(new Color(255 / 255f, 236 / 255f, 179 / 255f, 1));

        case HexType.FIELD:
            return(new Color(255 / 255f, 235 / 255f, 59 / 255f, 1));

        case HexType.HILLS:
            return(new Color(255 / 255f, 87 / 255f, 34 / 255f, 1));

        case HexType.MOUNTAIN:
            return(new Color(97 / 255f, 97 / 255f, 97 / 255f, 1));

        default:
            return(Color.black);
        }
    }
Пример #14
0
        private static string GetCountForType(HexType hexType, World w)
        {
            const string stats = "Total {0} : {1} ({2}%)";
            var totalHexesOfType = w.TotalHexesOfType(hexType);
            var percentage = totalHexesOfType/(double)w.TotalHexes * 100;

            return string.Format(stats, hexType, totalHexesOfType, percentage);
        }
Пример #15
0
 public void SetHexType(HexType hexType)
 {
     this.HexType = hexType;
     if (HexType == HexType.PointyTop)
     {
         Hex.transform.Rotate(0, 0, 90);
     }
 }
Пример #16
0
 public HexLibrary(HexType hexType, OffsetCoordinatesType offsetCoordinatesType, float hexSize)
 {
     _hex = hexType switch
     {
         HexType.FlatTopped => new HexFlatTopped(offsetCoordinatesType, hexSize),
         HexType.PointyTopped => new HexPointyTopped(offsetCoordinatesType, hexSize),
         _ => throw new ArgumentOutOfRangeException(nameof(hexType), hexType, $"HexType {hexType} is not supported.")
     };
 }
Пример #17
0
        public PathfinderDictionary FindAllPaths(HexCell hex, HexType typeFlags, int distance)
        {
            var queue = new PathfinderQueue();
            var map   = new PathfinderDictionary();

            queue.Enqueue((hex.Position, hex.Position, 0));
            TraverseAll(queue, map, typeFlags, distance);
            return(map);
        }
Пример #18
0
 public bool ChangeCellState(HexCoordinates existingCoord, HexType newState)
 {
     if (_allCells.ContainsKey(existingCoord))
     {
         _allCells[existingCoord] = newState;
         return(true);
     }
     return(false);
 }
Пример #19
0
 public Hex(HexType type, int i)
 {
     Type       = type;
     Occupant   = null;
     Objective  = new Objective();
     Impassable = false;
     Placeable  = false;
     Owner      = null;
 }
Пример #20
0
 public Hex(HexType type, Player player)
 {
     Type       = type;
     Occupant   = null;
     Objective  = null;
     Impassable = false;
     Placeable  = true;
     Owner      = player;
 }
Пример #21
0
 public static bool IsBiome(HexType hex)
 {
     return
         (hex == HexType.FireBiome ||
          hex == HexType.WaterBiome ||
          hex == HexType.EarthBiome ||
          hex == HexType.GrowthBiome ||
          hex == HexType.ShadowBiome ||
          hex == HexType.PoisonBiome);
 }
Пример #22
0
 public static bool IsElement(HexType hex)
 {
     return
         (hex == HexType.Fire ||
          hex == HexType.Water ||
          hex == HexType.Earth ||
          hex == HexType.Growth ||
          hex == HexType.Shadow ||
          hex == HexType.Poison);
 }
Пример #23
0
 public ScriptHex(Vector2 center, float size)
 {
     hexType = HexType.NONE;
     hexNum = 0;
     hexCenter = center;
     for (int i = 0; i < 6; i++)
     {
         hexCorners[i] = GenerateHexPoint(hexCenter, size, i);
     }
 }
Пример #24
0
 public ScriptHex(Vector2 center, float size)
 {
     hexType   = HexType.NONE;
     hexNum    = 0;
     hexCenter = center;
     for (int i = 0; i < 6; i++)
     {
         hexCorners[i] = GenerateHexPoint(hexCenter, size, i);
     }
 }
Пример #25
0
        public Hex(Index2D inx, Point center,  HexType type, int height)
        {
            r = GlobalConst.DEFAULT_r;
            a = 2d / Math.Sqrt(3) * r;
            index = inx;
            this.type = type;
            this.height = height;

            if (type != HexType.Empty)
                render = new HexRender(DisplayType.GAME_SimpleGround, height, center);
        }
Пример #26
0
    void SpawnLineOf(HexType type, Hex start, Hex end)
    {
        List <Hex> hexes;

        GridManager.Instance.DrawLineOnGrid(start, end, out hexes);

        foreach (Hex h in hexes)
        {
            h.Type = type;
        }
    }
Пример #27
0
    float CostOfTile(int SourceX, int SourceY, int TargetX, int TargetY)
    {
        HexType ht   = hexType[Hexes[TargetX, TargetY]];
        float   cost = ht.movementCost;

        if (SourceX != TargetX && SourceY != TargetY)
        {
            cost += 0.001f;
        }
        return(ht.movementCost);
    }
Пример #28
0
    private HexPiece AddHexPieceToClump(HexType pieceType, Transform parent)
    {
        HexPiece newPiece = Instantiate(HexPiecePrefab, parent);

        newPiece.Type  = pieceType;
        newPiece.clump = this;
        _pieces.Add(newPiece);
        _startingPositions[newPiece] = newPiece.transform.position;

        return(newPiece);
    }
Пример #29
0
    public void createCard(HexType hexType)
    {
        Card card = Instantiate(cardPrefab).GetComponent <Card>();

        //if (cardSize == Vector3.zero) cardSize = card.GetComponent<Renderer>().bounds.size;
        card.index            = cards.Count;
        card.transform.parent = this.transform;
        card.hexType          = hexType;
        cards.Add(card);

        reposition();
    }
Пример #30
0
    private void CreateRandomShapedClump(HexType clumpType, int clumpSize)
    {
        HexCell currentCell = _clumpGrid.GetCenterCell();

        AddHexPieceToClump(clumpType, currentCell.transform);

        for (int i = 1; i < clumpSize; ++i) // For each remaining piece to be created
        {
            currentCell = currentCell.GetRandomEmptyNeighbour();
            AddHexPieceToClump(clumpType, currentCell.transform);
        }
    }
Пример #31
0
    void GenerateMapVisualHexes()
    {
        double r = 0, c = 0, z = 0;

        for (int x = 0; x < MapSizeX; x++)
        {
            if (x % 2 == 0)
            {
                r = 0;
            }
            else
            {
                r = 0.95;
            }

            for (int y = 0; y < MapSizeY; y++)
            {
                HexType ht = hexType[Hexes[x, y]];

                //different levels of hex types (buffs, mountains, debuffs)
                switch (Hexes[x, y])
                {
                case 0: z = 0;
                    break;

                case 1: z = 0.5;
                    break;

                case 2: z = -0.5;
                    break;

                default: z = 0;
                    break;
                }

                //Used to set the prefab on the map as well as able to get the object that was clicked on.
                GameObject gObject = (GameObject)Instantiate(ht.VisualHexPrefab, new Vector3((float)r, (float)c, (float)z), Quaternion.identity);
                gObject.name = "Hex_" + x + "_" + y;
                gObject.transform.SetParent(this.transform);
                gObject.GetComponent <ClickableHex>().clearSelectedUnit();
                ClickableHex clickhex = gObject.GetComponent <ClickableHex>();

                clickhex.HexX = x;
                clickhex.HexY = y;
                //Debug.Log(clickhex.HexX + " ,  " + clickhex.HexY);
                clickhex.map = this;

                r = r + 1.9; //X coordinates
            }
            c = c + 1.6;     // Y coordinates
        }
    }
Пример #32
0
    // Fill the selected hex with the
    public void Fill(HexType playerType)
    {
        // If the hex already has a type, return
        if (currentType != HexType.None)
        {
            return;
        }

        currentType = playerType;
        SetTileMesh();

        GetComponent <MeshRenderer>().enabled = false;
    }
Пример #33
0
 protected void SetForceField(bool b)
 {
     if (b)
     {
         type           = CurrentHexType;
         CurrentHexType = HexType.WalledImpassable;
         Debug.Log("walled " + name);
     }
     else
     {
         CurrentHexType = type;
         Debug.Log("No longer walled " + name);
     }
 }
 public void addResource(int playerIndex, int turn, HexType resource)
 {
     resourcesOnTurn[playerIndex][turn].Add(resource);
 }
Пример #35
0
	void Awake() {
		hexType = HexType.Grass;
		roadBlock = null;
		setTexture (0);
		gameController = GameObject.Find ("GameController");
	}
Пример #36
0
	// Sets the type of the hexa and switces the texture 
	public void setType(HexType type) {
		hexType = type;
		switch (type) {
		case HexType.Grass:
			setTexture (0);
			break;
		case HexType.Road:
			setTexture (1);
			break;
		case HexType.Mountain:
			//setTexture (2);
			break;
		case HexType.End:
			setTexture (3);
			break;
		}
	}
Пример #37
0
 void Awake()
 {
     hexType = HexType.Grass;
     roadBlock = null;
     setTexture (0);
     gameController = GameObject.Find ("GameController");
     selecter = GameObject.Find("MapHexaSelectHighlight");
 }
Пример #38
0
 void Awake()
 {
     hexType = new HexType(HexType.BlockType.Fire);
 }
Пример #39
0
 public int TotalHexesOfType(HexType hexType)
 {
     return Hexes.Where(h => h.HexType == hexType).Count();
 }
Пример #40
0
 public ScriptHex()
 {
     hexType = HexType.NONE;
     hexNum = 0;
 }