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); }
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)); } }
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); } } }
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; }