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/ViewsModels/GameModel.cs
2022-04-07 14:20:56 +02:00

49 lines
No EOL
1.3 KiB
C#

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)
{
}
}