diff --git a/Tetris.csproj b/Tetris.csproj index c70bc94..6fb7e41 100644 --- a/Tetris.csproj +++ b/Tetris.csproj @@ -9,10 +9,14 @@ - + Always + + + + diff --git a/Views/GameWindow.xaml.cs b/Views/GameWindow.xaml.cs index 236afea..2d3ddcf 100644 --- a/Views/GameWindow.xaml.cs +++ b/Views/GameWindow.xaml.cs @@ -1,5 +1,6 @@ using System.Runtime.InteropServices; using System.Windows; +using Tetris.ViewsModels; namespace Tetris.Views; @@ -9,7 +10,7 @@ public partial class GameWindow : Window { AttachConsole(-1); InitializeComponent(); - // new GameManager((int)Width, (int)Height, ImageControl); + new GameModel((int)Width, (int)Height, ImageControl); } [DllImport("kernel32.dll")] diff --git a/ViewsModels/GameModel.cs b/ViewsModels/GameModel.cs new file mode 100644 index 0000000..774d018 --- /dev/null +++ b/ViewsModels/GameModel.cs @@ -0,0 +1,51 @@ +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) + { + var random = new Random(); + + _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