public void TRotateTest() { TetrisPiece piece = new TetrisPiece(PieceType.T); piece.Rotate(); List <Square> squares = piece.OccupiedSquares; Assert.AreEqual(4, squares.Count); Assert.IsTrue(squares.Any(s => s.Y == 1 && s.X == 6)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 6)); Assert.IsTrue(squares.Any(s => s.Y == 3 && s.X == 6)); piece.Rotate(); squares = piece.OccupiedSquares; Assert.AreEqual(4, squares.Count); Assert.IsTrue(squares.Any(s => s.Y == 1 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 4)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 6)); piece.Rotate(); squares = piece.OccupiedSquares; Assert.AreEqual(4, squares.Count); Assert.IsTrue(squares.Any(s => s.Y == 0 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 1 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 1 && s.X == 6)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 5)); }
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"); }
public void RotatePiece() { if (currentFallingPiece != null) { currentFallingPiece.Rotate(TetrisPiece.Rotation.CW); currentFallingPiece.ApplyChange(); currentFallingPiece.RefreshView(); } }
public void IRotateEraseTest() { TetrisPiece piece = new TetrisPiece(PieceType.I); piece.Rotate(); piece.EraseRow(2); List <Square> squares = piece.OccupiedSquares; Assert.AreEqual(4, squares.Count); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 4)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 6)); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 7)); piece.EraseRow(2); squares = piece.OccupiedSquares; Assert.AreEqual(0, squares.Count); }
// Tetris Update data private void Tick() { // slowdown for player since they don't play at framerate speed if (_Controller == Control.PLAYER) { _Stall += Time.deltaTime; if (_Stall > 0.04f) { _Stall = 0.0f; } else { return; } } // Check if current piece is empty if (_Piece._Type == Tetrominoes.NONE) { // Piece becomes a random new piece _Piece.BecomeNewPiece(); // Check if overlaps at start bool Failure = _Piece.CheckOverlapsSolid(); if (Failure) { EndGame(); return; } } // Overlap bool Overlap = false; // Do Move switch (_CurrentMove) { case Move.MOVE_LEFT: if (_Piece.MoveLeft()) { IncreaseFitness(ScoreSystemManager.GetCurrent().Move_Left); } break; case Move.MOVE_RIGHT: if (_Piece.MoveRight()) { IncreaseFitness(ScoreSystemManager.GetCurrent().Move_Right); } break; case Move.MOVE_DOWN: if (_Piece.MoveDown()) { IncreaseFitness(ScoreSystemManager.GetCurrent().Move_Down); } else { Overlap = true; } break; case Move.COLLAPSE: // Alternate Skip Mode if (GameplayManager.GetInstance().CollapseDoesNothing) { break; } float sc = _Piece.Collapse(); IncreaseFitness(ScoreSystemManager.GetCurrent().DropDown_Per_Tile *sc); break; case Move.ROTATE_CCW: if (_Piece.Rotate(false)) { IncreaseFitness(ScoreSystemManager.GetCurrent().Rotate); if (_Piece._Type == Tetrominoes.O) { IncreaseFitness(ScoreSystemManager.GetCurrent().RotatingCube); } } break; case Move.ROTATE_CW: if (_Piece.Rotate(true)) { IncreaseFitness(ScoreSystemManager.GetCurrent().Rotate); if (_Piece._Type == Tetrominoes.O) { IncreaseFitness(ScoreSystemManager.GetCurrent().RotatingCube); } } break; } // Update Move Text GameplayManager.GetInstance()._MoveText.text = GetMove().ToString(); // Reset Move _CurrentMove = Move.WAIT; // If 5th tick go down by one regardless if (_TickCounter % 5 == 0 && !Overlap) { if (!_Piece.MoveDown()) { Overlap = true; } } // Check if Piece is overlapping if (Overlap) { _Piece._y++; _Piece.UpdatePiece(); AddPieceToBoard(); } // TICK ++ UpdateTickCounter(); // Limited Pieces Game if ( GameplayManager.GetInstance().LimitPieces > 0 && _PiecesUsed > GameplayManager.GetInstance().LimitPieces - 1 ) { EndGame(); } }