Esempio n. 1
0
 public void DecodeConfigItem()
 {
     for (int i = 0; i < list.Count; i++)
     {
         if (i == 1)
         {
             List <string> itemList = StringUtils.Split(list[1], ',');
             for (int n = 0; n < itemList.Count; n++)
             {
                 if (itemList[n].Length == 0)
                 {
                     continue;
                 }
                 int item = (int)StringUtils.ToNumber(itemList[n]);
                 pieces.Add(PieceConfig.GetConfig(item));
             }
         }
         if (i == 2)
         {
             List <string> itemList = StringUtils.Split(list[2], ',');
             for (int n = 0; n < itemList.Count; n++)
             {
                 if (itemList[n].Length == 0)
                 {
                     continue;
                 }
                 int item = (int)StringUtils.ToNumber(itemList[n]);
                 pieces2.Add(PieceConfig.GetConfig(item));
             }
         }
         if (i == 3)
         {
             List <string> itemList = StringUtils.Split(list[3], ',');
             for (int n = 0; n < itemList.Count; n++)
             {
                 if (itemList[n].Length == 0)
                 {
                     continue;
                 }
                 int item = (int)StringUtils.ToNumber(itemList[n]);
                 coords.Add(CoordConfig.GetConfig(item));
             }
         }
     }
     list = null;
 }
Esempio n. 2
0
    public SaveLevelCommand(int level)
    {
        //读取配置
        //ConfigDecode.Decode();

        //删除之前的 level 相关信息
        if (LevelConfig.GetConfig(level) != null)
        {
            LevelConfig old = LevelConfig.GetConfig(level);
            LevelConfig.Configs.Remove(old);
            for (int i = 0; i < old.pieces.Count; i++)
            {
                PieceConfig.Configs.Remove(PieceConfig.GetConfig(old.pieces[i].id));
            }
            for (int i = 0; i < old.pieces2.Count; i++)
            {
                PieceConfig.Configs.Remove(PieceConfig.GetConfig(old.pieces2[i].id));
            }
        }

        if (EditorVO.Instance.level.pieces.Count > 0)
        {
            LevelConfig levelConfig = new LevelConfig();
            LevelConfig.Configs.Add(levelConfig);
            levelConfig.id = level;

            for (int i = 0; i < EditorVO.Instance.level.pieces.Count; i++)
            {
                EditorLevelPiece piece       = EditorVO.Instance.level.pieces[i];
                PieceConfig      pieceConfig = new PieceConfig();
                levelConfig.pieces.Add(pieceConfig);
                pieceConfig.id = level * 100 + i;
                for (int c = 0; c < piece.grids.Count; c++)
                {
                    if (CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y) == null)
                    {
                        CoordConfig coord = new CoordConfig();
                        coord.x  = piece.grids[c].x;
                        coord.y  = piece.grids[c].y;
                        coord.id = piece.grids[c].x * 1000 + -piece.grids[c].y;
                        CoordConfig.Configs.Add(coord);
                    }
                    pieceConfig.coords.Add(CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y));
                }
                PieceConfig.Configs.Add(pieceConfig);
            }

            for (int i = 0; i < EditorVO.Instance.level.otherPieces.Count; i++)
            {
                EditorLevelPiece piece       = EditorVO.Instance.level.otherPieces[i];
                PieceConfig      pieceConfig = new PieceConfig();
                levelConfig.pieces2.Add(pieceConfig);
                pieceConfig.id = level * 100 + EditorVO.Instance.level.pieces.Count + i;
                for (int c = 0; c < piece.grids.Count; c++)
                {
                    if (CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y) == null)
                    {
                        CoordConfig coord = new CoordConfig();
                        coord.x  = piece.grids[c].x;
                        coord.y  = piece.grids[c].y;
                        coord.id = piece.grids[c].x * 1000 + -piece.grids[c].y;
                        CoordConfig.Configs.Add(coord);
                    }
                    pieceConfig.coords.Add(CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y));
                }
                PieceConfig.Configs.Add(pieceConfig);
            }

            CheckLevelPiecePosition(levelConfig);
        }

        //CheckAllLevelPiecePosition();

        Save();
        //CheckOut();
    }
Esempio n. 3
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));
        }
    }