Archived
1
0
Fork 0

Optimize and add detection for full line

This commit is contained in:
Ziedelth 2022-06-06 11:39:10 +02:00
parent 2e901dc995
commit e441c451db
4 changed files with 29 additions and 29 deletions

View file

@ -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();
@ -21,29 +19,25 @@ public partial class GameWindow : Window
private static extern bool AttachConsole(int dwProcessId);
private void UIElement_OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
// If key is space
if (e.Key == Key.Space)
{
case Key.Space:
GameViewModel.Game.CurrentTetrominoe?.RotateRight();
}
break;
// If key is down
else if (e.Key == Key.Down)
{
case Key.Down:
GameViewModel.Game.CurrentTetrominoe?.GoDown();
}
break;
// If key is left
else if (e.Key == Key.Left)
{
case Key.Left:
GameViewModel.Game.CurrentTetrominoe?.GoLeft();
}
break;
// If key is right
else if (e.Key == Key.Right)
{
case Key.Right:
GameViewModel.Game.CurrentTetrominoe?.GoRight();
break;
}
}
}

View file

@ -8,7 +8,7 @@ namespace Tetris.Views;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public partial class MainWindow
{
public MainWindow()
{

View file

@ -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
}
}
}

View file

@ -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));
}
}