예제 #1
0
    private Point2D TrySetPiece(int x, int y, Piece piece, HaxgonCoord <Coord> sys)
    {
        bool find = true;

        for (int i = 0; i < piece.coords.length; i++)
        {
            Point2D p = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(piece.coords[i].x, piece.coords[i].y), 0.2f);

            p.x += piece.offx * 0.5f;
            p.y += piece.offy * 0.5f;
            Point2D p2 = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(x, y), 0.2f);

            p2.x += p.x;
            p2.y += p.y;
            p     = HaxgonCoord <Coord> .PositionToCoord(p2, 0.2f);

            Coord grid = sys.GetCoord(p);
            if (grid == null || grid.type != 0)
            {
                find = false;
                break;
            }
            else
            {
                //获取周围的格子
                List <Point2D> nextCoords = HaxgonCoord <Coord> .GetCoordsNextTo(p);

                for (int n = 0; n < nextCoords.Count; n++)
                {
                    Coord nextGrid = sys.GetCoord(Point2D.Create(nextCoords[n].x, nextCoords[n].y));
                    if (nextGrid != null && nextGrid.piece != grid.piece)
                    {
                        find = false;
                        break;
                    }
                }
            }
        }
        if (find)
        {
            for (int i = 0; i < piece.coords.length; i++)
            {
                Point2D p = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(piece.coords[i].x, piece.coords[i].y), 0.2f);

                p.x += piece.offx * 0.5f;
                p.y += piece.offy * 0.5f;
                Point2D p2 = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(x, y), 0.2f);

                p2.x += p.x;
                p2.y += p.y;
                p     = HaxgonCoord <Coord> .PositionToCoord(p2, 0.2f);

                sys.SetCoord(p, piece.coords[i]);
            }
            return(Point2D.Create(x, y));
        }
        return(null);
    }
예제 #2
0
        public void Init()
        {
            int   minx  = coords[0].x;
            int   maxy  = coords[0].y;
            float pminX = 1000;
            float pmaxX = -1000;
            float pminY = 1000;
            float pmaxY = -1000;

            for (int i = 0; i < coords.length; i++)
            {
                if (coords[i].x <minx || coords[i].x == minx && coords[i].y> maxy)
                {
                    minx = coords[i].x;
                    maxy = coords[i].y;
                }

                //计算所有的点位置范围
                Point2D position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coords[i].x, coords[i].y), 0.4f);

                if (position.x < pminX)
                {
                    pminX = position.x;
                }
                if (position.x > pmaxX)
                {
                    pmaxX = position.x;
                }
                if (position.y < pminY)
                {
                    pminY = position.y;
                }
                if (position.y > pmaxY)
                {
                    pmaxY = position.y;
                }
            }
            offx = -HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(minx, maxy), 0.4f).x;

            offy = -HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(minx, maxy), 0.4f).y;

            tipOffx = -pminX - (pmaxX - pminX) * 0.5f;
            tipOffy = -pminY + 1.6f;

            if (game != null)
            {
                show = new GameObject();
                show.transform.parent = game.rootStage.transform;
                tip = new GameObject();
                tip.transform.parent = game.rootStage.transform;
                shader = new GameObject();
                shader.transform.parent = game.root.transform;
                showOut = new GameObject();
                showOut.transform.parent = game.root.transform;
            }
        }
