public void IEraseTest() { TetrisPiece piece = new TetrisPiece(PieceType.I); piece.EraseRow(4); List <Square> 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 == 5)); Assert.IsTrue(squares.Any(s => s.Y == 3 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 4 && s.X == 5)); piece.EraseRow(4); squares = piece.OccupiedSquares; Assert.AreEqual(3, squares.Count); Assert.IsTrue(squares.Any(s => s.Y == 2 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 3 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 4 && s.X == 5)); piece.EraseRow(4); squares = piece.OccupiedSquares; Assert.AreEqual(2, squares.Count); Assert.IsTrue(squares.Any(s => s.Y == 3 && s.X == 5)); Assert.IsTrue(squares.Any(s => s.Y == 4 && s.X == 5)); piece.EraseRow(4); squares = piece.OccupiedSquares; Assert.AreEqual(1, squares.Count); Assert.IsTrue(squares.Any(s => s.Y == 4 && s.X == 5)); piece.EraseRow(4); squares = piece.OccupiedSquares; Assert.AreEqual(0, squares.Count); }
public bool IsObstructed(TetrisPiece piece, ObstructionDirection direction) { bool isObstructed = false; int yCheck = 0; int xCheck = 0; switch (direction) { case ObstructionDirection.DOWN: { yCheck = 1; xCheck = 0; } break; case ObstructionDirection.LEFT: { yCheck = 0; xCheck = -1; } break; case ObstructionDirection.RIGHT: { yCheck = 0; xCheck = 1; } break; } for (int itRow = piece.size.row - 1; itRow >= 0; itRow--) { for (int itCol = 0; itCol < piece.size.col; itCol++) { // check block is filled if (piece.Get(itRow, itCol) == 1) { int rowPos = (piece.position.row + itRow) + yCheck; int colPos = (piece.position.col + itCol) + xCheck; if (rowPos >= 0 && rowPos < this.row && colPos >= 0 && colPos < this.col) { if (boardData[rowPos, colPos] == 1) { return(true); } } else { // hit bottom return(true); } } } } return(isObstructed); }
public async Task LoadAsync(string savedFileContents) { loader = savedFileContents.Split('\n'); // reading table size string SizeData = loader[0]; Size = Int32.Parse(SizeData); // reading current piece string[] currentPieceData = loader[1].Split(' '); CurrentPiece = new TetrisPiece(); CurrentPiece.Type = (PieceType)(Int32.Parse(currentPieceData[0])); CurrentPiece.Direction = (PieceDirection)Int32.Parse(currentPieceData[1]); CurrentPiece.Coordinates.Clear(); for (int coordinate = 0; coordinate < 4; ++coordinate) { CurrentPiece.Coordinates.Add((Int32.Parse(currentPieceData[2 * (coordinate + 1)]), Int32.Parse(currentPieceData[2 * (coordinate + 1) + 1]))); } // reading table lines Table = new int[16, Size]; for (int line = 0; line < 16; ++line) { string[] TableLineData = loader[line + 2].Split(' '); for (int row = 0; row < Size; ++row) { Table[line, row] = Int32.Parse(TableLineData[row]); } } }
public bool IsSelectionCorrect(TetrisPiece selection) { switch (currentComparison) { case "area": if (selection == largerArea) { Debug.Log("correct!"); return(true); } Debug.Log("incorrect!"); return(false); case "perimeter": if (selection == largerPerimeter) { Debug.Log("correct!"); return(true); } Debug.Log("incorrect!"); return(false); } Debug.Log("warning : No matching case"); return(false); }
public override bool Equals(System.Object other) { if (other == null) { return(false); } TetrisPiece p = other as TetrisPiece; if ((System.Object)p == null) { return(false); } if (type != p.type) { return(false); } for (int i = 0; i < boxes.Count; i++) { if (boxes[i].value != p.boxes[i].value) { return(false); } } return(true); }
public void UpdateGrid(TetrisPiece tetrisPiece) { for (int y = 0; y < gridHeight; ++y) { for (int x = 0; x < gridWidth; ++x) { if (grid[x, y] != null) { if (grid[x, y].parent == tetrisPiece.transform) { grid[x, y] = null; } } } } foreach (Transform piece in tetrisPiece.transform) { Vector2 pos = Round(piece.position); if (pos.y < gridHeight) { grid[(int)pos.x, (int)pos.y] = piece; } } }
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)); }
void GetNextPiece() { if (game.splicer.pieces.Count > 0) { PieceIdx = Random.Range(0, game.splicer.pieces.Count); Piece = game.splicer.pieces[PieceIdx]; } }
/// <summary> /// Constructeur /// </summary> /// <param name="tetrisPiece"></param> /// <param name="x"></param> public TetrisPiece(TetrisPiece tetrisPiece, int x) { PieceID = tetrisPiece.PieceID; Rotation = tetrisPiece.Rotation; X = tetrisPiece.X + x; Y = tetrisPiece.Y; Couleur = tetrisPiece.Couleur; }
public void AttachPiece(TetrisPiece piece, int row, int col) { piece.SetPos(row, col); piece.ApplyChange(); piece.RefreshView(); tetrisBoard.AttachPiece(piece); tetrisBoard.CheckRowClear(); }
/// <summary> /// Constructeur /// </summary> /// <param name="tetrisPiece"></param> public TetrisPiece(TetrisPiece tetrisPiece) { PieceID = tetrisPiece.PieceID; Rotation = tetrisPiece.Rotation; X = tetrisPiece.X; Y = tetrisPiece.Y; Couleur = tetrisPiece.Couleur; TmpCouleur = tetrisPiece.Couleur; }
void OnMouseDown() { //get parent script Tetris Piece Transform parent = gameObject.transform.parent; TetrisPiece pieceScript = (TetrisPiece)parent.GetComponent(typeof(TetrisPiece)); pieceScript.Selected(); }
private void RotatePieceRandomly(TetrisPiece piece) { int rotationCount = _random.Next(4); for (int i = 0; i <= rotationCount; i++) { piece.Rotate90DegreesClockwise(); } }
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); }
/// <summary> /// Constructeur /// </summary> /// <param name="tetrisPiece"></param> /// <param name="y"></param> /// <param name="testScore"></param> public TetrisPiece(TetrisPiece tetrisPiece, int y, bool testScore) { PieceID = tetrisPiece.PieceID; Rotation = tetrisPiece.Rotation; X = tetrisPiece.X; Y = tetrisPiece.Y + y; Couleur = tetrisPiece.Couleur; TmpCouleur = tetrisPiece.Couleur; TestScore = testScore; }
public void StartTetrisMode(GameObject piece) { isRunning = true; tetrisBlock = SpawnBlock(piece.transform); position2D = ConvertV3toV2Int(spawn.localPosition); tetrisPiece = tetrisBlock.GetComponent <TetrisPiece>(); GameInputManager.Instance.SetPlayerInputMode(playerId, 1); //Set the local position to be 0, but be sure to set the pivot correctly in the 2D Object tetrisBlock.transform.localPosition = new Vector3(0, 0, 0); }
public void NewGame(int size) { Size = size; Table = new int[16, Size]; GameActive = true; CurrentPiece = new TetrisPiece(); Table[CurrentPiece.Coordinates[0].Item1, CurrentPiece.Coordinates[0].Item2] = (int)CurrentPiece.Type + 1; Table[CurrentPiece.Coordinates[1].Item1, CurrentPiece.Coordinates[1].Item2] = (int)CurrentPiece.Type + 1; Table[CurrentPiece.Coordinates[2].Item1, CurrentPiece.Coordinates[2].Item2] = (int)CurrentPiece.Type + 1; Table[CurrentPiece.Coordinates[3].Item1, CurrentPiece.Coordinates[3].Item2] = (int)CurrentPiece.Type + 1; }
private TetrisPiece MakeRandomPiece() { int pieceIndex = _random.Next(_prototypePieces.Length); TetrisPiece prototypePiece = _prototypePieces[pieceIndex]; TetrisPiece piece = (TetrisPiece)prototypePiece.Clone(); piece.Color = _colorFactory.MakeRandomColor(); RotatePieceRandomly(piece); return(piece); }
public int anchorPiece(Point pos, List <TetrisPiece> pieces) { for (int i = 0; i < pieces.Count; i++) { TetrisPiece other = pieces[i]; if (other.Fits(pos) && this == other) { return(i); } } return(-1); }
public TetrisCore(TemplatePiece[] pTemplatePieces, int tw = 10, int th = 20) { TetrisWidth = tw; TetrisHeight = th; TetrisBoard = new bool [TetrisWidth, TetrisHeight]; ColourBoard = new Color[TetrisWidth, TetrisHeight]; templatePieces = pTemplatePieces; CurrPiece = new TetrisPiece(); NextPiece = new TetrisPiece(); ClearBoard(); EventSystem <TetrisControlEvent> .Subscribe(TetrisControlEvent.Restart, ClearBoard); }
private void MoveNextPieceToTop() { _currentPiece = _nextPiece; _currentPiece.transform.position = new Vector3(BOARD_WIDTH / 2 * PIECE_SIZE - PIECE_SIZE, BOARD_HEIGHT * PIECE_SIZE - (3 * PIECE_SIZE)); _currentPiece.name = "Current Piece"; _controller.CurrentPiece = _currentPiece; var descendingPiece = _currentPiece.gameObject.AddComponent <DescendingPiece>(); descendingPiece.SecondsBetweenDrops = _secondsBetweenVerticalDrops; SpawnNextUpPiece(); }
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 bool CheckIsAboveGrid(TetrisPiece piece) { for (int x = 0; x < gridWidth; ++x) { foreach (Transform mino in piece.transform) { Vector2 pos = Round(mino.position); if (pos.y > gridHeight - 1) { return(true); } } } return(false); }
private void DisplayInPlaceOfPiece(TetrisPiece piece, Coordinates coord, string displayChar, string blankChar) { System.Console.ForegroundColor = (piece.Color as ConsoleColor2).Value; for (int pieceRow = 0; pieceRow < piece.MaxSize; pieceRow++) { for (int pieceColumn = 0; pieceColumn < piece.MaxSize; pieceColumn++) { int windowRow = coord.Row + pieceRow; int windowColumn = coord.Column + pieceColumn; bool isBrick = piece[pieceRow, pieceColumn] != null; System.Console.SetCursorPosition(windowColumn, windowRow); System.Console.Write(isBrick ? displayChar.ToString() : blankChar); } } }
public void AttachPiece(TetrisPiece piece) { if (IsInside(piece)) { for (int itRow = 0; itRow < piece.size.row; itRow++) { for (int itCol = 0; itCol < piece.size.col; itCol++) { if (piece.Get(itRow, itCol) == 1) { boardData[piece.position.row + itRow, piece.position.col + itCol] = piece.Get(itRow, itCol); tetrisCells[piece.position.row + itRow, piece.position.col + itCol] = piece.GetCell(itRow, itCol); } } } } }
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 AddPiece(TetrisPieceWithPosition pieceWithPos) { TetrisPiece piece = pieceWithPos.Piece; for (int row = 0; row < piece.MaxSize; row++) { for (int column = 0; column < piece.MaxSize; column++) { TetrisBrick brick = piece[row, column]; if (brick != null) { int rowRelativeToBoard = row + pieceWithPos.Position.Row; int columnRelativeToBoard = column + pieceWithPos.Position.Column; Bricks[rowRelativeToBoard][columnRelativeToBoard] = (TetrisBrick)brick.Clone(); } } } }
public void UpdateFallingPiece() { if (currentFallingPiece != null) { if (!currentFallingPiece.IsObstructed(TetrisBoard.ObstructionDirection.DOWN)) { // move object currentFallingPiece.Move(1, 0); currentFallingPiece.RefreshView(); } else if (currentFallingPiece.IsObstructed(TetrisBoard.ObstructionDirection.DOWN)) { tetrisBoard.AttachPiece(currentFallingPiece); tetrisBoard.CheckRowClear(); currentFallingPiece = null; } } }
private TetrisPieceWithPosition MakePieceWithPosition() { TetrisPieceWithPosition result = new TetrisPieceWithPosition(); if (NextPiece != null) { result.Piece = NextPiece; } else { result.Piece = PieceFactory.MakePiece(); } NextPiece = PieceFactory.MakePiece(); result.NextPiece = NextPiece; result.Position = new Coordinates(0, Columns / 2); return(result); }
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); }
public static List<IntVector3> NewPiece(TetrisPiece type) { switch (type) { case TetrisPiece.I: return I; case TetrisPiece.J: return J; case TetrisPiece.L: return L; case TetrisPiece.O: return O; case TetrisPiece.S: return S; case TetrisPiece.T: return T; case TetrisPiece.Z: return Z; default: throw new ArgumentException("Unknown piece type"); } }
private void MoveNextPieceToTop() { _currentPiece = _nextPiece; _currentPiece.transform.position = new Vector3(BOARD_WIDTH/2 * PIECE_SIZE - PIECE_SIZE, BOARD_HEIGHT * PIECE_SIZE - (3 * PIECE_SIZE)); _currentPiece.name = "Current Piece"; _controller.CurrentPiece = _currentPiece; var descendingPiece = _currentPiece.gameObject.AddComponent<DescendingPiece>(); descendingPiece.SecondsBetweenDrops = _secondsBetweenVerticalDrops; SpawnNextUpPiece(); }