Beispiel #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);
    }
Beispiel #2
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);
        }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        EditorMainThread.Instance.Update();
        CheckThread.Instance.Update();

        if (Input.GetAxis("Fire1") > 0 && lastClick == 0)
        {
            Vector3 pos = Input.mousePosition;
            pos.x = (pos.x / GameVO.Instance.PixelWidth - 0.5f) * GameVO.Instance.Width;
            pos.y = (pos.y / GameVO.Instance.PixelHeight - 0.5f) * GameVO.Instance.Height;

            Point2D p = HaxgonCoord <Point2D> .PositionToCoord(Point2D.Create(pos.x - offx, pos.y - offy), 0.4f);

            GridVO grid = EditorVO.Instance.GetGrid((int)p.x, (int)p.y);
            if (grid != null)
            {
                grid.color.value = EditorVO.Instance.color.value;
            }


            p = HaxgonCoord <Point2D> .PositionToCoord(Point2D.Create(pos.x - offx1, pos.y - offy1), 0.4f);

            grid = EditorVO.Instance.GetGrid1((int)p.x, (int)p.y);
            if (grid != null)
            {
                grid.color.value = EditorVO.Instance.color.value;
            }
            new CreateLevelCommand();
            DrawPieces();
        }
        lastClick = Input.GetAxis("Fire1");

        int max = 0;

        for (int i = 0; i < LevelConfig.Configs.Count; i++)
        {
            if (LevelConfig.Configs[i].id > max)
            {
                max = LevelConfig.Configs[i].id;
            }
        }
        maxLevelTxt.text = "最大关卡:" + max;
    }
Beispiel #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);
    }
Beispiel #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);
                }
            }
        }