Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
Tetris/Views/GameWindow.xaml.cs
2022-05-04 10:40:15 +02:00

49 lines
No EOL
1.2 KiB
C#

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