using System; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Input; using Tetris.ViewsModels; namespace Tetris.Views; public partial class GameWindow : Window { private static readonly GameViewModel GameViewModel = new GameViewModel(); public GameWindow() { AttachConsole(-1); InitializeComponent(); DataContext = GameViewModel; } [DllImport("kernel32.dll")] private static extern bool AttachConsole(int dwProcessId); private void UIElement_OnKeyDown(object sender, KeyEventArgs e) { // If key is space if (e.Key == Key.Space) { GameViewModel.CurrentTetrominoe.RotateRight(); } // If key is down else if (e.Key == Key.Down) { GameViewModel.CurrentTetrominoe.GoDown(); } // If key is left else if (e.Key == Key.Left) { GameViewModel.CurrentTetrominoe.GoLeft(); } // If key is right else if (e.Key == Key.Right) { GameViewModel.CurrentTetrominoe.GoRight(); } } }