예제 #3
0
        public bool IsTouchIn(float x, float y)
        {
            if (isInStage)
            {
                Point2D p = HaxgonCoord <Coord> .PositionToCoord(Point2D.Create(x - show.transform.position.x, y - show.transform.position.y + GameVO.Instance.Height * 0.2f), 0.4f);

                for (int i = 0; i < coords.length; i++)
                {
                    if (p.x == coords[i].x && p.y == coords[i].y)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                x -= offx * 0.5f;
                y -= offy * 0.5f;

                Point2D position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(outCoord.x, outCoord.y), 0.2f);

                x -= position.x;
                y -= position.y;

                Point2D p = HaxgonCoord <Coord> .PositionToCoord(Point2D.Create(x - game.offx1, y - game.offy1), 0.2f);

                for (int i = 0; i < coords.length; i++)
                {
                    if (p.x == coords[i].x && p.y == coords[i].y)
                    {
                        return(true);
                    }
                    else
                    {
                        Point2D posCoord = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coords[i].x, coords[i].y), 0.2f);

                        posCoord.x = x - game.offx1 - posCoord.x;
                        posCoord.y = y - game.offy1 - posCoord.y;
                        posCoord   = HaxgonCoord <Coord> .PositionToCoord(posCoord, 0.4f);

                        if (posCoord.x == 0 && posCoord.y == 0)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
예제 #4
0
    private Point2D AutoSetPiece(Piece piece, HaxgonCoord <Coord> sys)
    {
        List <Point2D> list = new List <Point2D>();
        float          minX = 1000;
        float          maxX = -1000;
        float          minY = 1000;
        float          maxY = -1000;

        for (int py = 0; py > this.miny; py--)
        {
            for (int x = 0; x < this.maxx; x++)
            {
                int y = py - 3 + movesy[x];
                list.Add(Point2D.Create(x, y));
                Point2D position = HaxgonCoord <Coord> .CoordToPosition(list[list.Count - 1], 0.2f);

                if (position.x < minX)
                {
                    minX = position.x;
                }
                if (position.x > maxX)
                {
                    maxX = position.x;
                }
                if (position.y < minY)
                {
                    minY = position.y;
                }
                if (position.y > maxY)
                {
                    maxY = position.y;
                }
            }
        }
        Point2D center = HaxgonCoord <Coord> .PositionToCoord(Point2D.Create((minX + maxX) * 0.5f, (minY + maxY) * 0.5f), 0.2f);

        //从可选格子的正中心开始,以六边形的方式向外扩展找可以放的地方
        Dictionary <string, bool> findMap  = new Dictionary <string, bool>();
        Dictionary <string, bool> findMap2 = new Dictionary <string, bool>();

        findMap2.Add(center.x + "," + center.y, true);
        List <Point2D> currentList = new List <Point2D>();

        currentList.Add(center);
        while (list.Count > 0)
        {
            for (int i = 0; i < currentList.Count; i++)
            {
                //在 list 中查找该点
                bool findInList = false;
                for (int l = 0; l < list.Count; l++)
                {
                    if (list[l].x == currentList[i].x && list[l].y == currentList[i].y)
                    {
                        list.RemoveAt(l);
                        findInList = true;
                        break;
                    }
                }
                if (findInList)
                {
                    //如果找到则查看该点是否可以放
                    Point2D result = TrySetPiece((int)currentList[i].x, (int)currentList[i].y, piece, sys);
                    if (result != null)
                    {
                        return(result);
                    }
                }
            }
            List <Point2D> newList = new List <Point2D>();
            //展开所有的点
            for (int i = 0; i < currentList.Count; i++)
            {
                if (findMap.ContainsKey(currentList[i].x + "," + currentList[i].y))
                {
                    continue;
                }
                //展开
                List <Point2D> nextCoords = HaxgonCoord <Coord> .GetCoordsNextTo(currentList[i]);

                for (int n = 0; n < nextCoords.Count; n++)
                {
                    if (findMap2.ContainsKey(nextCoords[n].x + "," + nextCoords[n].y))
                    {
                        continue;
                    }
                    findMap2.Add(nextCoords[n].x + "," + nextCoords[n].y, true);
                    newList.Add(nextCoords[n]);
                }
            }
            currentList = newList;
        }
        return(null);
    }
예제 #5
0
        public void Check(float x, float y, bool showResult = false, bool save = true)
        {
            HaxgonCoord <Coord> sys = game.coordSys;

            foreach (var item in sys.coords)
            {
                Coord coord = item.Value;
                if (coord.piece == this)
                {
                    coord.piece = null;
                    coord.type  = 0;
                }
            }
            bool find = true;

            if (save)
            {
                show.transform.position = new Vector3(startDragX - startDragTouchX + x, startDragY - startDragTouchY + y + GameVO.Instance.Height * 0.2f, showResult ? 0 : -1);
            }
            else
            {
                show.transform.position = new Vector3(x, y, showResult ? 0 : -1);
            }
            for (int i = 0; i < this.coords.length; i++)
            {
                Point2D position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coords[i].x, coords[i].y), 0.4f);

                position.x += show.transform.position.x - game.offx;
                position.y += show.transform.position.y - game.offy - GameVO.Instance.Height * 0.2f;
                Point2D pos = HaxgonCoord <Coord> .PositionToCoord(position, 0.4f);

                Coord coord = sys.GetCoord(pos);
                if (coord == null || coord.piece != null)
                {
                    find = false;
                    break;
                }
            }
            if (find)
            {
                Point2D position0 = new Point2D();
                Point2D copy      = new Point2D();
                for (int i = 0; i < this.coords.length; i++)
                {
                    Point2D position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coords[i].x, coords[i].y), 0.4f);

                    if (i == 0)
                    {
                        copy.x = position.x;
                        copy.y = position.y;
                    }
                    position.x += show.transform.position.x - game.offx;
                    position.y += show.transform.position.y - game.offy - GameVO.Instance.Height * 0.2f;
                    Point2D pos = HaxgonCoord <Coord> .PositionToCoord(position, 0.4f);

                    if (i == 0)
                    {
                        position0 = HaxgonCoord <Coord> .CoordToPosition(pos, 0.4f);
                    }
                    Coord coord = sys.GetCoord(pos);
                    coord.piece = this;
                    coord.type  = coords[i].type;
                }
                if (showResult)
                {
                    if (save && !isInStage)
                    {
                        Game.Instance.history.Add(this);
                        Game.Instance.history2.Add(new Point2D(0, 0));
                    }
                    MainData.Instance.dispatcher.DispatchWith(EventType.SET_PIECE);
                    show.transform.position = new Vector3(position0.x + game.offx - copy.x, position0.y + game.offy - copy.y + GameVO.Instance.Height * 0.2f);
                    show.SetActive(true);
                    shader.SetActive(false);
                    showOut.SetActive(false);
                    isInStage = true;
                    game.CheckFinish();
                    if (isRightPosition && hasShowTip)
                    {
                        tip.transform.localPosition = new Vector3(tip.transform.localPosition.x, tip.transform.localPosition.y, 1);
                    }
                }
                else
                {
                    shader.transform.position = new Vector3(position0.x + game.offx - copy.x, position0.y + game.offy - copy.y);
                    shader.SetActive(true);
                }
            }
            else
            {
                if (showResult)
                {
                    if (save && isInStage)
                    {
                        Game.Instance.history.Add(this);
                        Game.Instance.history2.Add(new Point2D(lastx, lasty));
                    }
                    show.SetActive(false);
                    shader.SetActive(false);
                    showOut.SetActive(true);
                    isInStage = false;
                }
                else
                {
                    shader.SetActive(false);
                }
            }
        }
