/// <summary> /// Draws the TOPOUTCHAR over the board one line at a time, starting at the top /// </summary> public void TopOutAnimation() { for (int i = 0; i < TetfuzaBoard.BOARD_HEIGHT; i++) { StableFrames.Stabilize(MS_PER_FRAME * 4, _timer); _board.ReplaceLine(i, _board.BoardLine(BlockColor.Topout)); _screen.DrawGameplayScreen(this); } _screen.DrawGameplayScreen(this); }
public static void Start() { Console.WriteLine("Hello World!"); Console.Write("Enter number of frames: "); int numFrames = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter milliseconds per frame: "); int ms = Convert.ToInt32(Console.ReadLine()); Stopwatch timer = new Stopwatch(); timer.Start(); for (int i = 0; i < numFrames; i++) { Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); StableFrames.Stabilize(ms, timer); Console.WriteLine(timer.ElapsedMilliseconds + " milliseconds elapsed for " + (i + 1) + " frames."); } timer.Stop(); Console.ReadKey(); }
/// <summary> /// Main Loop /// </summary> /// <returns>Final Score</returns> public long Run() { _screen.ClearScreen(); bool gameOver = false; _timer.Start(); int pieceNum = _rand.Next(0, 7); NextPiece = new FuzaPiece((FuzaPieceType)pieceNum); while (!gameOver) { // Spawn a new piece and reset center CurrentPiece = NextPiece; _pieceCenter = new Coordinate(5, 2); // Determine next piece pieceNum = _rand.Next(0, 7); NextPiece = new FuzaPiece((FuzaPieceType)pieceNum); // Draw Board _screen.DrawGameplayScreen(this); bool isLockDown = false; while (!isLockDown) { // Get user key press int xDirection = 0; int yDirection = 0; int rotation = 0; if (true == _keyboard.InputAvailable) { _keyboard.GetInput(ref xDirection, ref yDirection, ref rotation); // Move and/or Rotate piece as appropriate MovePieceLeftRight(xDirection); RotatePiece(rotation); } // Move piece down at constant rate, or instant if user inputs down bool autoDown = (_frameCount % DropSpeed) == 0; if (yDirection == -1) { autoDown = true; Score += 1; } if (autoDown) { isLockDown = !DropPiece(); } _board.DrawPiece(CurrentPiece, _pieceCenter); // Draw Screen _screen.DrawGameplayScreen(this); StableFrames.Stabilize(MS_PER_FRAME, _timer); _frameCount++; } // Lock Piece and redraw it CurrentPiece.LockPiece(); _board.DrawPiece(CurrentPiece, _pieceCenter); // Check if lines were cleared and update score int linesCleared = _board.ClearLines(); if (linesCleared > 0) { AddClearedLinesToScore(linesCleared); } // Check if player has topped out (game over) gameOver = _board.CheckTopOut(); } // Plays the game over animation TopOutAnimation(); return(Score); }