public BoardWindow() { InitializeMaps(); WindowWidth = Console.WindowWidth; WindowHeight = Console.WindowHeight; Board = new TetrisBoard(WindowHeight, WindowWidth); RenderedBoard = new SquareType[WindowWidth, WindowHeight]; }
static void Draw() { if (!terminate) { Console.Clear(); Console.WriteLine(firstLine); Console.WriteLine(secondLine); Console.WriteLine("Score: " + score); Console.WriteLine(debugLine + "\n"); Console.WriteLine("Now:\n" + currentTetrimino.Draw() + "\nNext:\n" + nextTetrimino.Draw()); Console.WriteLine(TetrisBoard.Draw()); } }
public static void CheckForKey() { ConsoleKeyInfo info; while (!Program.terminate) { if (!Program.haveARest) { if (Console.KeyAvailable) { info = Console.ReadKey(true); if (info.Key == ConsoleKey.W || info.Key == ConsoleKey.UpArrow) { TetrisBoard.activeTermino.Rotate(); TetrisBoard.UpdateActiveCoords(); } else if (info.Key == ConsoleKey.D || info.Key == ConsoleKey.RightArrow) { if (TetrisBoard.activeTermino.GetWidth() + TetrisBoard.topLeft.x < Program.BOARD_WIDTH) { TetrisBoard.topLeft.x++; TetrisBoard.UpdateActiveCoords(); } } else if (info.Key == ConsoleKey.A || info.Key == ConsoleKey.LeftArrow) { if (TetrisBoard.topLeft.x >= 1) { TetrisBoard.topLeft.x--; TetrisBoard.UpdateActiveCoords(); } } else if (info.Key == ConsoleKey.S || info.Key == ConsoleKey.DownArrow) { if (!TetrisBoard.CheckIfHit()) { TetrisBoard.topLeft.y++; } else { } } else if (info.Key == ConsoleKey.Escape) { //Program.Game_Over(); } } //endif } //endif } //endwhile } //endmethod
static void Pre_Update() { currentFrame = DateTime.Now; TimeSpan delta = currentFrame.Subtract(lastFrame); lastFrame = currentFrame; TimeSpan duration = currentFrame.Subtract(start); currentTurn = DateTime.Now; deltaTurn = currentTurn.Subtract(lastTurn); if (deltaTurn.TotalMilliseconds >= TimePerTurn) { lastTurn = currentTurn; TetrisBoard.DoTurn(); } while (delta.TotalMilliseconds < (1 / FPS_CAP) * SECOND) { currentFrame = DateTime.Now; delta = currentFrame.Subtract(lastFrame); } firstLine = duration.Hours + ":" + duration.Minutes + ":" + duration.Seconds; secondLine = (1 / delta.TotalSeconds) + " FPS\t" + delta.TotalMilliseconds + " ms"; haveARest = true; }