예제 #6
0
        public void CreateDisplay()
        {
            //创建拖动显示
            for (int i = 0; i < coords.length; i++)
            {
                GameObject image    = GameBufferPool.CreateGrid(coords[i].type);
                Point2D    position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coords[i].x, coords[i].y), 0.4f);

                image.transform.localPosition = new Vector3(position.x, position.y, 1);
                image.transform.parent        = show.transform;
            }
            show.SetActive(false);

            if (isAnswer)
            {
                //创建提示
                tipGrids = new List <SpriteRenderer>();
                for (int i = 0; i < coords.length; i++)
                {
                    GameObject image    = GameBufferPool.CreateGrid(coords[i].type);
                    Point2D    position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coords[i].x, coords[i].y), 0.4f);

                    image.transform.localPosition = new Vector3(position.x, position.y, 3);
                    image.transform.parent        = tip.transform;
                    tipGrids.Add(image.GetComponent <SpriteRenderer>());
                    image.GetComponent <SpriteRenderer>().color = new Color(image.GetComponent <SpriteRenderer>().color.r, image.GetComponent <SpriteRenderer>().color.g, image.GetComponent <SpriteRenderer>().color.b, shaderAlpha);
                }
                tip.transform.localPosition = new Vector3(Game.Instance.offx, Game.Instance.offy, -3);
                tip.SetActive(false);
            }

            //创建阴影
            for (int i = 0; i < coords.length; i++)
            {
                GameObject image = GameBufferPool.CreateGrid(coords[i].type);
                shaders.Add(image);
                Point2D position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coords[i].x, coords[i].y), 0.4f);

                image.transform.localPosition = new Vector3(position.x, position.y, 3);
                image.transform.parent        = shader.transform;
                image.GetComponent <SpriteRenderer>().color = new Color(image.GetComponent <SpriteRenderer>().color.r, image.GetComponent <SpriteRenderer>().color.g, image.GetComponent <SpriteRenderer>().color.b, shaderAlpha);
            }
            shader.SetActive(false);

            //创建库中的显示
            for (int i = 0; i < coords.length; i++)
            {
                Point2D position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coords[i].x, coords[i].y), 0.2f);

                Point2D position2 = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(outCoord.x, outCoord.y), 0.2f);

                position.x += position2.x;
                position.y += position2.y;

                GameObject image;
                image = GameBufferPool.CreateGrid(coords[i].type);
                image.transform.localScale    = new Vector3(0.5f, 0.5f);
                image.transform.localPosition = new Vector3(position.x, position.y, 3);
                image.transform.parent        = showOut.transform;


                if (!HasCoordAt(HaxgonCoord <Coord> .GetCoordNextTo(Point2D.Create(coords[i].x, coords[i].y), HaxgonCoordNextDirection.UP)))
                {
                    image = GameBufferPool.CreateGridSide();
                    image.transform.localScale    = new Vector3(0.5f, 0.5f);
                    image.transform.localPosition = new Vector3(position.x + offx * 0.5f, position.y + offy * 0.5f + 0.17f * HaxgonCoord <Coord> .halfSqrt3, 4);
                    image.transform.parent        = background.transform;
                }

                if (!HasCoordAt(HaxgonCoord <Coord> .GetCoordNextTo(Point2D.Create(coords[i].x, coords[i].y), HaxgonCoordNextDirection.RIGHT_UP)))
                {
                    image = GameBufferPool.CreateGridSide();
                    image.transform.localScale    = new Vector3(0.5f, 0.5f);
                    image.transform.localPosition = new Vector3(position.x + offx * 0.5f + 0.17f * 0.75f, position.y + offy * 0.5f + 0.5f * 0.17f * HaxgonCoord <Coord> .halfSqrt3, 4);
                    image.transform.eulerAngles   = new Vector3(0, 0, -60);
                    image.transform.parent        = background.transform;
                }

                if (!HasCoordAt(HaxgonCoord <Coord> .GetCoordNextTo(Point2D.Create(coords[i].x, coords[i].y), HaxgonCoordNextDirection.RIGHT_DOWN)))
                {
                    image = GameBufferPool.CreateGridSide();
                    image.transform.localScale    = new Vector3(0.5f, 0.5f);
                    image.transform.localPosition = new Vector3(position.x + offx * 0.5f + 0.17f * 0.75f, position.y + offy * 0.5f - 0.5f * 0.17f * HaxgonCoord <Coord> .halfSqrt3, 4);
                    image.transform.eulerAngles   = new Vector3(0, 0, 60);
                    image.transform.parent        = background.transform;
                }

                if (!HasCoordAt(HaxgonCoord <Coord> .GetCoordNextTo(Point2D.Create(coords[i].x, coords[i].y), HaxgonCoordNextDirection.DOWN)))
                {
                    image = GameBufferPool.CreateGridSide();
                    image.transform.localScale    = new Vector3(0.5f, 0.5f);
                    image.transform.localPosition = new Vector3(position.x + offx * 0.5f, position.y + offy * 0.5f - 0.17f * HaxgonCoord <Coord> .halfSqrt3, 4);
                    image.transform.parent        = background.transform;
                }

                if (!HasCoordAt(HaxgonCoord <Coord> .GetCoordNextTo(Point2D.Create(coords[i].x, coords[i].y), HaxgonCoordNextDirection.LEFT_DOWN)))
                {
                    image = GameBufferPool.CreateGridSide();
                    image.transform.localScale    = new Vector3(0.5f, 0.5f);
                    image.transform.localPosition = new Vector3(position.x + offx * 0.5f - 0.17f * 0.75f, position.y + offy * 0.5f - 0.5f * 0.17f * HaxgonCoord <Coord> .halfSqrt3, 4);
                    image.transform.eulerAngles   = new Vector3(0, 0, -60);
                    image.transform.parent        = background.transform;
                }

                if (!HasCoordAt(HaxgonCoord <Coord> .GetCoordNextTo(Point2D.Create(coords[i].x, coords[i].y), HaxgonCoordNextDirection.LEFT_UP)))
                {
                    image = GameBufferPool.CreateGridSide();
                    image.transform.localScale    = new Vector3(0.5f, 0.5f);
                    image.transform.localPosition = new Vector3(position.x + offx * 0.5f - 0.17f * 0.75f, position.y + offy * 0.5f + 0.5f * 0.17f * HaxgonCoord <Coord> .halfSqrt3, 4);
                    image.transform.eulerAngles   = new Vector3(0, 0, 60);
                    image.transform.parent        = background.transform;
                }
            }
            showOut.transform.localPosition = new Vector3(game.offx1 + offx * 0.5f, game.offy1 + offy * 0.5f);
        }
