示例#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);
        }
    private GridVO GetGridNextTo(int x, int y, int color, List <GridVO> grids)
    {
        List <Point2D> nextCoords = HaxgonCoord <Point2D> .GetCoordsNextTo(Point2D.Create(x, y));

        for (int i = 0; i < grids.Count; i++)
        {
            for (int n = 0; n < nextCoords.Count; n++)
            {
                if (grids[i].x.value == nextCoords[n].x && grids[i].y.value == nextCoords[n].y && grids[i].color.value == color)
                {
                    return(grids[i]);
                }
            }
        }
        return(null);
    }
示例#5
0
 private void OnControl(lib.Event e)
 {
     if (e.Type == ControlInputEvent.LEFT)
     {
         GameData.Instance.camera.Position = Point2D.Create(GameData.Instance.camera.Position.X - 0.01f, GameData.Instance.camera.Position.Y);
     }
     else if (e.Type == ControlInputEvent.RIGHT)
     {
         GameData.Instance.camera.Position = Point2D.Create(GameData.Instance.camera.Position.X + 0.01f, GameData.Instance.camera.Position.Y);
     }
     else if (e.Type == ControlInputEvent.UP)
     {
         GameData.Instance.camera.Position = Point2D.Create(GameData.Instance.camera.Position.X, GameData.Instance.camera.Position.Y + 0.01f);
     }
     else if (e.Type == ControlInputEvent.DOWN)
     {
         GameData.Instance.camera.Position = Point2D.Create(GameData.Instance.camera.Position.X, GameData.Instance.camera.Position.Y - 0.01f);
     }
 }
示例#6
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;
    }
示例#7
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);
    }
示例#8
0
    public GameCheck(LevelConfig config)
    {
        //外面有 23 x 9 的大小
        HaxgonCoord <Coord> sys = new HaxgonCoord <Coord>();

        for (int py = 0; py > miny; py--)
        {
            for (int x = 0; x < maxx; x++)
            {
                int y = py - 3 + movesy[x];
                sys.SetCoord(Point2D.Create(x, y), new Coord {
                    type = 0
                });
            }
        }

        //颜色信息
        int type = 1;

        //生成片信息
        for (int i = 0; i < config.pieces.Count; i++)
        {
            Piece piece = new Piece();
            piece.isAnswer = true;
            pieces[i]      = piece;
            for (int p = 0; p < config.pieces[i].coords.Count; p++)
            {
                Coord coord = new Coord
                {
                    x     = config.pieces[i].coords[p].x,
                    y     = config.pieces[i].coords[p].y,
                    piece = piece,
                    type  = type
                };
                piece.coords.Add(coord);
            }
            type++;
            piece.Init();
        }
        for (int i = 0; i < config.pieces2.Count; i++)
        {
            Piece piece = new Piece();
            piece.isAnswer = false;
            pieces.Add(piece);
            for (int p = 0; p < config.pieces2[i].coords.Count; p++)
            {
                Coord coord = new Coord
                {
                    x     = config.pieces2[i].coords[p].x,
                    y     = config.pieces2[i].coords[p].y,
                    piece = piece,
                    type  = type
                };
                piece.coords.Add(coord);
            }
            type++;
            piece.Init();
        }

        //创建主坐标系
        for (int i = 0; i < pieces.length; i++)
        {
            Piece piece = pieces[i];
            if (AutoSetPiece(pieces[i], sys) == null)
            {
                ThreadEvent te = ThreadEvent.Create("tip", "片超出范围 : 关卡" + config.id);
                ThreadEventList.GetList(CheckThread.ThreadId, EditorMainThread.ThreadId).AddEvent(te);
            }
        }
    }
