51 lines
No EOL
1.4 KiB
C#
51 lines
No EOL
1.4 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)
|
|
{
|
|
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)
|
|
{
|
|
|
|
}
|
|
} |