예제 #7
0
    // Use this for initialization
    void Start()
    {
        new EditorMainThread();
        new CheckThread();

        ConfigDecode.Decode();

        //删除重复的 piece 信息
        for (int i = 0; i < PieceConfig.Configs.Count; i++)
        {
            for (int j = i + 1; j < PieceConfig.Configs.Count; j++)
            {
                if (PieceConfig.Configs[i].id == PieceConfig.Configs[j].id)
                {
                    PieceConfig.Configs.RemoveAt(j);
                    EditorTip.Show("重复的片信息 : " + PieceConfig.Configs[i].id);
                    j--;
                }
            }
        }

        EditorVO.Instance.dispatcher.AddListener("UIsaveHandle", OnSave);
        EditorVO.Instance.dispatcher.AddListener("UIloadHandle", OnLoad);
        EditorVO.Instance.dispatcher.AddListener("UIclearHandle", OnClear);

        //colorDropDown.options = EditorVO.Instance.colors;
        //colorDropDown.value = EditorVO.Instance.color.value;

        //生成格子
        List <GridVO> grids = EditorVO.Instance.grids;

        for (int i = 0; i < grids.Count; i++)
        {
            GameObject obj      = ResourceManager.CreateImage("image/grid/gridBg");
            Point2D    position = HaxgonCoord <Point2D> .CoordToPosition(Point2D.Create(grids[i].x.value, grids[i].y.value), 0.4f);

            obj.transform.position             = new Vector3((float)(position.x + offx), position.y + offy);
            (obj.AddComponent <GameGrid>()).vo = grids[i];
        }

        grids = EditorVO.Instance.otherGrids1;
        for (int i = 0; i < grids.Count; i++)
        {
            GameObject obj      = ResourceManager.CreateImage("image/grid/gridBg");
            Point2D    position = HaxgonCoord <Point2D> .CoordToPosition(Point2D.Create(grids[i].x.value, grids[i].y.value), 0.4f);

            obj.transform.position             = new Vector3((float)(position.x + offx1), position.y + offy1);
            (obj.AddComponent <GameGrid>()).vo = grids[i];
        }

        grids = EditorVO.Instance.piecesGrids;
        for (int i = 0; i < grids.Count; i++)
        {
            GameObject obj = ResourceManager.CreateImage("image/grid/gridBg");
            obj.transform.localScale = new Vector3(0.5f, 0.5f);
            Point2D position = HaxgonCoord <Point2D> .CoordToPosition(Point2D.Create(grids[i].x.value, grids[i].y.value), 0.2f);

            obj.transform.position             = new Vector3((float)(position.x + 2), position.y);
            (obj.AddComponent <GameGrid>()).vo = grids[i];
        }

        for (int i = 0; i < LevelConfig.Configs.Count; i++)
        {
            for (int j = 0; j < LevelConfig.Configs[i].pieces.Count; j++)
            {
                if (LevelConfig.Configs[i].pieces[j] == null)
                {
                    EditorTip.Show("关卡 " + LevelConfig.Configs[i].id + " 缺少片信息");
                }
            }
            for (int j = 0; j < LevelConfig.Configs[i].pieces2.Count; j++)
            {
                if (LevelConfig.Configs[i].pieces2[j] == null)
                {
                    EditorTip.Show("关卡 " + LevelConfig.Configs[i].id + " 缺少片信息");
                }
            }
        }
    }
