public void CreateBlock(int x, float rotation) { V2Int[] positions = tetrominoes[currentPiece].GetBlockPositions(x, TetrisSettings.SpawnY, rotation); TetrisPiece newBlock = Instantiate(tetrominoes[currentPiece]).GetComponent <TetrisPiece>(); newBlock.transform.SetParent(transform); newBlock.gameObject.SetActive(true); newBlock.Init(this, grid, agent); newBlock.SetBlockPositions(positions); }
public TetrisPiece CreatePiece(TetrisPiece.PieceType type) { TetrisPiece tetrisPiece = this.tetrisPieceFactory.Create(); tetrisPiece.Init(type); //TetrisPiece tetrisPiece = this.tetrisPieceFactory.Generate(TetrisPiece.PieceType.I); tetrisPiece.position.row = 0; tetrisPiece.position.col = 3; RenderPiece(tetrisPiece); currentFallingPiece = tetrisPiece; return(tetrisPiece); }
public void RotateIPieceCCW() { CommonInstall(); // Use the Assert class to test conditions. TetrisPiece piece = factory.Create(); piece.Init(TetrisPiece.PieceType.I); piece.Rotate(TetrisPiece.Rotation.CCW); piece.ApplyChange(); Assert.AreEqual( "0100\n" + "0100\n" + "0100\n" + "0100", piece.GetString(), "Failed CCW rotate once"); piece.Rotate(TetrisPiece.Rotation.CCW); piece.ApplyChange(); Assert.AreEqual( "0000\n" + "0000\n" + "1111\n" + "0000", piece.GetString(), "Failed CCW rotate twice"); piece.Rotate(TetrisPiece.Rotation.CCW); piece.ApplyChange(); Assert.AreEqual( "0010\n" + "0010\n" + "0010\n" + "0010", piece.GetString(), "Failed CCW rotate three times"); piece.Rotate(TetrisPiece.Rotation.CCW); piece.ApplyChange(); Assert.AreEqual( "0000\n" + "1111\n" + "0000\n" + "0000", piece.GetString(), "Failed CCW rotate four times"); }