void all_intersect(xy t_xy) { m_stackA.Clear(); m_listB.Clear(); m_stackA.Push(t_xy); xy judgxy; xy tempxy; while (m_stackA.Count > 0) { judgxy = (xy)m_stackA.Pop(); for (int i = 0; i < m_listA.Count; i++) { if (m_listA[i] != null) { tempxy = (xy)m_listA[i]; if (intersect(CreateBobble.Instance.m_bobble[judgxy.x, judgxy.y].bobbleObject.transform.position, Config.RADIUS, CreateBobble.Instance.m_bobble[tempxy.x, tempxy.y].bobbleObject.transform.position, Config.RADIUS)) { m_stackA.Push(tempxy); m_listA[i] = null; } } } m_listB.Add(judgxy); } }
void all_intersect(xy t_xy) { stackA.Clear(); listB.Clear(); stackA.Push(t_xy); xy judgxy; xy tempxy; while (stackA.Count > 0) { judgxy = (xy)stackA.Pop(); for (int i = 0; i < listA.Count; i++) { if (listA[i] != null) { tempxy = (xy)listA[i]; if (Vector3.Distance(CreateBobble.Instance.m_bobble[judgxy.x, judgxy.y].bobbleObject.transform.position, CreateBobble.Instance.m_bobble[tempxy.x, tempxy.y].bobbleObject.transform.position) < 2 * Config.radBobble * 1.1f) { stackA.Push(tempxy); listA[i] = null; } } } listB.Add(judgxy); } }
static void Main(string[] args) { var l = new List <xy>(); string s = "L1,L3,L5,L3,R1,L4,L5,R1,R3,L5,R1,L3,L2,L3,R2,R2,L3,L3,R1,L2,R1,L3,L2,R4,R2,L5,R4,L5,R4,L2,R3,L2,R4,R1,L5,L4,R1,L2,R3,R1,R2,L4,R1,L2,R3,L2,L3,R5,L192,R4,L5,R4,L1,R4,L4,R2,L5,R45,L2,L5,R4,R5,L3,R5,R77,R2,R5,L5,R1,R4,L4,L4,R2,L4,L1,R191,R1,L1,L2,L2,L4,L3,R1,L3,R1,R5,R3,L1,L4,L2,L3,L1,L1,R5,L4,R1,L3,R1,L2,R1,R4,R5,L4,L2,R4,R5,L1,L2,R3,L4,R2,R2,R3,L2,L3,L5,R3,R1,L4,L3,R4,R2,R2,R2,R1,L4,R4,R1,R2,R1,L2,L2,R4,L1,L2,R3,L3,L5,L4,R4,L3,L1,L5,L3,L5,R5,L5,L4,L2,R1,L2,L4,L2,L4,L1,R4,R4,R5,R1,L4,R2,L4,L2,L4,R2,L4,L1,L2,R1,R4,R3,R2,R2,R5,L1,L2"; var ps = s.Split(','); int x = 0, y = 0, f = 0; for (int i = 0; i < ps.Length; i++) { if (ps[i][0] == 'L') { f -= 1; } else { f += 1; } if (f < 0) { f += 4; } if (f > 3) { f -= 4; } var p = int.Parse(ps[i].Substring(1)); for (int j = 0; j < p; j++) { xy my = new xy { x = x, y = y }; if (l.Contains(my)) { break; } l.Add(my); if (f == 0) { x -= 1; } else if (f == 1) { y -= 1; } else if (f == 2) { x += 1; } else if (f == 3) { y += 1; } } } Console.WriteLine(x + " " + y); }
protected internal override xyz Cross(LineType ViewLine) { Point = ModelMatrix * base.Cross(ViewLine); Params = GetUV(); if (Params.y >= 1) { Params.y = 1; } return(Surface.Value(Params.x, Params.y)); }
// Update is called once per frame void Update() { Vector2 NowCurPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); if (Input.GetKeyDown(KeyCode.Mouse0)) { if (!isOverlay) { startPos = NowPos(); if (NowCurPos.x > gridViewArr[0, 0].x && NowCurPos.x < gridViewArr[gridSize, gridSize].x && NowCurPos.y <gridViewArr[0, 0].y && NowCurPos.y> gridViewArr[gridSize, gridSize].y) { Overlay.SetActive(true); OverlayStartPos = NowPos(); } } else { if (NowCurPos.x > gridViewArr[0, 0].x && NowCurPos.x < gridViewArr[gridSize, gridSize].x && NowCurPos.y <gridViewArr[0, 0].y && NowCurPos.y> gridViewArr[gridSize, gridSize].y) { } else { isOverlay = false; Direction_Button.SetActive(false); Direction_Button_Division.SetActive(false); Overlay.SetActive(false); OverlayStartPos = new xy(); OverlayEndPos = new xy(); } } } if (Input.GetKeyUp(KeyCode.Mouse0) && !isOverlay) { endPos = NowPos(); if (NowCurPos.x > gridViewArr[0, 0].x && NowCurPos.x < gridViewArr[gridSize, gridSize].x && NowCurPos.y <gridViewArr[0, 0].y && NowCurPos.y> gridViewArr[gridSize, gridSize].y) { Overlay.SetActive(false); Operate(); } } else if (Input.GetKey(KeyCode.Mouse0) && NowCurPos.x > gridViewArr[0, 0].x && NowCurPos.x < gridViewArr[gridSize, gridSize].x && NowCurPos.y <gridViewArr[0, 0].y && NowCurPos.y> gridViewArr[gridSize, gridSize].y && !isOverlay) { OverlayEndPos = NowPos(); Overlay.SetActive(true); Set_Overlay(); } else if (Input.GetKey(KeyCode.Mouse0) & !isOverlay) { Overlay.SetActive(false); } }
public override void OnPaint() { base.OnPaint(); double FirstLine = 2; xy Size = getEnvText(Arial, "Drawing 3d"); drawText(Arial, new xyz(-Size.x / 2, FirstLine, 0), "Drawing 3d", 1); Size = getEnvText(Arial, "for") * 1; drawText(Arial, new xyz(-Size.x / 2, FirstLine - Size.y, 0), "for", 1); Size = getEnvText(Arial, "Windows") * 1; drawText(Arial, new xyz(-Size.x / 2, FirstLine - 2 * Size.y, 0), "Windows", 1); }
public int solution(int[] A) { var positions = new xy[A.Length]; for (int i = 0; i < A.Length; i++) { positions[i] = new xy() { ind = i, left = i - A[i], right = i + A[i] }; } throw new NotImplementedException(); }
public override Base GetBase() { xy UV = GetUV(); if ((UV.x < 0) || (UV.x < 0) || (UV.y < 0) || (UV.y < 0)) { } Base B = Base.UnitBase; B.BaseO = Surface.Value(UV.x, UV.y); B.BaseZ = Surface.Normal(UV.x, UV.y).normalized();; B.BaseX = Surface.uDerivation(UV.X, UV.Y).normalized(); B.BaseY = B.BaseZ & B.BaseX; B = this.ModelMatrix * B; return(B); }
void Set_Overlay() { xy LT, RB = new xy(); LT.x = OverlayStartPos.x < OverlayEndPos.x ? OverlayStartPos.x : OverlayEndPos.x; LT.y = OverlayStartPos.y < OverlayEndPos.y ? OverlayStartPos.y : OverlayEndPos.y; RB.x = OverlayStartPos.x > OverlayEndPos.x ? OverlayStartPos.x : OverlayEndPos.x; RB.y = OverlayStartPos.y > OverlayEndPos.y ? OverlayStartPos.y : OverlayEndPos.y; Overlay_Top.transform.position = (gridViewArr[LT.x, LT.y] + gridViewArr[RB.x + 1, LT.y]) / 2; Overlay_Top.transform.localScale = new Vector3(RB.x - LT.x + 1f, 1f, 1f) * (4f / gridSize); Overlay_Bottom.transform.position = (gridViewArr[LT.x, RB.y + 1] + gridViewArr[RB.x + 1, RB.y + 1]) / 2; Overlay_Bottom.transform.localScale = new Vector3(RB.x - LT.x + 1f, 1f, 1f) * (4f / gridSize);; Overlay_Left.transform.position = (gridViewArr[LT.x, LT.y] + gridViewArr[LT.x, RB.y + 1]) / 2; Overlay_Left.transform.localScale = new Vector3(1f, RB.y - LT.y + 1f, 1f) * (4f / gridSize);; Overlay_Right.transform.position = (gridViewArr[RB.x + 1, LT.y] + gridViewArr[RB.x + 1, RB.y + 1]) / 2; Overlay_Right.transform.localScale = new Vector3(1f, RB.y - LT.y + 1f, 1f) * (4f / gridSize);; Overlay_field.transform.position = (gridViewArr[LT.x, LT.y] + gridViewArr[RB.x + 1, RB.y + 1]) / 2; Overlay_field.transform.localScale = new Vector3(RB.x - LT.x + 1f, RB.y - LT.y + 1f, 1f) * (4f / gridSize);; }
public LifeGamePresets(int x, int y) { int xHalf = x / 2; int yHalf = y / 2; if (x >= 3 && y >= 3) { blinker = new xy[3] { new xy(xHalf, yHalf), new xy(xHalf, yHalf - 1), new xy(xHalf, yHalf + 1) }; } else { blinker = new xy[0]; } if (x >= 2 && y >= 2) { block = new xy[4] { new xy(xHalf, yHalf), new xy(xHalf, yHalf + 1), new xy(xHalf + 1, yHalf), new xy(xHalf + 1, yHalf + 1) }; } else { block = new xy[0]; } int randomSize = Random.Range(0, x * y + 1); random = new xy[randomSize]; for (int i = 0; i < randomSize; i++) { int randomX = Random.Range(0, x); int randomY = Random.Range(0, y); random[i] = new xy(randomX, randomY); } }
xy NowPos() // 현재 마우스 커서가 grid 속 어느 부분에 있는지 xy형태로 반환 { xy result = new xy(gridSize, gridSize); Vector2 NowCurPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); if (NowCurPos.x > gridViewArr[0, 0].x && NowCurPos.x < gridViewArr[gridSize, gridSize].x && NowCurPos.y <gridViewArr[0, 0].y && NowCurPos.y> gridViewArr[gridSize, gridSize].y) { for (int i = 0; i < gridSize; i++) { if (NowCurPos.x >= gridViewArr[i, 0].x && NowCurPos.x < gridViewArr[i + 1, 0].x) { for (int j = 0; j < gridSize; j++) { if (NowCurPos.y <= gridViewArr[0, j].y && NowCurPos.y > gridViewArr[0, j + 1].y) { result = new xy(i, j); } } } } } return(result); }
// Find the near point when the bobble stop xy NearPoint(Vector3 point) { float length = 100f; xy nearpoint = new xy(); for (int i = m_x - 1; i >= 0; i--) { for (int j = 0; j < m_y - (i % 2); j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject == null) { float tempLen = Vector3.Distance(point, CreateBobble.Instance.m_bobble[i, j].pointObject.transform.position); if (tempLen < length) { length = tempLen; nearpoint.x = i; nearpoint.y = j; } } } } return(nearpoint); }
void OnCollisionEnter(Collision collision) { if (collision.collider.tag == Config.staticBobble || collision.collider.tag == Config.topWall) { GetComponent <Rigidbody>().velocity = Vector3.zero; Destroy(GetComponent <StopBobble>()); tag = Config.staticBobble; m_xy = NearPoint(transform.position); GetComponent <Rigidbody>().isKinematic = true; transform.position = CreateBobble.Instance.m_bobble[m_xy.x, m_xy.y].pointObject.transform.position; GetComponent <BobbleProperty>().stop = true; if (Cannon.Instance.creatable == true) { CreateShootBobble(); Cannon.Instance.creatable = false; } // Put all the same color bobbles into list A listA.Clear(); for (int i = 0; i < m_x; i++) { for (int j = 0; j < m_y - i % 2; j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject != null) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject.GetComponent <BobbleProperty>().color == GetComponent <BobbleProperty>().color) { xy t_xy; t_xy.x = i; t_xy.y = j; listA.Add(t_xy); } } } } CreateBobble.Instance.m_bobble[m_xy.x, m_xy.y].bobbleObject = this.gameObject; // Defeat detect for (int i = 0; i < m_x; i++) { for (int j = 0; j < m_y - i % 2; j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject != null) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject.transform.position.x >= (GameObject.Find("Moving Up").transform.position.x - Config.defeatDistance)) { Cannon.Instance.defeat = true; } } } } // Find the intersect same color bobbles and put them into list B all_intersect(m_xy); // If there are three same color intersect if (listB.Count >= 3) { for (int i = 0; i < listB.Count; i++) { xy t_xy = (xy)listB[i]; CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject.GetComponent <BobbleProperty>().popped = true; Cannon.Instance.PoppedScore(); CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject = null; } } // Drop bobbles listA.Clear(); listB.Clear(); stackA.Clear(); // Put all the bobbles except row 1 into list A for (int i = 1; i < m_x; i++) { for (int j = 0; j < m_y - i % 2; j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject != null) { xy t_xy; t_xy.x = i; t_xy.y = j; listA.Add(t_xy); } } } // Clean the bobble not intersect with row 1 out of list A for (int j = 0; j < m_y; j++) { if (CreateBobble.Instance.m_bobble[0, j].bobbleObject != null) { xy t_xy; t_xy.x = 0; t_xy.y = j; listA.Add(t_xy); all_intersect(t_xy); } } if (Config.debug) { Debug.Log("Rolling, List A is " + listA.Count); } if (listA.Count > 0) { for (int i = 0; i < listA.Count; i++) { if (listA[i] != null) { xy t_xy = (xy)listA[i]; if (!CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject.GetComponent <BobbleProperty>().popped) { CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject.GetComponent <BobbleProperty>().rolling = true; rollingCount++; CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject = null; } } } } if (Config.debug) { Debug.Log("Rolling count is " + rollingCount); } if (rollingCount > 0) { Cannon.Instance.RollingScore(rollingCount); } rollingCount = 0; // Victory detect for (int i = 0; i < m_x; i++) { for (int j = 0; j < m_y - i % 2; j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject == null) { Cannon.Instance.victory = true; } } } } }
public override void OnPaint() { BackColor = Color.White; switch (ActiveSnapKind) { case Snapkind.SurfaceSnapItem: // Problem Ränder //if (SnappItems.Count >0) //{ // Emission = Color.Red; // SnappItems[0].DrawTriangleInfo(); // Emission = Color.Black; // return; //} CurveExtruder CurveEx = new CurveExtruder(); CurveEx.Direction = new xyz(0, 1, 1); CurveEx.Height = -1; CurveEx.Curve = new Bezier(new xy(9, 0), new xy(6, 3), new xy(3, 3), new xy(0, 0)); CurveEx.DownPlane = new Plane(new xyz(0, 0, 0), new xyz(0, 0, 1)); CurveEx.UpPlane = new Plane(new xyz(0, 0, 0) + CurveEx.Direction * 7, CurveEx.Direction); CurveEx.Paint(this); break; case Snapkind.LineSnapItem: drawCurve(new Line(new xy(0, 0), new xy(10, 0))); break; case Snapkind.PointSnapItem: drawPoint(new xyz(4, 3, 0), 0.2); break; case Snapkind.CurveSnapItem: Curve C = new Bezier(new xy(9, 0), new xy(6, 3), new xy(3, 3), new xy(0, 0)); PolygonMode = PolygonMode.Line; Emission = Color.Black; PenWidth = 3; drawCurve(C); PolygonMode = PolygonMode.Fill; break; case Snapkind.PolyCurveSnapItem: Lights[0].Position = new xyzwf(-10, -10, 10, 1); CurveArray _Curves0 = new CurveArray(); PolygonMode = PolygonMode.Line; _Curves0.Count = 4; _Curves0[0] = new Line(new xy(-3, -3), new xy(-3, 4)); _Curves0[1] = new Line(new xy(-3, 4), new xy(4, 4)); _Curves0[2] = new Line(new xy(4, 4), new xy(4, -3)); _Curves0[3] = new Bezier(new xy(4, -3), new xy(3, -3.5), new xy(1, -3.5), new xy(-3, -3)); drawPolyCurve(_Curves0); PolygonMode = PolygonMode.Fill; break; case Snapkind.PolyPolyCurveSnapItem: Loca _Loca = new Loca(); CurveArray Curves0 = new CurveArray(); Curves0.Count = 4; Curves0[0] = new Line(new xy(-3, -3), new xy(-3, 4)); Curves0[1] = new Line(new xy(-3, 4), new xy(4, 4)); Curves0[2] = new Line(new xy(4, 4), new xy(4, -3)); Curves0[3] = new Bezier(new xy(4, -3), new xy(3, -3.5), new xy(1, -3.5), new xy(-3, -3)); _Loca.Add(Curves0); OpenGlDevice.CheckError(); CurveArray Curves1 = new CurveArray(); Curves1.Count = 4; Curves1[0] = new Line(new xy(0, 0), new xy(1, 0)); Curves1[1] = new Line(new xy(1, 0), new xy(1, 1)); Curves1[2] = new Line(new xy(1, 1), new xy(0, 1)); Curves1[3] = new Line(new xy(0, 1), new xy(0, 0)); _Loca.Add(Curves1); PolygonMode = PolygonMode.Fill; drawPolyPolyCurve(_Loca); break; case Snapkind.TextSnapItem: Font.FontSize = 4; xy Pos = getEnvText(Font, "Drawing 3D"); drawText(Font, new xyz(-Pos.X / 2, 0, 0), "Drawing 3D", 2); break; case Snapkind.MeshSnapItem: int[] Indices = new int[] { 0, 1, 2 }; xyzf[] Position = new xyzf[] { new xyzf(0, 0, 0), new xyzf(3, 5, 0), new xyzf(6, 0, 0) }; xyzf[] Normal = new xyzf[] { new xyzf(0, 0, 1), new xyzf(0, 0, 1), new xyzf(0, 0, 1) }; xyf[] Texture = new xyf[] { new xyf(0, 0), new xyf(3, 5), new xyf(6, 0) }; xyzf[] Colors = new xyzf[] { new xyzf(1, 0, 0), new xyzf(0, 1, 0), new xyzf(0, 0, 1) }; drawMesh(Indices, Position, Normal, null, Colors); break; case Snapkind.PolyLineSnapItem: xyArray Poly = new xyArray(); Poly.data = new xy[] { new xy(1, 1), new xy(3, 4), new xy(5, 4), new xy(6, 2), new xy(1, 1) }; PolygonMode = PolygonMode.Fill; PenWidth = 3; drawPolyLine(Poly); PolygonMode = PolygonMode.Fill; break; case Snapkind.CurveSnapItem3D: Bezier3D Bezier = new Bezier3D(new xyz(1, 2, 1), new xyz(3, -2, 3), new xyz(5, 3, 2), new xyz(7, 1, 1)); drawCurve(Bezier); break; case Snapkind.PolyLineSnapItem3D: xyzArray Poly3d = new xyzArray(); Poly3d.data = new xyz[] { new xyz(0, 0, 1), new xyz(0, 3, 1), new xyz(3, 3, 1), new xyz(4, 0, 1), new xyz(0, 0, 1) }; drawPolyLine(Poly3d); break; case Snapkind.PolyPolyLineSnapItem3D: xyzArray AA = new xyzArray(); AA.Add(new xyz(1, 1, 1)); AA.Add(new xyz(0, 1, 1)); AA.Add(new xyz(0, 0, 1)); AA.Add(new xyz(1, 0, 1)); AA.Add(new xyz(1, 1, 1)); xyzArray BB = new xyzArray(); BB.Add(new xyz(3, 3, 1)); BB.Add(new xyz(3, -2, 1)); BB.Add(new xyz(-1, -2, 1)); BB.Add(new xyz(-1, 3, 1)); BB.Add(new xyz(3, 3, 1)); Loxyz L = new Loxyz(); L.Add(AA); L.Add(BB); drawPolyPolyLine(L); break; case Snapkind.PolyPolyLineSnapItem: xyArray _AA = new xyArray(); _AA.Add(new xy(2, 0.5)); _AA.Add(new xy(0, 0.5)); _AA.Add(new xy(0, 0)); _AA.Add(new xy(2, 0)); _AA.Add(new xy(2, 0.5)); xyArray _BB = new xyArray(); _BB.Add(new xy(4, 4)); _BB.Add(new xy(4, -2)); _BB.Add(new xy(-1, -2)); _BB.Add(new xy(-1, 4)); _BB.Add(new xy(4, 4)); Loxy _L = new Loxy(); _L.Add(_AA); _L.Add(_BB); drawPolyPolyLine(_L); break; case Snapkind.SphereSnapItem: drawSphere(new xyz(2, 1, 1), 3); break; case Snapkind.BoxSnapItem: drawBox(new xyz(0, 0, 0), new xyz(4, 3, 4)); break; default: break; } ACursor.Paint(this); }
public void Filtracja() { int[] maska = new[] { 1, 1, 1, 1, 0, 1, 1, 1, 1 }; int WymiarMacierzy = 9; xy[] macierz = new xy[WymiarMacierzy]; int srodek = (int)Math.Sqrt(WymiarMacierzy) / 2; int q = 0; for (int i = -srodek; i <= srodek; i++) { for (int k = -srodek; k <= srodek; k++) { macierz[q].x = k; macierz[q].y = i; q++; } } double dzielnik = 0; for (int i = 0; i < maska.Length; i++) { dzielnik += maska[i]; } if (dzielnik <= 0) { dzielnik = 1.0; } for (int i = 0; i < Image.GetLength(0); i++) { for (int j = 0; j < Image.GetLength(1); j++) { double r = 0.0; double g = 0.0; double b = 0.0; for (int k = 0; k < WymiarMacierzy; k++) { int x = i + macierz[k].x; int y = j + macierz[k].y; if (x >= 0 && x < Image.GetLength(0) && y >= 0 && y < Image.GetLength(1)) { r += Image[x, y].R * maska[k]; g += Image[x, y].G * maska[k]; b += Image[x, y].B * maska[k]; } } r = r / dzielnik; g = g / dzielnik; b = b / dzielnik; if (r > 255) { r = 255; } if (r < 0) { r = 0; } if (g > 255) { g = 255; } if (g < 0) { g = 0; } if (b > 255) { b = 255; } if (b < 0) { b = 0; } Image[i, j].R = (int)r; Image[i, j].G = (int)g; Image[i, j].B = (int)b; } } }
void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.tag == Config.STATICBOBBLE || other.gameObject.tag == Config.TOPWALL) { Destroy(GetComponent <BobbleStop>()); GetComponent <Rigidbody2D>().isKinematic = true; GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Static; tag = Config.STATICBOBBLE; m_xy = NearPoint(transform.position); transform.position = CreateBobble.Instance.m_bobble[m_xy.x, m_xy.y].pointObject.transform.position; // Create new bobble if (Shooter.Instance.creatable) { CreatShotBall(); Shooter.Instance.creatable = false; } // Put all the same color bobbles into list A m_listA.Clear(); for (int i = 0; i < m_x; i++) { for (int j = 0; j < m_y - i % 2; j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject != null) //不为空泡泡 { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject.GetComponent <BobbleProperty>().color == GetComponent <BobbleProperty>().color) { xy t_xy; t_xy.x = i; t_xy.y = j; m_listA.Add(t_xy); } } } } CreateBobble.Instance.m_bobble[m_xy.x, m_xy.y].bobbleObject = this.gameObject; this.transform.parent = topWall.transform; // Defeat detect for (int i = 0; i < m_x; i++) { for (int j = 0; j < m_y - i % 2; j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject != null) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject.transform.position.y <= (GameObject.Find("Down").gameObject.transform.position.y + Config.RADIUS)) { Shooter.Instance.defeat = true; } } } } // Find the intersect same color bobbles and put them into list B all_intersect(m_xy); // If there are three same color intersect if (m_listB.Count >= 3) { for (int i = 0; i < m_listB.Count; i++) { xy t_xy = (xy)m_listB[i]; CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject.GetComponent <BobbleProperty>().popped = true; Shooter.Instance.PoppedScore(); CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject = null; } } // Drop bobbles m_listA.Clear(); m_listB.Clear(); m_stackA.Clear(); // Put all the bobbles except row 1 into list A for (int i = 1; i < m_x; i++) { for (int j = 0; j < m_y - i % 2; j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject != null) { xy t_xy; t_xy.x = i; t_xy.y = j; m_listA.Add(t_xy); } } } // Clean the bobble not intersect with row 1 out of list A for (int j = 0; j < m_y; j++) { if (CreateBobble.Instance.m_bobble[0, j].bobbleObject != null) { xy t_xy; t_xy.x = 0; t_xy.y = j; m_listA.Add(t_xy); all_intersect(t_xy); } } if (m_listA.Count > 0) { for (int i = 0; i < m_listA.Count; i++) { if (m_listA[i] != null) { xy t_xy = (xy)m_listA[i]; if (!CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject.GetComponent <BobbleProperty>().popped) { CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject.GetComponent <BobbleProperty>().dropped = true; droppedCount++; CreateBobble.Instance.m_bobble[t_xy.x, t_xy.y].bobbleObject = null; } } } } if (droppedCount > 0) { Shooter.Instance.DroppedScore(droppedCount); } droppedCount = 0; // Victory detect int temp = 1; for (int i = 0; i < m_x; i++) { for (int j = 0; j < m_y - i % 2; j++) { if (CreateBobble.Instance.m_bobble[i, j].bobbleObject != null) { temp *= 0; } } } if (temp == 1) { Shooter.Instance.victory = true; } } }
void Operate() { xy LT, RB = new xy(); LT.x = startPos.x < endPos.x ? startPos.x : endPos.x; LT.y = startPos.y < endPos.y ? startPos.y : endPos.y; RB.x = startPos.x > endPos.x ? startPos.x : endPos.x; RB.y = startPos.y > endPos.y ? startPos.y : endPos.y; OverlayLT = LT; OverlayRB = RB; if (Oper == 1) // + { bool isable = true; int cnt = 0; for (int i = LT.x; i <= RB.x; i++) { for (int j = LT.y; j <= RB.y; j++) { cnt++; if (gridNow[i, j] != 0) { isable = false; } } } if (isable && cnt == Num) { SavePreData(); for (int i = LT.x; i <= RB.x; i++) { for (int j = LT.y; j <= RB.y; j++) { gridcs.ChangeBlockColor(i, j, color); } } FinishOperate(); } else { PopDisable(); } } else if (Oper == 2) // - { bool isable = true; int cnt = 0; for (int i = LT.x; i <= RB.x; i++) { for (int j = LT.y; j <= RB.y; j++) { cnt++; if (gridNow[i, j] == 0) { isable = false; } } } if (isable && cnt == Num) { SavePreData(); for (int i = LT.x; i <= RB.x; i++) { for (int j = LT.y; j <= RB.y; j++) { gridcs.ChangeBlockColor(i, j, 0); } } FinishOperate(); } else { PopDisable(); } } else if (Oper == 3) // × { Overlay.SetActive(true); Direction_Button.SetActive(true); bool isable = true; for (int i = LT.x; i <= RB.x; i++) { for (int j = LT.y; j <= RB.y; j++) { if (gridNow[i, j] == 0) { isable = false; } } } if (!isable) { Overlay.SetActive(false); Direction_Button.SetActive(false); goto end; } bool isableUp, isableDown, isableLeft, isableRight; isableUp = isableDown = isableLeft = isableRight = true; //위로 가능한지 확인 if (LT.y - (Num - 1) * (RB.y - LT.y + 1) < 0) { isableUp = false;; } else { for (int i = LT.x; i <= RB.x; i++) { for (int j = LT.y - 1; j >= LT.y - (Num - 1) * (RB.y - LT.y + 1); j--) { if (gridNow[i, j] != 0) { isableUp = false; } } } } //아래로 가능한지 확인 if (RB.y + (Num - 1) * (RB.y - LT.y + 1) >= gridSize) { isableDown = false;; } else { for (int i = LT.x; i <= RB.x; i++) { for (int j = RB.y + 1; j <= RB.y + (Num - 1) * (RB.y - LT.y + 1); j++) { if (gridNow[i, j] != 0) { isableDown = false; } } } } //왼쪽로 가능한지 확인 if (LT.x - (Num - 1) * (RB.x - LT.x + 1) < 0) { isableLeft = false; } else { for (int i = LT.x - 1; i >= LT.x - (Num - 1) * (RB.x - LT.x + 1); i--) { for (int j = LT.y; j <= RB.y; j++) { if (gridNow[i, j] != 0) { isableLeft = false; } } } } //오른쪽으로 가능한지 확인 if (RB.x + (Num - 1) * (RB.x - LT.x + 1) >= gridSize) { isableRight = false; } else { for (int i = RB.x + 1; i <= RB.x + (Num - 1) * (RB.x - LT.x + 1); i++) { for (int j = LT.y; j <= RB.y; j++) { if (gridNow[i, j] != 0) { isableRight = false; } } } } UpButton.transform.position = (gridViewArr[LT.x, LT.y] + gridViewArr[RB.x + 1, LT.y]) / 2f + new Vector2(0f, 50f) * ratio; DownButton.transform.position = (gridViewArr[LT.x, RB.y + 1] + gridViewArr[RB.x + 1, RB.y + 1]) / 2f - new Vector2(0f, 50f) * ratio; LeftButton.transform.position = (gridViewArr[LT.x, LT.y] + gridViewArr[LT.x, RB.y + 1]) / 2f - new Vector2(50f, 0f) * ratio; RightButton.transform.position = (gridViewArr[RB.x + 1, LT.y] + gridViewArr[RB.x + 1, RB.y + 1]) / 2f + new Vector2(50f, 0f) * ratio; if (isableUp || isableDown || isableLeft || isableRight) { isOverlay = true; } UpButton.SetActive(isableUp); DownButton.SetActive(isableDown); LeftButton.SetActive(isableLeft); RightButton.SetActive(isableRight); end :; } else if (Oper == 4) // ÷ { Overlay.SetActive(true); Direction_Button_Division.SetActive(true); bool isable = true; for (int i = LT.x; i <= RB.x; i++) { for (int j = LT.y; j <= RB.y; j++) { if (gridNow[i, j] == 0) { isable = false; } } } if (!isable) { Overlay.SetActive(false); Direction_Button_Division.SetActive(false); goto end; } bool isVertical, isHorizental; isVertical = isHorizental = true; if ((RB.x - LT.x + 1) % Num != 0) { isHorizental = false; } else { for (int j = LT.y; j <= RB.y; j++) { for (int k = 0; k < ((RB.x - LT.x + 1) / Num); k++) { for (int i = LT.x + ((RB.x - LT.x + 1) / Num) + k; i <= RB.x; i += ((RB.x - LT.x + 1) / Num)) { if (gridNow[i, j] != gridNow[LT.x + k, j]) { isHorizental = false; } } } } } if ((RB.y - LT.y + 1) % Num != 0) { isVertical = false; } else { for (int i = LT.x; i <= RB.x; i++) { for (int k = 0; k < ((RB.y - LT.y + 1) / Num); k++) { for (int j = LT.y + ((RB.y - LT.y + 1) / Num) + k; j <= RB.y; j += ((RB.y - LT.y + 1) / Num)) { if (gridNow[i, j] != gridNow[i, LT.y + k]) { isVertical = false; } } } } } DownButton_Division.transform.position = (gridViewArr[LT.x, LT.y] + gridViewArr[RB.x + 1, LT.y]) / 2f - new Vector2(0f, 50f) * ratio; UpButton_Division.transform.position = (gridViewArr[LT.x, RB.y + 1] + gridViewArr[RB.x + 1, RB.y + 1]) / 2f + new Vector2(0f, 50f) * ratio; RightButton_Division.transform.position = (gridViewArr[LT.x, LT.y] + gridViewArr[LT.x, RB.y + 1]) / 2f + new Vector2(50f, 0f) * ratio; LeftButton_Division.transform.position = (gridViewArr[RB.x + 1, LT.y] + gridViewArr[RB.x + 1, RB.y + 1]) / 2f - new Vector2(50f, 0f) * ratio; if (isVertical || isHorizental) { isOverlay = true; } UpButton_Division.SetActive(isVertical); DownButton_Division.SetActive(isVertical); LeftButton_Division.SetActive(isHorizental); RightButton_Division.SetActive(isHorizental); end :; } else if (Oper == 5) // change_color { if (color_from != 0 && color_to != 0) { SavePreData(); for (int i = LT.x; i <= RB.x; i++) { for (int j = LT.y; j <= RB.y; j++) { if (gridNow[i, j] == color_from) { gridcs.ChangeBlockColor(i, j, color_to); } } } FinishOperate(); } } else if (Oper == 6) // erase_line { if (is_Vertical == 1) { SavePreData(); int i = LT.x; for (int j = 0; j < gridSize; j++) { gridcs.ChangeBlockColor(i, j, 0); } FinishOperate(); } else if (is_Vertical == 2) { SavePreData(); int j = LT.y; for (int i = 0; i < gridSize; i++) { gridcs.ChangeBlockColor(i, j, 0); } FinishOperate(); } } else // ? { } }