예제 #8
0
        private void CreateDisplay()
        {
            //生成背景
            float      minX = 1000;
            float      maxX = -1000;
            float      minY = 1000;
            float      maxY = -1000;
            GameObject p    = new GameObject();

            p.transform.parent = rootStage.transform;
            foreach (var item in coordSys.coords)
            {
                Coord      coord = item.Value;
                GameObject image = GameBufferPool.CreateGridBg();
                backgroundgrids.Add(image);
                Point2D position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(coord.x, coord.y), 0.4f);

                image.transform.position = new Vector3(position.x, position.y, 5);
                image.transform.parent   = p.transform;
                if (position.x < minX)
                {
                    minX = position.x;
                }
                if (position.x > maxX)
                {
                    maxX = position.x;
                }
                if (position.y < minY)
                {
                    minY = position.y;
                }
                if (position.y > maxY)
                {
                    maxY = position.y;
                }
            }
            MainData.Instance.levelWidth  = maxX - minX + 1.5f;
            MainData.Instance.levelHeight = maxY - minY + 1.5f;
            offx = -((maxX - minX) * 0.5f + minX);
            offy = -((maxY - minY) * 0.5f + minY) + GameVO.Instance.Height * 0.2f;
            p.transform.position = new Vector3(offx, offy - GameVO.Instance.Height * 0.2f);
            stageRoot            = p;

            rootStage.transform.localPosition = new Vector3(0, GameVO.Instance.Height * 0.2f);

            outBackground = new GameObject();
            outBackground.transform.parent = root.transform;
            //outBackground.SetActive(!MainData.Instance.isLoading);

            //生成背景
            minX = 1000;
            maxX = -1000;
            minY = 1000;
            maxY = -1000;
            GameObject p1 = new GameObject();

            p1.transform.parent = root.transform;
            for (int x = 0; x < this.maxx; x++)
            {
                for (int py = 0; py > this.miny; py--)
                {
                    int     y        = py - 3 + movesy[x];
                    Point2D position = HaxgonCoord <Coord> .CoordToPosition(Point2D.Create(x, y), 0.2f);

                    /*
                     * GameObject image = ResourceManager.CreateImage("image/grid/gridBg");
                     * image.transform.localScale = new Vector3(0.5f, 0.5f);
                     * image.transform.position = new Vector3(position.x, position.y,100);
                     * image.transform.parent = p1.transform;
                     * //*/

                    if (position.x < minX)
                    {
                        minX = position.x;
                    }
                    if (position.x > maxX)
                    {
                        maxX = position.x;
                    }
                    if (position.y < minY)
                    {
                        minY = position.y;
                    }
                    if (position.y > maxY)
                    {
                        maxY = position.y;
                    }
                }
            }
            offx1 = -((maxX - minX) * 0.5f + minX);
            offy1 = -((maxY - minY) * 0.5f + minY) - 2.4f;
            p1.transform.position = new Vector3(offx1, offy1);

            for (int i = 0; i < pieces.length; i++)
            {
                pieces[i].background = outBackground;
                pieces[i].CreateDisplay();
            }

            outBackground.transform.position = new Vector3(offx1, offy1);
        }