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