示例#9
0
    private void CheckLevelPiecePosition(LevelConfig config)
    {
        //外面有 23 x 9 的大小
        HaxgonCoord <Coord> sys = new HaxgonCoord <Coord>();

        for (int py = 0; py > miny; py--)
        {
            for (int x = 0; x < maxx; x++)
            {
                int y = py - 3 + movesy[x];
                sys.SetCoord(Point2D.Create(x, y), new Coord {
                    type = 0
                });
            }
        }

        Array <Piece> pieces = new Array <Piece>();

        //颜色信息
        int type = 1;

        //生成片信息
        for (int i = 0; i < config.pieces.Count; i++)
        {
            Piece piece = new Piece();
            piece.isAnswer = true;
            pieces[i]      = piece;
            for (int p = 0; p < config.pieces[i].coords.Count; p++)
            {
                Coord coord = new Coord
                {
                    x     = config.pieces[i].coords[p].x,
                    y     = config.pieces[i].coords[p].y,
                    piece = piece,
                    type  = type
                };
                piece.coords.Add(coord);
            }
            type++;
            piece.Init();
        }
        for (int i = 0; i < config.pieces2.Count; i++)
        {
            Piece piece = new Piece();
            piece.isAnswer = false;
            pieces.Add(piece);
            for (int p = 0; p < config.pieces2[i].coords.Count; p++)
            {
                Coord coord = new Coord
                {
                    x     = config.pieces2[i].coords[p].x,
                    y     = config.pieces2[i].coords[p].y,
                    piece = piece,
                    type  = type
                };
                piece.coords.Add(coord);
            }
            type++;
            piece.Init();
        }

        config.coords.Clear();
        //创建主坐标系
        for (int i = 0; i < pieces.length; i++)
        {
            Piece   piece = pieces[i];
            Point2D p     = AutoSetPiece(pieces[i], sys);
            int     key   = ((int)(p.x)) * 1000 + -(int)(p.y);
            if (CoordConfig.GetConfig(key) == null)
            {
                CoordConfig coord = new CoordConfig();
                coord.x  = (int)p.x;
                coord.y  = (int)p.y;
                coord.id = key;
                CoordConfig.Configs.Add(coord);
            }
            config.coords.Add(CoordConfig.GetConfig(key));
        }
    }
示例#10
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);
                }
            }
        }
示例#11
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);
        }
示例#12
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 + " 缺少片信息");
                }
            }
        }
    }
示例#13
0
    private void SetPiece(EditorLevelPiece piece)
    {
        List <GridVO> grids = EditorVO.Instance.piecesGrids;
        int           minx  = piece.grids[0].x;
        int           maxy  = piece.grids[0].y;

        for (int i = 1; i < piece.grids.Count; i++)
        {
            if (piece.grids[i].x < minx)
            {
                minx = piece.grids[i].x;
            }
            if (piece.grids[i].y > maxy)
            {
                maxy = piece.grids[i].y;
            }
        }
        int offx = minx % 2 == 0 ? -minx : -minx + 1;
        int offy = -maxy;

        for (int y = 0; y > -10; y--)
        {
            for (int x = 0; x < 22; x++, x++)
            {
                bool find = true;
                for (int i = 0; i < piece.grids.Count; i++)
                {
                    GridVO grid = EditorVO.Instance.GetGridPiece((int)piece.grids[i].x + offx + x, (int)piece.grids[i].y + offy + y);
                    if (grid == null || grid.color.value != 0)
                    {
                        find = false;
                        break;
                    }
                    else
                    {
                        //获取周围的格子
                        List <Point2D> nextCoords = HaxgonCoord <Point2D> .GetCoordsNextTo(Point2D.Create((int)piece.grids[i].x + offx + x, (int)piece.grids[i].y + offy + y));

                        for (int n = 0; n < nextCoords.Count; n++)
                        {
                            GridVO nextGrid = EditorVO.Instance.GetGridPiece((int)nextCoords[n].x, (int)nextCoords[n].y);
                            if (nextGrid != null && nextGrid.color.value != 0 && nextGrid.color.value != grid.color.value)
                            {
                                find = false;
                                break;
                            }
                        }
                    }
                }
                if (find)
                {
                    for (int i = 0; i < piece.grids.Count; i++)
                    {
                        EditorVO.Instance.GetGridPiece((int)piece.grids[i].x + offx + x, (int)piece.grids[i].y + offy + y).color.value = piece.grids[i].color;
                    }
                    return;
                }
            }
        }
    }
