public FrmTetris() { // Create instance of TetrisBoard tb = new TetrisBoard(192, 50, 10, 20, 200, 400); tb.GenerateUpcoming(); tb.GeneratePiece(); InitializeComponent(); }
private void InitNewGame(object sender, EventArgs e) { board = new TetrisBoard(g, gNext); board.ScoreChanged += (object obj, EventArgs args) => scoreLabel.Text = "Score: " + board.Score; board.LevelChanged += (object obj, EventArgs args) => levelLabel.Text = "Level: " + ((board.Level < TetrisBoard.LevelMax) ? board.Level.ToString() : "Max"); board.Score = 0; board.Level = 1; fallingTimer.Enabled = true; }
public string[] PrintGame(TetrisBoard tetrisBoard, TetrisBoard nextTetrimino, GameStats gameStats) { string[] boardRows = PrintBoard(tetrisBoard); string[] nextTetriminoRows = PrintBoard(nextTetrimino); int totalWidth = 14 + 3; int innerWidth = 12 + 3; string scoreTitle = PadOutString(" SCORE", innerWidth); string scoreAmount = PadOutString($" {gameStats.Score}", innerWidth); string lines = PadOutString($" Lines: {gameStats.Lines}", innerWidth); string blocks = PadOutString($" Blocks: {gameStats.Shapes}", innerWidth); string level = PadOutString($" Level: {gameStats.Level}", innerWidth); string blankLine14 = PadOutString(totalWidth); string[] gameFieldPrint = { $"┌{PrintLine(innerWidth)}┐ " + $" ┌{PrintLine(30)}┐", $"│{nextTetriminoRows[0]}│ " + $" │{boardRows[0]}│", $"│{nextTetriminoRows[1]}│ " + $" │{boardRows[1]}│", $"│{nextTetriminoRows[2]}│ " + $" │{boardRows[2]}│", $"│{nextTetriminoRows[3]}│ " + $" │{boardRows[3]}│", $"└{PrintLine(innerWidth)}┘ " + $" │{boardRows[4]}│", $"{blankLine14} " + $" │{boardRows[5]}│", $"┌{PrintLine(innerWidth)}┐ " + $" │{boardRows[6]}│", $"│{scoreTitle}│ " + $" │{boardRows[7]}│", $"│{scoreAmount}│ " + $" │{boardRows[8]}│", $"└{PrintLine(innerWidth)}┘ " + $" │{boardRows[9]}│", $"{blankLine14} " + $" │{boardRows[10]}│", $"┌{PrintLine(innerWidth)}┐ " + $" │{boardRows[11]}│", $"│{lines}│ " + $" │{boardRows[12]}│", $"│{blocks}│ " + $" │{boardRows[13]}│", $"│{level}│ " + $" │{boardRows[14]}│", $"└{PrintLine(innerWidth)}┘ " + $" │{boardRows[15]}│", $"{blankLine14} " + $" │{boardRows[16]}│", $"{blankLine14} " + $" │{boardRows[17]}│", $"{blankLine14} " + $" │{boardRows[18]}│", $"{blankLine14} " + $" │{boardRows[19]}│", $"{blankLine14} " + $" └{PrintLine(30)}┘" }; return(gameFieldPrint); }
public void MergeInPlace(TetrisBoard otherBoard) { // Map based on lower edge of blocks in otherBoard (active piece) int thisRowStart = (otherBoard.yOffset - yOffset + blockHeight) / blockHeight; int thisColStart = (otherBoard.xOffset - xOffset) / blockWidth; for (int curRow = 0; curRow < otherBoard.numRows; curRow++) { for (int curCol = 0; curCol < otherBoard.numCols; curCol++) { if (otherBoard.myBlocks[curRow][curCol] != null) { //otherBoard has a block at this index myBlocks[thisRowStart + curRow][thisColStart + curCol] = otherBoard.myBlocks[curRow][curCol]; } } } // Check if lines need to be cleared and clear them ClearLine(); }
public GameScreen(ScreenFactory screenFactory, KeyMapping keyMapping, TetrisBoardOperator tetrisBoardOperator, Tetriminos.Factory tetriminoFactory) { _screenFactory = screenFactory; _tetriminoFactory = tetriminoFactory; SetKeyMapping(keyMapping); int spawnX = tetrisBoardOperator.TetrisBoard.Width / 2; int spawnY = 1; _centerPoint = new Point(spawnX, spawnY); _tetrisBoardOperator = tetrisBoardOperator; _tetrisBoard = _tetrisBoardOperator.TetrisBoard; _tetrisBoardOperator.NewCurrentTetrimino(CreateTetrimino(), _centerPoint); _tetrisBoardOperator.NewNextTetrimino(CreateTetrimino(), _centerPoint); UpdateNextTetrimino(); }
public static void Main2(string[] args) { Console.SetWindowSize(12,22); TetrisBoard board = new TetrisBoard(10,20); board.SetBlock(0,0,new int[,]{ {1,1,1,1}, {0,0,0,1}, }); do { for (int x = 0; x < board.Width; x++) { for (int y = 0; y < board.Height; y++) { if (board.HasTileAt(x, y)) { Console.SetCursorPosition(y, x); Console.Write('#'); } } } //ConsoleKeyInfo key = Console.ReadKey(true); } while(true); }
// Check for collision with edge of tetris board or other blocks public bool CheckCollision(TetrisBoard otherBoard) { // Map based on lower edge of blocks in otherBoard int thisRowStart = (otherBoard.yOffset - yOffset + blockHeight) / blockHeight; int thisColStart = (otherBoard.xOffset - xOffset) / blockWidth; int thisRowEnd = thisRowStart + 4; int thisColEnd = thisColStart + 4; for (int curRow = 0; curRow < otherBoard.numRows; curRow++) { for (int curCol = 0; curCol < otherBoard.numCols; curCol++) { if (otherBoard.myBlocks[curRow][curCol] != null) { // otherBoard (active piece) has a block at this index // Does not allow block to pass left edge of grid if (thisColStart + curCol < 0 || thisColEnd + curCol > 13) { return(true); } // Stops block at the bottom of grid if (thisRowStart + curRow >= myBlocks.Length) { return(true); } // otherBoard has a block at this index if (myBlocks[thisRowStart + curRow][thisColStart + curCol] != null) { return(true); } } } } return(false); }
public void SetUp() { board = new TetrisBoard(10, 20); }
public void TestSimpleGame() { TetrisBoard board = new TetrisBoard(10, 5); bool success = board.SetBlock(0, 0, new int[,]{ {1,1,1}, {1,1,1} }); Assert.IsTrue(success); while (board.MoveDown()); board.MergeBlock(); success = board.SetBlock(0, 0, new int[,]{ {1,1}, {1,1}, }); Assert.IsTrue(success); while(board.MoveRight()); while(board.MoveDown()); Assert.True(board.HasTileAt(9,0)); board.MergeBlock(); int lines = board.RemoveLines(); Assert.AreEqual(2, lines); Assert.False(board.HasTileAt(9,0)); }
public StatefulBackedCommand(TetrisBoard board) : base(board) { }
public SimpleCommand(TetrisBoard board, ActionDelegate action) : base(board) { this.action = action; }
public Command(TetrisBoard board) { this.board = board; }
public TetrisBoardTests() { _tetrisBoard = new TetrisBoard(5, 5); }