diff --git a/Tetris/Views/GameWindow.xaml.cs b/Tetris/Views/GameWindow.xaml.cs index b6bb3c2..15494fb 100644 --- a/Tetris/Views/GameWindow.xaml.cs +++ b/Tetris/Views/GameWindow.xaml.cs @@ -1,12 +1,10 @@ -using System; -using System.Runtime.InteropServices; -using System.Windows; +using System.Runtime.InteropServices; using System.Windows.Input; using Tetris.ViewsModels; namespace Tetris.Views; -public partial class GameWindow : Window +public partial class GameWindow { private static readonly GameViewModel GameViewModel = new(); @@ -22,28 +20,24 @@ public partial class GameWindow : Window private void UIElement_OnKeyDown(object sender, KeyEventArgs e) { - // If key is space - if (e.Key == Key.Space) + switch (e.Key) { - GameViewModel.Game.CurrentTetrominoe?.RotateRight(); - } - - // If key is down - else if (e.Key == Key.Down) - { - GameViewModel.Game.CurrentTetrominoe?.GoDown(); - } - - // If key is left - else if (e.Key == Key.Left) - { - GameViewModel.Game.CurrentTetrominoe?.GoLeft(); - } - - // If key is right - else if (e.Key == Key.Right) - { - GameViewModel.Game.CurrentTetrominoe?.GoRight(); + // If key is space + case Key.Space: + GameViewModel.Game.CurrentTetrominoe?.RotateRight(); + break; + // If key is down + case Key.Down: + GameViewModel.Game.CurrentTetrominoe?.GoDown(); + break; + // If key is left + case Key.Left: + GameViewModel.Game.CurrentTetrominoe?.GoLeft(); + break; + // If key is right + case Key.Right: + GameViewModel.Game.CurrentTetrominoe?.GoRight(); + break; } } } \ No newline at end of file diff --git a/Tetris/Views/MainWindow.xaml.cs b/Tetris/Views/MainWindow.xaml.cs index 90e910c..ea38c31 100644 --- a/Tetris/Views/MainWindow.xaml.cs +++ b/Tetris/Views/MainWindow.xaml.cs @@ -8,7 +8,7 @@ namespace Tetris.Views; /// /// Interaction logic for MainWindow.xaml /// -public partial class MainWindow : Window +public partial class MainWindow { public MainWindow() { diff --git a/Tetris/ViewsModels/GameViewModel.cs b/Tetris/ViewsModels/GameViewModel.cs index 4d5aac4..215374d 100644 --- a/Tetris/ViewsModels/GameViewModel.cs +++ b/Tetris/ViewsModels/GameViewModel.cs @@ -45,6 +45,7 @@ public class GameViewModel : INotifyPropertyChanged } public ImageSource Source => _writeableBitmap; + public ImageSource RightSource => _writeableBitmap; private void Render(object? sender, EventArgs eventArgs) { @@ -92,5 +93,11 @@ public class GameViewModel : INotifyPropertyChanged { Game.PrintTetrominoe(); } + + if (Game.LineFull()) + { + Game.ClearLine(); + // TODO: Add score + } } } \ No newline at end of file diff --git a/Tetris/ViewsModels/ViewModel.cs b/Tetris/ViewsModels/ViewModel.cs index e65e2bd..3fe7583 100644 --- a/Tetris/ViewsModels/ViewModel.cs +++ b/Tetris/ViewsModels/ViewModel.cs @@ -4,11 +4,10 @@ namespace Tetris.ViewsModels; public class ViewModel : INotifyPropertyChanged { - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { - if (PropertyChanged != null) - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } \ No newline at end of file