示例#14
0
        public Game(LevelConfig config)
        {
            Instance = this;
            //创建跟接点
            root       = new GameObject();
            root.name  = "GameRoot";
            root.layer = 8;
            rootStage  = new GameObject();
            rootStage.transform.parent = root.transform;
            rootStage.name             = "rootStage";

            MainData.Instance.dispatcher.AddListener(EventType.BACK_STEP, BACK_STEP);
            MainData.Instance.dispatcher.AddListener(EventType.RESTART, OnRestart);
            MainData.Instance.dispatcher.AddListener(EventType.SHOW_TIP, OnShowTip);
            MainData.Instance.dispatcher.AddListener(EventType.HIDE_GAME, OnHideGame);
            MainData.Instance.dispatcher.AddListener(EventType.SHOW_START_EFFECT, ShowStartEffect);
            MainData.Instance.dispatcher.AddListener(EventType.SHOW_CUT, ShowCut);
            MainData.Instance.dispatcher.AddListener(hexjig.EventType.SHOW_GAME_CHANGE_OUT_EFFECT0, OnShowGameChangeOut0);
            MainData.Instance.dispatcher.AddListener(hexjig.EventType.SHOW_GAME_CHANGE_OUT_EFFECT, OnShowGameChangeOut);
            MainData.Instance.dispatcher.AddListener(hexjig.EventType.SHOW_GAME_CHANGE_IN_EFFECT, OnShowGameChangeIn);

            //外面有 23 x 9 的大小
            HaxgonCoord <Coord> sys = new HaxgonCoord <Coord>();

            for (int py = 0; py > miny; py--)
            {
                for (int x = 0; x < maxx; x++)
                {
                    int y = py - 3 + movesy[x];
                    sys.SetCoord(Point2D.Create(x, y), new Coord {
                        type = 0
                    });
                }
            }
            //颜色信息
            List <int> types1 = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
            };
            Array <int> types2 = new Array <int>();

            while (types1.Count > 0)
            {
                int index = UnityEngine.Random.Range(0, types1.Count);
                types2.Add(types1[index]);
                types1.RemoveAt(index);
            }
            int type = types2.Pop();

            //生成片信息
            for (int i = 0; i < config.pieces.Count; i++)
            {
                Piece piece = new Piece();
                piece.game     = this;
                piece.isAnswer = true;
                pieces[i]      = piece;
                for (int p = 0; p < config.pieces[i].coords.Count; p++)
                {
                    Coord coord = new Coord
                    {
                        x     = config.pieces[i].coords[p].x,
                        y     = config.pieces[i].coords[p].y,
                        piece = piece,
                        type  = type
                    };
                    piece.coords.Add(coord);
                }
                type = types2.Pop();
                piece.Init();
            }
            for (int i = 0; i < config.pieces2.Count; i++)
            {
                Piece piece = new Piece();
                piece.game     = this;
                piece.isAnswer = false;
                pieces.Add(piece);
                for (int p = 0; p < config.pieces2[i].coords.Count; p++)
                {
                    Coord coord = new Coord
                    {
                        x     = config.pieces2[i].coords[p].x,
                        y     = config.pieces2[i].coords[p].y,
                        piece = piece,
                        type  = type
                    };
                    piece.coords.Add(coord);
                }
                type = types2.Pop();
                piece.Init();
            }

            //创建主坐标系
            for (int i = 0; i < pieces.length; i++)
            {
                Piece piece = pieces[i];
                piece.outCoord = new Point2D(config.coords[i].x, config.coords[i].y);
                if (piece.isAnswer)
                {
                    for (int n = 0; n < piece.coords.length; n++)
                    {
                        Coord coord = new Coord
                        {
                            x    = piece.coords[n].x,
                            y    = piece.coords[n].y,
                            type = 0
                        };
                        coordSys.SetCoord(Point2D.Create(piece.coords[n].x, piece.coords[n].y), coord);
                    }
                }
            }

            //生成显示相关内容
            CreateDisplay();

            //计时
            MainData.Instance.time.value = 0;
            startTime = System.DateTime.Now;
        }
示例#15
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);
        }