public bool IsValid(Mino mino, int rotationId, Vector2Int centerPos) { Mino t = new Mino(mino.id); t.SetRotation(rotationId); return(IsValid(t, centerPos)); }
static Rotate GetNextRotation(Move rotate, Mino mino) { int value; if (rotate == Move.RightRotate) { value = ((int)mino.rotation); value++; if (value == 4) { value = 0; } } else if (rotate == Move.LeftRotate) { value = ((int)mino.rotation); value--; if (value == -1) { value = 3; } } else { throw new Exception(); } return((Rotate)value); }
private void CreateMino() { Mino mino = ScriptableObject.CreateInstance <Mino>(); List <Vector2Int> localCoordinates = CalculateLocalCoordinates(); //BlocksLocalCoordinates Vector2IntList vectorList = new Vector2IntList(); vectorList.List.AddRange(localCoordinates); mino.AddPairInCreating(MinoSide.Bottom, vectorList); List <Vector2Int> rotateCoordinates = new List <Vector2Int>(localCoordinates); ShowCollectiction(rotateCoordinates); Debug.Log(Enum.GetNames(typeof(MinoSide)).Length); for (int index = 1; index < Enum.GetNames(typeof(MinoSide)).Length; index++) { Debug.Log("rotate"); MinoSide key = (MinoSide)index; rotateCoordinates = CalculateRotateDirectionCoordinates(rotateCoordinates); vectorList = new Vector2IntList(); vectorList.List.AddRange(rotateCoordinates); mino.AddPairInCreating(key, vectorList); ShowCollectiction(rotateCoordinates); } SaveMinoAsset(mino); }
public bool IsValid(Mino mino, Vector2Int centerPos) { int minoId = mino.GetIdInt(); int x = centerPos.x; int y = centerPos.y; Mino tmpMino = new Mino(mino.id); tmpMino.SetRotation(mino.GetRotationId()); tmpMino.SetPosition(centerPos); List <Vector2Int> l = GetAllCoordinates(tmpMino); foreach (Vector2Int v in l) { int i = v.x; int j = v.y; if (i > 9 || i < 0) { return(false); } if (j < 0) { return(false); } if (array[i, j] != 0) { return(false); } } return(true); }
public void HandleEvent(IFallable sender, FallEventArgs e) { if (sender == null || e == null) { return; } if (sender is Mino) { Mino mino = sender as Mino; Counter += mino.Game.TargetElapsedTime; if (Counter >= FallTimeSpan) { mino.Position += new Vector2(0, FallVelocity); Counter -= FallTimeSpan; } } if (sender is Polyomino) { Polyomino polyomino = sender as Polyomino; Counter += polyomino.Game.TargetElapsedTime; if (Counter >= FallTimeSpan) { foreach (Mino mino in polyomino.Minoes) { mino.Position += new Vector2(0, FallVelocity); } Counter -= FallTimeSpan; } } }
/// <summary> /// 回転したあとキックテーブルのテスト /// </summary> /// <param name="tryValue">キックテーブル</param> /// <param name="mino">回転させるミノ</param> /// <param name="field">盤面</param> /// <param name="afterRotate">回転後のrotatio算出出用</param> /// <returns></returns> static private bool TryMovetoValidPosition(Vector2[] tryValue, ref Mino mino, int[,] field, Rotate afterRotate) { Rotate temp = mino.rotation; mino.rotation = afterRotate; foreach (Vector2 pos in tryValue) { if (CheckValidPosition(field, mino.positions, pos)) { mino.positions[0].x += pos.x; mino.positions[1].x += pos.x; mino.positions[2].x += pos.x; mino.positions[3].x += pos.x; mino.positions[0].y += pos.y; mino.positions[1].y += pos.y; mino.positions[2].y += pos.y; mino.positions[3].y += pos.y; return(true); } } //回転できなかった場合元に戻す処理 SimpleRotate(temp, ref mino); mino.rotation = temp; return(false); }
public void UpdateMinosInGrid() { if (tetrominoMatrix == null) { return; } for (int row = 0; row < tetrominoMatrix.GetLength(0); row++) { bool removeRow = false; for (int col = 0; col < tetrominoMatrix.GetLength(1); col++) { Mino aux = GetMinoByIndex(row, col); if (aux != null) { if (!CheckTetrominoInGrid(aux.transform)) { removeRow = true; continue; } } } if (removeRow) { MoveMinoRowDown(row); RemoveLastMinosRow(); // we've pulled the minos to the last line UpdateMinosInGrid(); // needs to check again the rows //so we can just remove the minos the last line } } RedrawTetromino(); }
public static Vector2Int WallKickOffset(Field field, Mino mino, int A, int B, Vector2Int coordinate)//A和B都是rotationId { int size = mino.GetSize(); if (size == 3) { for (int i = 0; i < 5; i++) { //Debug.Log("A:" + A + " B:" + B); //Debug.Log(coordinate + OFFSET_3x3[i, A] - OFFSET_3x3[i, B] + " " + i); if (field.IsValid(mino, B, coordinate + OFFSET_3x3[i, A] - OFFSET_3x3[i, B])) { return(OFFSET_3x3[i, A] - OFFSET_3x3[i, B]); } } } else if (size == 5) { for (int i = 0; i < 5; i++) { if (field.IsValid(mino, B, coordinate + OFFSET_I[i, A] - OFFSET_I[i, B])) { return(OFFSET_I[i, A] - OFFSET_I[i, B]); } } } return(new Vector2Int(0, 0)); }
public void DisableMino(Mino mino) { mino.gameObject.SetActive(true); mino.transform.SetParent(poolParent.transform); mino.transform.name = ""; transform.position = Vector2.zero; }
void ApplyCurNudge() { Mino target = null; bool targetFound = false; for (int i = curCoord.y; i < manager.gridSize.y; i++) { if (manager.gridE[curCoord.x, i].state == bState.mblock) { target = manager.gridE[curCoord.x, i].transform.parent.GetComponent <Mino>(); targetFound = true; break; } } if (targetFound) { target.Nudge(curShot); } else { manager.invalidSFO.GetComponent <AudioSource>().Play(); } curShot = nextShot; nextShot = GetRandomShot(); return; }
public int LinesCanClear(Mino mino)//返回可消除的行数 { int lines = 0; List <Vector2Int> l = GetAllCoordinates(mino); List <int> ys = new List <int>();//方块占据的所有y坐标,比如竖着的长条占了4行 foreach (Vector2Int v in l) { if (!ys.Contains(v.y)) { ys.Add(v.y); } } ys.Sort(); foreach (int y in ys) { bool canClear = true; for (int j = 0; j < 10; j++) { if (array[j, y] == 0) { canClear = false; } } if (canClear) { lines++; } } return(lines); }
public bool HasThreeCorners(Mino tMino)//判定tspin的条件之一 { int x = tMino.position.x; int y = tMino.position.y; int corner = 0; for (int i = x - 1; i <= x + 1; i += 2) { for (int j = y - 1; j <= y + 1; j += 2) { if (i < 0 || 9 < i || j < 0) { corner++; continue; } if (array[i, j] != 0) { corner++; } } } if (corner >= 3) { return(true); } return(false); }
public void ShowMino(Mino mino) { List <Vector2Int> l = Field.GetAllCoordinates(mino); foreach (Vector2Int v in l) { DisplayUtils.InstChild(MinoTiles[mino.GetIdInt() - 1], new Vector3(v.x, v.y, 0), MinoParent); } }
private void PutMino(Mino mino) { game.SetActiveMino(mino); _ = game.LockMino(out _); game.NextMino(); if (showField) { UpdateFieldDisplay(); } }
public override bool Equals(object obj) { if (obj.GetType() == this.GetType()) { Mino m = obj as Mino; return(m.id == id && m.position.x == position.x && m.position.y == position.y && m.rotation == rotation); } return(base.Equals(obj)); }
static public Mino Clone(Mino mino) { Mino mino_clone = new Mino(); mino_clone.kind = mino.kind; mino_clone.positions = (Vector2[])mino.positions.Clone(); mino_clone.rotation = mino.rotation; return(mino_clone); }
public void ShowMino(int minoID, int x, int y, int rotation) { Mino mino = new Mino(minoID, x, y, rotation); List <Vector2Int> l = Field.GetAllCoordinates(mino); foreach (Vector2Int v in l) { DisplayUtils.InstChild(MinoTiles[mino.GetIdInt() - 1], new Vector3(v.x, v.y, 0), MinoParent); } }
public void LockMino(Mino currentMino) { List <Vector2Int> l = GetAllCoordinates(currentMino); foreach (Vector2Int pos in l) { array[pos.x, pos.y] = currentMino.GetIdInt(); } dig = 0; }
public int LandHeight(Mino m) { Vector2Int pos = m.position; while (IsValid(m, pos)) { pos.y--; } return(pos.y + 1); }
public int GetScore(Mino mino) { Field f = Clone(); f.LockMino(mino); if (f.LinesCanClear(mino) > 0) { f.Clear(mino); } return(f.GetScore()); }
public bool Get_ContainMino(Mino m) { if (m.MinoType == minotype && minos.Contains(m)) { return(true); } else { return(false); } }
private void MoveDown() { mino.MoveDown(); if (IsCorrectPosition(mino.Blocks)) { return; } FillStateMino(mino.Blocks); mino = null; TryDellLines(); }
public static ClearType CheckClearType(Field field, Mino mino, string op, int combo, bool wasB2B) { ClearType clearType; Field fClone = field.Clone(); fClone.LockMino(mino); int minoId = mino.GetIdInt(); int lines = fClone.LinesCanClear(mino); bool tSpin = false; int tSpinType = 0;//0mini 1single 2double 3triple bool spin = IsWallKick(op); bool pc = fClone.IsAllClear(lines); //bool wasB2b; //int combo; if (mino.id == Mino.MinoID.T)//tspin判定 { bool c, f; c = field.HasThreeCorners(mino); f = field.HasTwoFeets(mino); if (lines == 1) { //Debug.Log(cannotGoUp); if (c && f)//t-spin single { tSpin = true; tSpinType = 1; } else if (c && !f && spin)//t-spin mini { tSpin = true; tSpinType = 0; } } else if (lines == 2 && (c || spin))//t-spin double { tSpin = true; tSpinType = 2; } else if (lines == 3) { tSpin = true; tSpinType = 3; } } clearType = new ClearType(minoId, lines, tSpin, tSpinType, pc, combo, wasB2B); return(clearType); }
public bool RotateCCW(Field field, out SearchNode sn) { bool ok = false; Mino tmp = mino.Clone(); int size = tmp.GetSize(); int newRotationId = (tmp.GetRotationId() + 3) % 4; string k = "z"; if (size == 3) { if (field.IsValid(tmp, newRotationId, tmp.GetPosition()))//如果可以直接转进去 { tmp.CCWRotate(); ok = true; } else//如果不能就做踢墙检定 { Vector2Int o = Game.WallKickOffset(field, tmp, tmp.GetRotationId(), newRotationId, tmp.GetPosition()); if (o != new Vector2Int(0, 0)) { tmp.CCWRotate(); tmp.Move(o); k = "Z"; ok = true; } else { ok = false; } } } else if (size == 5) { Vector2Int o = Game.WallKickOffset_I(field, tmp, tmp.GetRotationId(), newRotationId, tmp.GetPosition(), out bool iSpin); if (o != new Vector2Int(0, 0)) { tmp.CCWRotate(); tmp.Move(o); if (iSpin) { k = "Z"; } ok = true; } else { ok = false; } } sn = new SearchNode(tmp, op + k); return(ok); }
public static List <SearchNode> GetLandPoints(Field field, Mino mino) { return(GetLandPointsKick(field, mino)); if (field.CountHole(out _) == 0) { return(GetLandPointsLite(field, mino)); } else { return(GetLandPointsKick(field, mino)); } }
// Start is called before the first frame update void Start() { mino = new Mino(NextManager.Get()); fieldTransform = FieldMinos.GetComponent <Transform>(); blockTransforms = new Transform[4]; blockSpriteRenderers = new SpriteRenderer[4]; for (int i = 0; i < blocks.Length; ++i) { blockTransforms[i] = blocks[i].GetComponent <Transform>(); blockSpriteRenderers[i] = blocks[i].GetComponent <SpriteRenderer>(); } SetSprites(); }
void RemoveLastMinosRow() { int lastRow = tetrominoMatrix.GetLength(0) - 1; for (int col = 0; col < tetrominoMatrix.GetLength(1); col++) {// the line has switched so i want to remove the above one now Mino aux = GetMinoByIndex(lastRow, col); if (aux != null) { RemoveMinoFromMatrix(aux); } } }
public bool MoveDown(Field field, out SearchNode sn) { Vector2Int newPos = mino.position; Mino tmp = mino.Clone(); bool ok = false; newPos.y--; if (field.IsValid(mino, newPos)) { tmp.Fall(); ok = true; } sn = new SearchNode(tmp, op + "d"); return(ok); }
public bool MoveRight(Field field, out SearchNode sn) { Vector2Int newPos = mino.position; Mino tmp = mino.Clone(); bool ok = false; //是否不能再往右了 newPos.x++; if (field.IsValid(mino, newPos)) { tmp.Move(1); ok = true; } sn = new SearchNode(tmp, op + "r"); return(ok); }
private void SpawnCell(Vector2Int position, Mino minoData) { if (minoData == null) { throw new ArgumentNullException("minoData"); } var cell = cellPool.Spawn(); cells[position.x, position.y] = cell; cell.SetColor(minoData.Color); var newPosition = gridComponent.CellToLocal(new Vector3Int(position.x, position.y, 0)) + gridCornerOffset; cell.SetLocalPosition(newPosition); cell.SetLocalScale(gridComponent.cellSize); }