diff --git a/App.xaml b/App.xaml
index 5ac26ee..fd080c9 100644
--- a/App.xaml
+++ b/App.xaml
@@ -1,9 +1,8 @@
-
+
\ No newline at end of file
diff --git a/App.xaml.cs b/App.xaml.cs
index 3213dd3..e0d82d7 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -1,15 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.Data;
-using System.Linq;
-using System.Threading.Tasks;
-using System.Windows;
+using System.Windows;
-namespace Tetris {
- ///
- /// Interaction logic for App.xaml
- ///
- public partial class App : Application {
- }
-}
+namespace Tetris;
+
+///
+/// Interaction logic for App.xaml
+///
+public partial class App : Application
+{
+}
\ No newline at end of file
diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs
index b9d746b..4a05c7d 100644
--- a/AssemblyInfo.cs
+++ b/AssemblyInfo.cs
@@ -7,4 +7,4 @@ using System.Windows;
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
-)]
+)]
\ No newline at end of file
diff --git a/Models/Game.cs b/Models/Game.cs
index a72d73c..e236529 100644
--- a/Models/Game.cs
+++ b/Models/Game.cs
@@ -1,37 +1,43 @@
-using System;
-using System.ComponentModel;
+using System.ComponentModel;
namespace Tetris.Models;
-public class Party : INotifyPropertyChanged {
- public event PropertyChangedEventHandler PropertyChanged;
+public class Party : INotifyPropertyChanged
+{
+ private int _score;
- private String _userName;
+ private string _userName;
- public String UserName {
+ public Party(string userName)
+ {
+ _userName = userName;
+ }
+
+ public string UserName
+ {
get => _userName;
- set {
+ set
+ {
_userName = value;
OnPropertyChanged("UserName");
}
}
- private int _score = 0;
-
- public int Score {
+ public int Score
+ {
get => _score;
- set {
+ set
+ {
_score = value;
OnPropertyChanged("Score");
}
}
- public Party(String userName) {
- _userName = userName;
- }
+ public event PropertyChangedEventHandler PropertyChanged;
- protected virtual void OnPropertyChanged(string propertyName) {
+ protected virtual void OnPropertyChanged(string propertyName)
+ {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
-}
+}
\ No newline at end of file
diff --git a/Resources/icon.ico b/Resources/icon.ico
new file mode 100644
index 0000000..1aaab21
Binary files /dev/null and b/Resources/icon.ico differ
diff --git a/Resources/tetris.png b/Resources/tetris.png
new file mode 100644
index 0000000..3fb9254
Binary files /dev/null and b/Resources/tetris.png differ
diff --git a/Tetris.csproj b/Tetris.csproj
index d01518f..f60d261 100644
--- a/Tetris.csproj
+++ b/Tetris.csproj
@@ -5,10 +5,19 @@
enable
true
net6.0-windows
+ Resources\icon.ico
-
+
+
+ Always
+
+
+
+
+
+
diff --git a/Views/GameWindow.xaml b/Views/GameWindow.xaml
new file mode 100644
index 0000000..66e917f
--- /dev/null
+++ b/Views/GameWindow.xaml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/Views/GameWindow.xaml.cs b/Views/GameWindow.xaml.cs
new file mode 100644
index 0000000..2d3ddcf
--- /dev/null
+++ b/Views/GameWindow.xaml.cs
@@ -0,0 +1,18 @@
+using System.Runtime.InteropServices;
+using System.Windows;
+using Tetris.ViewsModels;
+
+namespace Tetris.Views;
+
+public partial class GameWindow : Window
+{
+ public GameWindow()
+ {
+ AttachConsole(-1);
+ InitializeComponent();
+ new GameModel((int)Width, (int)Height, ImageControl);
+ }
+
+ [DllImport("kernel32.dll")]
+ private static extern bool AttachConsole(int dwProcessId);
+}
\ No newline at end of file
diff --git a/Views/MainWindow.xaml b/Views/MainWindow.xaml
index 805184a..8993ed9 100644
--- a/Views/MainWindow.xaml
+++ b/Views/MainWindow.xaml
@@ -3,12 +3,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:Tetris"
xmlns:viewsModels="clr-namespace:Tetris.ViewsModels"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance viewsModels:ViewModel, IsDesignTimeCreatable=True}"
Title="MainWindow" Height="450" Width="800">
-
+
+
-
+
\ No newline at end of file
diff --git a/Views/MainWindow.xaml.cs b/Views/MainWindow.xaml.cs
index 6deee64..90e910c 100644
--- a/Views/MainWindow.xaml.cs
+++ b/Views/MainWindow.xaml.cs
@@ -1,27 +1,29 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Runtime.InteropServices;
using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
using Tetris.ViewsModels;
-namespace Tetris.Views {
- ///
- /// Interaction logic for MainWindow.xaml
- ///
- public partial class MainWindow : Window {
- public MainWindow() {
- DataContext = new ViewModel();
- InitializeComponent();
- }
+namespace Tetris.Views;
+
+///
+/// Interaction logic for MainWindow.xaml
+///
+public partial class MainWindow : Window
+{
+ public MainWindow()
+ {
+ AttachConsole(-1);
+ DataContext = new ViewModel();
+ InitializeComponent();
}
-}
+
+ [DllImport("kernel32.dll")]
+ private static extern bool AttachConsole(int dwProcessId);
+
+ private void StartButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ Console.WriteLine("Start game...");
+ new GameWindow().Show();
+ Close();
+ }
+}
\ No newline at end of file
diff --git a/ViewsModels/GameModel.cs b/ViewsModels/GameModel.cs
new file mode 100644
index 0000000..6e8771e
--- /dev/null
+++ b/ViewsModels/GameModel.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Threading;
+
+namespace Tetris.ViewsModels;
+
+public class GameModel
+{
+ private const int RendererHertz = 5;
+ private const int GameRendererHertz = (1 / RendererHertz) * 1000;
+ private readonly WriteableBitmap _writeableBitmap;
+
+ public GameModel(int width, int height, Image image)
+ {
+ _writeableBitmap = BitmapFactory.New(width, height);
+ image.Source = _writeableBitmap;
+
+ var dispatcherRenderTimer = new DispatcherTimer
+ {
+ Interval = new TimeSpan(0, 0, 0, 0, GameRendererHertz)
+ };
+
+ dispatcherRenderTimer.Tick += Render;
+ dispatcherRenderTimer.Start();
+
+ var dispatcherUpdateTimer = new DispatcherTimer
+ {
+ Interval = new TimeSpan(0, 0, 0, 0, 25)
+ };
+
+ dispatcherUpdateTimer.Tick += Update;
+ dispatcherUpdateTimer.Start();
+ }
+
+ private void Render(object? sender, EventArgs eventArgs)
+ {
+ _writeableBitmap.Lock();
+ _writeableBitmap.Clear(Colors.Black);
+
+ _writeableBitmap.Unlock();
+ }
+
+ private void Update(object? sender, EventArgs eventArgs)
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/ViewsModels/ViewModel.cs b/ViewsModels/ViewModel.cs
index 7d12ac7..e65e2bd 100644
--- a/ViewsModels/ViewModel.cs
+++ b/ViewsModels/ViewModel.cs
@@ -1,12 +1,14 @@
using System.ComponentModel;
-namespace Tetris.ViewsModels;
+namespace Tetris.ViewsModels;
-public class ViewModel : INotifyPropertyChanged {
+public class ViewModel : INotifyPropertyChanged
+{
public event PropertyChangedEventHandler PropertyChanged;
-
- protected virtual void OnPropertyChanged(string propertyName) {
+
+ protected virtual void OnPropertyChanged(string propertyName)
+ {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
-}
+}
\ No newline at end of file