public static void Draw(GameField field) { Console.SetCursorPosition(0, 0); for (int row = 0; row < field.Field.GetLength(0); row++) { for (int col = 0; col < field.Field.GetLength(1); col++) { if (field.Field[row, col] != 0) { int colorValue = field.Field[row, col]; ColorConsole.Write("█", GetColor(colorValue)); } else { ColorConsole.Write("*"); } } ColorConsole.Write("\n"); } }
public static void UpdatePosition(Figure figure, GameField field, ref bool runGame) { KeyboardControls keyboard = new KeyboardControls(); keyboard.OnLeftPressed += HandleOnLeftPressed; keyboard.OnRightPressed += HandleOnRightPressed; keyboard.OnRotatePressed += HandleOnRotatePressed; keyboard.OnEscapePressed += HandleOnEscapePressed; keyboard.ProcessInput(); switch (command) { case GameCommand.none: break; case GameCommand.left: if (figure.PositionY > 0) { figure.MoveLeft(); } break; case GameCommand.right: if (figure.PositionY + figure.Form.GetLength(1) < field.Field.GetLength(1)) { figure.MoveRight(); } break; case GameCommand.rotate: if ((figure.PositionX + figure.Form.GetLength(1) - 1 < field.Field.GetLength(0)) && (figure.PositionY + figure.Form.GetLength(0) - 1 < field.Field.GetLength(1))) { figure.RotateR(); } break; case GameCommand.escape: runGame = false; break; default: break; } command = GameCommand.none; }
public UIController(GameField gameField) { this.gameField = gameField; }