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

49 lines
1.2 KiB
C#
Raw Normal View History

2022-05-04 10:40:15 +02:00
using System;
using System.Runtime.InteropServices;
2022-04-06 11:15:55 +02:00
using System.Windows;
2022-05-04 10:40:15 +02:00
using System.Windows.Input;
2022-04-06 11:30:44 +02:00
using Tetris.ViewsModels;
2022-04-06 11:15:55 +02:00
namespace Tetris.Views;
public partial class GameWindow : Window
{
2022-05-04 10:40:15 +02:00
private static readonly GameViewModel GameViewModel = new GameViewModel();
2022-04-06 11:15:55 +02:00
public GameWindow()
{
AttachConsole(-1);
InitializeComponent();
2022-05-04 10:40:15 +02:00
DataContext = GameViewModel;
2022-04-06 11:15:55 +02:00
}
[DllImport("kernel32.dll")]
private static extern bool AttachConsole(int dwProcessId);
2022-05-04 10:40:15 +02:00
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();
}
}
2022-04-06 11:15:55 +02:00
}