Files
2026-08-27 11:23:13 -06:00

1127 lines
40 KiB
C#

// Decompiled with JetBrains decompiler
// Type: Raton.Windows.Games
// Assembly: Raton, Version=0.4.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 36C4E416-7F8D-4D23-930F-B5CCB0D810E7
// Assembly location: C:\Users\user\Desktop\v3.8.0 Deluxe Plugins (v4.0.0) cracked\Raton.exe
using Microsoft.Win32;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Shapes;
using System.Windows.Threading;
#nullable disable
namespace Raton.Windows;
public partial class Games : Window
{
private readonly Random _rng = new Random();
private Games.GamePanel _activePanel;
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
private DispatcherTimer _snakeTimer;
private List<Point> _snakeBody;
private Point _snakeDir;
private Point _snakeNextDir;
private Point _snakeFood;
private int _snakeScore;
private bool _snakeRunning;
private bool _snakeAlive;
private const int S_COLS = 35;
private const int S_ROWS = 22;
private static readonly System.Windows.Media.Color S_HEAD_COLOR = System.Windows.Media.Color.FromRgb((byte) 155, (byte) 124, (byte) 224 /*0xE0*/);
private static readonly System.Windows.Media.Color S_BODY_COLOR = System.Windows.Media.Color.FromRgb((byte) 107, (byte) 79, (byte) 168);
private static readonly System.Windows.Media.Color S_FOOD_COLOR = System.Windows.Media.Color.FromRgb((byte) 217, (byte) 85, (byte) 85);
private static readonly System.Windows.Media.Color S_GRID_COLOR = System.Windows.Media.Color.FromArgb((byte) 25, (byte) 120, (byte) 100, (byte) 200);
private bool _isPainting;
private Point _lastPaintPt;
private System.Windows.Media.Color _paintColor = Colors.Black;
private double _brushSize = 12.0;
private bool _isEraser;
private const int M_ROWS = 9;
private const int M_COLS = 9;
private const int M_MINES = 10;
private DispatcherTimer _mineTimer;
private int[,] _mineGrid;
private bool[,] _mineRevealed;
private bool[,] _mineFlagged;
private bool _mineGameOver;
private bool _mineFirstClick;
private int _mineFlags;
private int _mineSeconds;
private static readonly System.Windows.Media.Color[] NumColors = new System.Windows.Media.Color[9]
{
Colors.Transparent,
System.Windows.Media.Color.FromRgb((byte) 91, (byte) 163, (byte) 245),
System.Windows.Media.Color.FromRgb((byte) 77, (byte) 184, (byte) 122),
System.Windows.Media.Color.FromRgb((byte) 217, (byte) 85, (byte) 85),
System.Windows.Media.Color.FromRgb((byte) 192 /*0xC0*/, (byte) 96 /*0x60*/, (byte) 240 /*0xF0*/),
System.Windows.Media.Color.FromRgb((byte) 245, (byte) 112 /*0x70*/, (byte) 48 /*0x30*/),
System.Windows.Media.Color.FromRgb((byte) 66, (byte) 213, (byte) 245),
System.Windows.Media.Color.FromRgb((byte) 220, (byte) 220, (byte) 240 /*0xF0*/),
System.Windows.Media.Color.FromRgb((byte) 136, (byte) 136, (byte) 170)
};
private DispatcherTimer _flappyTimer;
private double _birdY;
private double _birdVel;
private List<double[]> _pipes;
private int _flappyScore;
private int _flappyBest;
private bool _flappyAlive;
private bool _flappyStarted;
private double _flappySpawnAccum;
private double _starScroll;
private const double F_GRAVITY = 0.55;
private const double F_FLAP = -9.5;
private const double F_PIPE_SPD = 3.2;
private const double F_PIPE_GAP = 155.0;
private const double F_PIPE_W = 52.0;
private const double F_BIRD_X = 110.0;
private const double F_BIRD_SZ = 30.0;
public Games()
{
this.InitializeComponent();
this.InitSnake();
this.InitMinesweeper();
this.InitFlappy();
this.Loaded += (RoutedEventHandler) ((s, e) =>
{
this.SwitchTo(Games.GamePanel.Snake);
this.SnakeDraw();
this.FlappyDraw();
this.ApplyDarkMode();
});
this.SizeChanged += (SizeChangedEventHandler) ((s, e) =>
{
switch (this._activePanel)
{
case Games.GamePanel.Snake:
this.SnakeDraw();
break;
case Games.GamePanel.Flappy:
this.FlappyDraw();
break;
}
});
}
private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton != MouseButton.Left)
return;
this.DragMove();
}
private void MinimizeWindow(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void CloseHub(object sender, RoutedEventArgs e) => this.Close();
[DllImport("dwmapi.dll", CharSet = CharSet.Auto)]
private static extern int DwmSetWindowAttribute(
IntPtr hwnd,
int attr,
ref int attrValue,
int attrSize);
private void SwitchTo(Games.GamePanel panel)
{
this._snakeTimer?.Stop();
this._flappyTimer?.Stop();
this._mineTimer?.Stop();
this.PanelSnake.Visibility = Visibility.Collapsed;
this.PanelPaint.Visibility = Visibility.Collapsed;
this.PanelMine.Visibility = Visibility.Collapsed;
this.PanelFlappy.Visibility = Visibility.Collapsed;
this.BtnSnake.Style = (Style) this.FindResource((object) "TabBtn");
this.BtnPaint.Style = (Style) this.FindResource((object) "TabBtn");
this.BtnMine.Style = (Style) this.FindResource((object) "TabBtn");
this.BtnFlappy.Style = (Style) this.FindResource((object) "TabBtn");
this._activePanel = panel;
switch (panel)
{
case Games.GamePanel.Snake:
this.PanelSnake.Visibility = Visibility.Visible;
this.BtnSnake.Style = (Style) this.FindResource((object) "TabBtnActive");
this.SnakeCanvas.Focus();
this.SetStatus("Snake: Use arrow keys or WASD · SPACE to start");
break;
case Games.GamePanel.Paint:
this.PanelPaint.Visibility = Visibility.Visible;
this.BtnPaint.Style = (Style) this.FindResource((object) "TabBtnActive");
this.SetStatus("Paint: Left drag to draw · Walah");
break;
case Games.GamePanel.Mine:
this.PanelMine.Visibility = Visibility.Visible;
this.BtnMine.Style = (Style) this.FindResource((object) "TabBtnActive");
this.SetStatus("Minesweeper: Left-click reveal · Right-click flag");
break;
case Games.GamePanel.Flappy:
this.PanelFlappy.Visibility = Visibility.Visible;
this.BtnFlappy.Style = (Style) this.FindResource((object) "TabBtnActive");
this.FlappyCanvas.Focus();
this.FlappyDraw();
this.SetStatus("Flappy rat: SPACE or click to flap");
break;
}
}
private void SetStatus(string text) => this.StatusBarLeft.Text = text;
private void Nav_Snake(object sender, RoutedEventArgs e) => this.SwitchTo(Games.GamePanel.Snake);
private void Nav_Paint(object sender, RoutedEventArgs e) => this.SwitchTo(Games.GamePanel.Paint);
private void Nav_Minesweeper(object sender, RoutedEventArgs e)
{
this.SwitchTo(Games.GamePanel.Mine);
}
private void Nav_Flappy(object sender, RoutedEventArgs e)
{
this.SwitchTo(Games.GamePanel.Flappy);
}
private void InitSnake()
{
this._snakeTimer = new DispatcherTimer();
this._snakeTimer.Interval = TimeSpan.FromMilliseconds(80.0);
this._snakeTimer.Tick += new EventHandler(this.SnakeTick);
this.SnakeReset();
}
private void SnakeReset()
{
this._snakeTimer.Stop();
this._snakeRunning = false;
this._snakeAlive = true;
this._snakeScore = 0;
this._snakeDir = new Point(1.0, 0.0);
this._snakeNextDir = new Point(1.0, 0.0);
this._snakeTimer.Interval = TimeSpan.FromMilliseconds(80.0);
this._snakeBody = new List<Point>()
{
new Point(8.0, 11.0),
new Point(7.0, 11.0),
new Point(6.0, 11.0)
};
this.SnakeSpawnFood();
this.SnakeScoreTxt.Text = "0";
this.SnakeStatusTxt.Text = "Press SPACE to start";
this.SnakeDraw();
}
private void SnakeSpawnFood()
{
Point point;
do
{
point = new Point((double) this._rng.Next(1, 34), (double) this._rng.Next(1, 21));
}
while (this._snakeBody.Contains(point));
this._snakeFood = point;
}
private void SnakeTick(object sender, EventArgs e)
{
this._snakeDir = this._snakeNextDir;
Point point1 = new Point(this._snakeBody[0].X + this._snakeDir.X, this._snakeBody[0].Y + this._snakeDir.Y);
if (point1.X < 0.0 || point1.X >= 35.0 || point1.Y < 0.0 || point1.Y >= 22.0)
this.SnakeDie();
else if (this._snakeBody.Contains(point1))
{
this.SnakeDie();
}
else
{
this._snakeBody.Insert(0, point1);
if (point1 == this._snakeFood)
{
++this._snakeScore;
this.SnakeScoreTxt.Text = this._snakeScore.ToString();
this.SnakeSpawnFood();
double totalMilliseconds = this._snakeTimer.Interval.TotalMilliseconds;
if (totalMilliseconds > 65.0)
this._snakeTimer.Interval = TimeSpan.FromMilliseconds(totalMilliseconds - 2.0);
}
else
this._snakeBody.RemoveAt(this._snakeBody.Count - 1);
this.SnakeDraw();
}
}
private void SnakeDie()
{
this._snakeTimer.Stop();
this._snakeAlive = false;
this._snakeRunning = false;
this.SnakeStatusTxt.Text = $"Snake: You suck, score: {this._snakeScore} — SPACE to restart";
this.SetStatus($"Snake: Game over, score: {this._snakeScore}");
this.SnakeDraw();
}
private void SnakeDraw()
{
this.SnakeCanvas.Children.Clear();
double num1 = this.SnakeCanvas.ActualWidth > 0.0 ? this.SnakeCanvas.ActualWidth : 750.0;
double num2 = this.SnakeCanvas.ActualHeight > 0.0 ? this.SnakeCanvas.ActualHeight : 440.0;
double num3 = num1 / 35.0;
double num4 = num2 / 22.0;
for (int index1 = 0; index1 < 35; index1 += 4)
{
for (int index2 = 0; index2 < 22; index2 += 4)
{
Ellipse ellipse = new Ellipse();
ellipse.Width = 1.5;
ellipse.Height = 1.5;
ellipse.Fill = (Brush) new SolidColorBrush(Games.S_GRID_COLOR);
Ellipse element = ellipse;
Canvas.SetLeft((UIElement) element, (double) index1 * num3 + num3 / 2.0 - 0.75);
Canvas.SetTop((UIElement) element, (double) index2 * num4 + num4 / 2.0 - 0.75);
this.SnakeCanvas.Children.Add((UIElement) element);
}
}
DropShadowEffect dropShadowEffect = new DropShadowEffect();
dropShadowEffect.Color = Games.S_FOOD_COLOR;
dropShadowEffect.BlurRadius = 12.0;
dropShadowEffect.ShadowDepth = 0.0;
dropShadowEffect.Opacity = 0.8;
Ellipse ellipse1 = new Ellipse();
ellipse1.Width = num3 - 4.0;
ellipse1.Height = num4 - 4.0;
ellipse1.Fill = (Brush) new SolidColorBrush(Games.S_FOOD_COLOR);
ellipse1.Effect = (Effect) dropShadowEffect;
Ellipse element1 = ellipse1;
Canvas.SetLeft((UIElement) element1, this._snakeFood.X * num3 + 2.0);
Canvas.SetTop((UIElement) element1, this._snakeFood.Y * num4 + 2.0);
this.SnakeCanvas.Children.Add((UIElement) element1);
for (int index = 0; index < this._snakeBody.Count; ++index)
{
Point point = this._snakeBody[index];
byte num5 = (byte) ((1.0 - (double) index / (double) this._snakeBody.Count * 0.65) * (double) byte.MaxValue);
System.Windows.Media.Color color1;
if (index != 0)
{
int a = (int) num5;
System.Windows.Media.Color bodyColor = Games.S_BODY_COLOR;
int r = (int) bodyColor.R;
bodyColor = Games.S_BODY_COLOR;
int g = (int) bodyColor.G;
bodyColor = Games.S_BODY_COLOR;
int b = (int) bodyColor.B;
color1 = System.Windows.Media.Color.FromArgb((byte) a, (byte) r, (byte) g, (byte) b);
}
else
color1 = Games.S_HEAD_COLOR;
System.Windows.Media.Color color2 = color1;
Rectangle rectangle = new Rectangle();
rectangle.Width = num3 - 2.0;
rectangle.Height = num4 - 2.0;
rectangle.Fill = (Brush) new SolidColorBrush(color2);
rectangle.RadiusX = 4.0;
rectangle.RadiusY = 4.0;
Rectangle element2 = rectangle;
if (index == 0)
element2.Effect = (Effect) new DropShadowEffect()
{
Color = Games.S_HEAD_COLOR,
BlurRadius = 10.0,
ShadowDepth = 0.0,
Opacity = 0.7
};
Canvas.SetLeft((UIElement) element2, point.X * num3 + 1.0);
Canvas.SetTop((UIElement) element2, point.Y * num4 + 1.0);
this.SnakeCanvas.Children.Add((UIElement) element2);
}
if (this._snakeAlive)
return;
Rectangle element3 = new Rectangle();
element3.Width = num1;
element3.Height = num2;
element3.Fill = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromArgb((byte) 90, (byte) 10, (byte) 8, (byte) 25));
this.SnakeCanvas.Children.Add((UIElement) element3);
}
private void SnakeCanvas_KeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Space:
this.SnakeStartOrRestart();
break;
case Key.Left:
case Key.A:
if (this._snakeDir.X != 1.0)
{
this._snakeNextDir = new Point(-1.0, 0.0);
break;
}
break;
case Key.Up:
case Key.W:
if (this._snakeDir.Y != 1.0)
{
this._snakeNextDir = new Point(0.0, -1.0);
break;
}
break;
case Key.Right:
case Key.D:
if (this._snakeDir.X != -1.0)
{
this._snakeNextDir = new Point(1.0, 0.0);
break;
}
break;
case Key.Down:
case Key.S:
if (this._snakeDir.Y != -1.0)
{
this._snakeNextDir = new Point(0.0, 1.0);
break;
}
break;
}
e.Handled = true;
}
private void SnakeStartOrRestart()
{
this.SnakeReset();
this._snakeRunning = true;
this._snakeAlive = true;
this._snakeTimer.Interval = TimeSpan.FromMilliseconds(80.0);
this._snakeTimer.Start();
this.SnakeStatusTxt.Text = "Arrow keys / WASD";
}
private void SnakeRestart(object sender, RoutedEventArgs e)
{
this.SnakeStartOrRestart();
this.SnakeCanvas.Focus();
}
private void PaintColor_Click(object sender, RoutedEventArgs e)
{
if (!(sender is Button button))
return;
string tag = button.Tag as string;
if (string.IsNullOrEmpty(tag))
return;
this._isEraser = false;
this._paintColor = (System.Windows.Media.Color) ColorConverter.ConvertFromString(tag);
this.ColorPreview.Background = (Brush) new SolidColorBrush(this._paintColor);
this.BtnEraser.Style = (Style) this.FindResource((object) "TabBtn");
}
private void BrushSlider_Changed(object sender, RoutedPropertyChangedEventArgs<double> e)
{
this._brushSize = e.NewValue;
}
private void PaintEraser_Click(object sender, RoutedEventArgs e)
{
this._isEraser = !this._isEraser;
this.BtnEraser.Style = this._isEraser ? (Style) this.FindResource((object) "TabBtnActive") : (Style) this.FindResource((object) "TabBtn");
}
private void PaintClear_Click(object sender, RoutedEventArgs e)
{
this.PaintCanvas.Children.Clear();
}
private void PaintCanvas_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton != MouseButtonState.Pressed)
return;
this._isPainting = true;
this._lastPaintPt = e.GetPosition((IInputElement) this.PaintCanvas);
this.PaintCanvas.CaptureMouse();
this.PaintDot(this._lastPaintPt);
}
private void PaintCanvas_MouseMove(object sender, MouseEventArgs e)
{
if (!this._isPainting || e.LeftButton != MouseButtonState.Pressed)
return;
Point position = e.GetPosition((IInputElement) this.PaintCanvas);
this.PaintStroke(this._lastPaintPt, position);
this._lastPaintPt = position;
}
private void PaintCanvas_MouseUp(object sender, MouseButtonEventArgs e)
{
this._isPainting = false;
this.PaintCanvas.ReleaseMouseCapture();
}
private void PaintDot(Point p)
{
System.Windows.Media.Color color = this._isEraser ? Colors.White : this._paintColor;
double num = this._brushSize / 2.0;
Ellipse ellipse = new Ellipse();
ellipse.Width = this._brushSize;
ellipse.Height = this._brushSize;
ellipse.Fill = (Brush) new SolidColorBrush(color);
Ellipse element = ellipse;
Canvas.SetLeft((UIElement) element, p.X - num);
Canvas.SetTop((UIElement) element, p.Y - num);
this.PaintCanvas.Children.Add((UIElement) element);
}
private void PaintStroke(Point from, Point to)
{
int num1 = Math.Max(1, (int) (Math.Sqrt(Math.Pow(to.X - from.X, 2.0) + Math.Pow(to.Y - from.Y, 2.0)) / (this._brushSize / 4.0)));
for (int index = 1; index <= num1; ++index)
{
double num2 = (double) index / (double) num1;
this.PaintDot(new Point(from.X + (to.X - from.X) * num2, from.Y + (to.Y - from.Y) * num2));
}
}
private void InitMinesweeper()
{
this._mineTimer = new DispatcherTimer();
this._mineTimer.Interval = TimeSpan.FromSeconds(1.0);
this._mineTimer.Tick += (EventHandler) ((s, e) =>
{
++this._mineSeconds;
this.MineTimerTxt.Text = $"{this._mineSeconds}s";
});
this.MineSetup();
}
private void MineSetup()
{
this._mineTimer.Stop();
this._mineSeconds = 0;
this._mineFirstClick = true;
this._mineGameOver = false;
this._mineFlags = 0;
this._mineGrid = new int[9, 9];
this._mineRevealed = new bool[9, 9];
this._mineFlagged = new bool[9, 9];
this.MineTimerTxt.Text = "0s";
this.MineCountTxt.Text = 10.ToString();
this.MineStatusTxt.Text = "Left-click reveal or Right-click flag";
this.MineOverlay.Visibility = Visibility.Collapsed;
this.MineRebuild();
}
private void MinePlaceMines(int safeR, int safeC)
{
int num1 = 0;
while (num1 < 10)
{
int index1 = this._rng.Next(9);
int index2 = this._rng.Next(9);
if (this._mineGrid[index1, index2] != -1 && (Math.Abs(index1 - safeR) > 1 || Math.Abs(index2 - safeC) > 1))
{
this._mineGrid[index1, index2] = -1;
++num1;
}
}
for (int index3 = 0; index3 < 9; ++index3)
{
for (int index4 = 0; index4 < 9; ++index4)
{
if (this._mineGrid[index3, index4] != -1)
{
int num2 = 0;
for (int index5 = -1; index5 <= 1; ++index5)
{
for (int index6 = -1; index6 <= 1; ++index6)
{
int index7 = index3 + index5;
int index8 = index4 + index6;
if (index7 >= 0 && index7 < 9 && index8 >= 0 && index8 < 9 && this._mineGrid[index7, index8] == -1)
++num2;
}
}
this._mineGrid[index3, index4] = num2;
}
}
}
}
private void MineFloodReveal(int r, int c)
{
if (r < 0 || r >= 9 || c < 0 || c >= 9 || this._mineRevealed[r, c] || this._mineFlagged[r, c])
return;
this._mineRevealed[r, c] = true;
if (this._mineGrid[r, c] != 0)
return;
for (int index1 = -1; index1 <= 1; ++index1)
{
for (int index2 = -1; index2 <= 1; ++index2)
this.MineFloodReveal(r + index1, c + index2);
}
}
private bool MineCheckWin()
{
for (int index1 = 0; index1 < 9; ++index1)
{
for (int index2 = 0; index2 < 9; ++index2)
{
if (this._mineGrid[index1, index2] != -1 && !this._mineRevealed[index1, index2])
return false;
}
}
return true;
}
private void MineRebuild()
{
this.MineGridCtrl.Children.Clear();
for (int row = 0; row < 9; ++row)
{
for (int col = 0; col < 9; ++col)
this.MineGridCtrl.Children.Add((UIElement) this.BuildMineCell(row, col));
}
}
private Button BuildMineCell(int row, int col)
{
Button button1 = new Button();
button1.Width = 35.0;
button1.Height = 35.0;
button1.Margin = new Thickness(1.0);
button1.FontSize = 14.0;
button1.FontWeight = FontWeights.Bold;
button1.BorderThickness = new Thickness(0.0);
button1.Cursor = Cursors.Hand;
button1.Tag = (object) new int[2]{ row, col };
Button button2 = button1;
if (!this._mineRevealed[row, col])
{
button2.Background = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 42, (byte) 40, (byte) 62));
button2.Foreground = (Brush) Brushes.White;
button2.Content = this._mineFlagged[row, col] ? (object) "\uD83D\uDEA9" : (object) "";
SolidColorBrush normalBg = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 42, (byte) 40, (byte) 62));
SolidColorBrush hoverBg = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 58, (byte) 55, (byte) 88));
button2.MouseEnter += (MouseEventHandler) ((s, e) =>
{
if (this._mineGameOver)
return;
((Control) s).Background = (Brush) hoverBg;
});
button2.MouseLeave += (MouseEventHandler) ((s, e) =>
{
if (this._mineGameOver)
return;
((Control) s).Background = (Brush) normalBg;
});
button2.Template = this.BuildCellTemplate();
}
else
{
button2.Background = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 24, (byte) 23, (byte) 36));
button2.BorderThickness = new Thickness(1.0);
button2.BorderBrush = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 42, (byte) 40, (byte) 64 /*0x40*/));
button2.IsEnabled = false;
if (this._mineGrid[row, col] == -1)
{
button2.Background = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 80 /*0x50*/, (byte) 24, (byte) 24));
button2.Content = (object) "";
}
else
{
int index = this._mineGrid[row, col];
if (index > 0 && index < Games.NumColors.Length)
{
button2.Foreground = (Brush) new SolidColorBrush(Games.NumColors[index]);
button2.Content = (object) index.ToString();
}
}
button2.Template = this.BuildRevealedTemplate();
}
button2.Click += new RoutedEventHandler(this.MineCell_Click);
button2.MouseRightButtonDown += new MouseButtonEventHandler(this.MineCell_RightClick);
return button2;
}
private ControlTemplate BuildCellTemplate()
{
ControlTemplate controlTemplate = new ControlTemplate(typeof (Button));
FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof (Border));
frameworkElementFactory.Name = "bd";
frameworkElementFactory.SetBinding(Border.BackgroundProperty, (BindingBase) new Binding("Background")
{
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent)
});
frameworkElementFactory.SetValue(Border.CornerRadiusProperty, (object) new CornerRadius(5.0));
FrameworkElementFactory child = new FrameworkElementFactory(typeof (ContentPresenter));
child.SetValue(FrameworkElement.HorizontalAlignmentProperty, (object) HorizontalAlignment.Center);
child.SetValue(FrameworkElement.VerticalAlignmentProperty, (object) VerticalAlignment.Center);
frameworkElementFactory.AppendChild(child);
controlTemplate.VisualTree = frameworkElementFactory;
return controlTemplate;
}
private ControlTemplate BuildRevealedTemplate()
{
ControlTemplate controlTemplate = new ControlTemplate(typeof (Button));
FrameworkElementFactory frameworkElementFactory = new FrameworkElementFactory(typeof (Border));
frameworkElementFactory.SetBinding(Border.BackgroundProperty, (BindingBase) new Binding("Background")
{
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent)
});
frameworkElementFactory.SetBinding(Border.BorderBrushProperty, (BindingBase) new Binding("BorderBrush")
{
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent)
});
frameworkElementFactory.SetBinding(Border.BorderThicknessProperty, (BindingBase) new Binding("BorderThickness")
{
RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent)
});
frameworkElementFactory.SetValue(Border.CornerRadiusProperty, (object) new CornerRadius(4.0));
FrameworkElementFactory child = new FrameworkElementFactory(typeof (ContentPresenter));
child.SetValue(FrameworkElement.HorizontalAlignmentProperty, (object) HorizontalAlignment.Center);
child.SetValue(FrameworkElement.VerticalAlignmentProperty, (object) VerticalAlignment.Center);
frameworkElementFactory.AppendChild(child);
controlTemplate.VisualTree = frameworkElementFactory;
return controlTemplate;
}
private void MineCell_Click(object sender, RoutedEventArgs e)
{
if (this._mineGameOver)
return;
int[] tag = (int[]) ((FrameworkElement) sender).Tag;
int index1 = tag[0];
int index2 = tag[1];
if (this._mineFlagged[index1, index2])
return;
if (this._mineFirstClick)
{
this._mineFirstClick = false;
this.MinePlaceMines(index1, index2);
this._mineTimer.Start();
}
if (this._mineGrid[index1, index2] == -1)
{
this._mineGameOver = true;
this._mineTimer.Stop();
for (int index3 = 0; index3 < 9; ++index3)
{
for (int index4 = 0; index4 < 9; ++index4)
{
if (this._mineGrid[index3, index4] == -1)
this._mineRevealed[index3, index4] = true;
}
}
this.MineRebuild();
this.MineOverlayTxt.Text = $"You suck, your time: {this._mineSeconds}s";
this.MineOverlay.Visibility = Visibility.Visible;
this.MineStatusTxt.Text = "Click New Game to retry";
this.SetStatus("Minesweeper: Try better next time");
}
else
{
this.MineFloodReveal(index1, index2);
this.MineRebuild();
if (!this.MineCheckWin())
return;
this._mineGameOver = true;
this._mineTimer.Stop();
this.MineOverlayTxt.Text = $"You won, get a life, {this._mineSeconds}s";
this.MineOverlay.Visibility = Visibility.Visible;
this.MineStatusTxt.Text = "Kaboom kaboom...";
this.SetStatus($"Minesweeper: Won in {this._mineSeconds}s!");
}
}
private void MineCell_RightClick(object sender, MouseButtonEventArgs e)
{
if (this._mineGameOver)
return;
int[] tag = (int[]) ((FrameworkElement) sender).Tag;
int index1 = tag[0];
int index2 = tag[1];
if (this._mineRevealed[index1, index2])
return;
this._mineFlagged[index1, index2] = !this._mineFlagged[index1, index2];
this._mineFlags += this._mineFlagged[index1, index2] ? 1 : -1;
this.MineCountTxt.Text = (10 - this._mineFlags).ToString();
this.MineRebuild();
}
private void MineRestart(object sender, RoutedEventArgs e) => this.MineSetup();
private void InitFlappy()
{
this._flappyTimer = new DispatcherTimer();
this._flappyTimer.Interval = TimeSpan.FromMilliseconds(16.0);
this._flappyTimer.Tick += new EventHandler(this.FlappyTick);
this.FlappyReset(false);
}
private void FlappyReset(bool autoStart)
{
this._flappyTimer.Stop();
this._birdY = 230.0;
this._birdVel = 0.0;
this._pipes = new List<double[]>();
this._flappyScore = 0;
this._flappyAlive = true;
this._flappyStarted = autoStart;
this._flappySpawnAccum = 0.0;
this.FlappyScoreTxt.Text = "0";
this.FlappyStatusTxt.Text = autoStart ? "SPACE / Click to jump" : "Press SPACE or Click to start";
this.FlappyDraw();
if (!autoStart)
return;
this._flappyTimer.Start();
this.FlappyCanvas.Focus();
}
private void FlappyTick(object sender, EventArgs e)
{
double num1 = this.FlappyCanvas.ActualWidth > 0.0 ? this.FlappyCanvas.ActualWidth : 760.0;
double ch = this.FlappyCanvas.ActualHeight > 0.0 ? this.FlappyCanvas.ActualHeight : 440.0;
this._birdVel += 0.55;
this._birdY += this._birdVel;
this._starScroll = (this._starScroll + 0.6) % num1;
this._flappySpawnAccum += 3.2;
if (this._flappySpawnAccum >= 265.0)
{
this._flappySpawnAccum = 0.0;
double num2 = (double) this._rng.Next((int) (ch * 0.22), (int) (ch * 0.72));
this._pipes.Add(new double[2]{ num1 + 52.0, num2 });
}
for (int index = this._pipes.Count - 1; index >= 0; --index)
{
double num3 = this._pipes[index][0];
double num4 = num3 - 3.2;
this._pipes[index][0] = num4;
double num5 = 125.0;
if (num3 > num5 && num4 <= num5)
{
++this._flappyScore;
this.FlappyScoreTxt.Text = this._flappyScore.ToString();
if (this._flappyScore > this._flappyBest)
{
this._flappyBest = this._flappyScore;
this.FlappyBestTxt.Text = this._flappyBest.ToString();
}
}
if (num4 + 52.0 < 0.0)
this._pipes.RemoveAt(index);
}
if (this._birdY + 30.0 > ch || this._birdY < 0.0)
{
this.FlappyDie(ch);
}
else
{
foreach (double[] pipe in this._pipes)
{
double num6 = pipe[0];
double num7 = pipe[1];
if ((135.0 > num6 && 115.0 < num6 + 52.0) & (this._birdY + 5.0 < num7 - 77.5 || this._birdY + 30.0 - 5.0 > num7 + 77.5))
{
this.FlappyDie(ch);
return;
}
}
this.FlappyDraw();
}
}
private void FlappyDie(double ch)
{
this._flappyTimer.Stop();
this._flappyAlive = false;
this._flappyStarted = false;
this._birdY = Math.Min(this._birdY, ch - 30.0);
this.FlappyDraw();
this.FlappyStatusTxt.Text = string.Format("You suck: SPACE to restart", (object) this._flappyScore);
this.SetStatus($"You suck, Score: {this._flappyScore}");
}
private void FlappyDraw()
{
this.FlappyCanvas.Children.Clear();
double num1 = this.FlappyCanvas.ActualWidth > 0.0 ? this.FlappyCanvas.ActualWidth : 760.0;
double num2 = this.FlappyCanvas.ActualHeight > 0.0 ? this.FlappyCanvas.ActualHeight : 440.0;
byte[] numArray1 = new byte[6]
{
(byte) 12,
(byte) 13,
(byte) 14,
(byte) 14,
(byte) 15,
(byte) 16 /*0x10*/
};
byte[] numArray2 = new byte[6]
{
(byte) 16 /*0x10*/,
(byte) 18,
(byte) 20,
(byte) 22,
(byte) 24,
(byte) 27
};
byte[] numArray3 = new byte[6]
{
(byte) 24,
(byte) 28,
(byte) 34,
(byte) 40,
(byte) 46,
(byte) 52
};
for (int index = 0; index < 6; ++index)
{
Rectangle rectangle = new Rectangle();
rectangle.Width = num1;
rectangle.Height = num2 / 6.0 + 1.0;
rectangle.Fill = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb(numArray1[index], numArray2[index], numArray3[index]));
Rectangle element = rectangle;
Canvas.SetTop((UIElement) element, (double) index * num2 / 6.0);
this.FlappyCanvas.Children.Add((UIElement) element);
}
Random random = new Random(42);
for (int index = 0; index < 55; ++index)
{
double length1 = ((random.NextDouble() * num1 * 2.8 - this._starScroll) % num1 + num1) % num1;
double length2 = random.NextDouble() * num2 * 0.78;
double num3 = random.NextDouble() * 1.8 + 0.4;
byte a = (byte) random.Next(80 /*0x50*/, 210);
Ellipse ellipse = new Ellipse();
ellipse.Width = num3;
ellipse.Height = num3;
ellipse.Fill = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromArgb(a, (byte) 200, (byte) 200, byte.MaxValue));
Ellipse element = ellipse;
Canvas.SetLeft((UIElement) element, length1);
Canvas.SetTop((UIElement) element, length2);
this.FlappyCanvas.Children.Add((UIElement) element);
}
foreach (double[] pipe in this._pipes)
{
double length3 = pipe[0];
double num4 = pipe[1];
double num5 = num4 - 77.5;
double length4 = num4 + 77.5;
double num6 = num2 - 22.0 - length4;
SolidColorBrush solidColorBrush1 = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 58, (byte) 136, (byte) 60));
SolidColorBrush solidColorBrush2 = new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 44, (byte) 104, (byte) 46));
if (num5 > 0.0)
{
Rectangle rectangle1 = new Rectangle();
rectangle1.Width = 52.0;
rectangle1.Height = num5;
rectangle1.Fill = (Brush) solidColorBrush1;
Rectangle element1 = rectangle1;
Canvas.SetLeft((UIElement) element1, length3);
Canvas.SetTop((UIElement) element1, 0.0);
this.FlappyCanvas.Children.Add((UIElement) element1);
Rectangle rectangle2 = new Rectangle();
rectangle2.Width = 60.0;
rectangle2.Height = 12.0;
rectangle2.Fill = (Brush) solidColorBrush2;
rectangle2.RadiusX = 3.0;
rectangle2.RadiusY = 3.0;
Rectangle element2 = rectangle2;
Canvas.SetLeft((UIElement) element2, length3 - 4.0);
Canvas.SetTop((UIElement) element2, num5 - 12.0);
this.FlappyCanvas.Children.Add((UIElement) element2);
}
if (num6 > 0.0)
{
Rectangle rectangle3 = new Rectangle();
rectangle3.Width = 52.0;
rectangle3.Height = num6;
rectangle3.Fill = (Brush) solidColorBrush1;
Rectangle element3 = rectangle3;
Canvas.SetLeft((UIElement) element3, length3);
Canvas.SetTop((UIElement) element3, length4);
this.FlappyCanvas.Children.Add((UIElement) element3);
Rectangle rectangle4 = new Rectangle();
rectangle4.Width = 60.0;
rectangle4.Height = 12.0;
rectangle4.Fill = (Brush) solidColorBrush2;
rectangle4.RadiusX = 3.0;
rectangle4.RadiusY = 3.0;
Rectangle element4 = rectangle4;
Canvas.SetLeft((UIElement) element4, length3 - 4.0);
Canvas.SetTop((UIElement) element4, length4);
this.FlappyCanvas.Children.Add((UIElement) element4);
}
}
Rectangle rectangle5 = new Rectangle();
rectangle5.Width = num1;
rectangle5.Height = 22.0;
rectangle5.Fill = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 34, (byte) 58, (byte) 34));
Rectangle element5 = rectangle5;
Canvas.SetTop((UIElement) element5, num2 - 22.0);
this.FlappyCanvas.Children.Add((UIElement) element5);
Rectangle rectangle6 = new Rectangle();
rectangle6.Width = num1;
rectangle6.Height = 3.0;
rectangle6.Fill = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 74, (byte) 160 /*0xA0*/, (byte) 74));
Rectangle element6 = rectangle6;
Canvas.SetTop((UIElement) element6, num2 - 22.0);
this.FlappyCanvas.Children.Add((UIElement) element6);
double angle = Math.Max(-35.0, Math.Min(35.0, this._birdVel * 3.5));
Ellipse ellipse1 = new Ellipse();
ellipse1.Width = 30.0;
ellipse1.Height = 25.5;
ellipse1.Fill = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 139, (byte) 108, (byte) 208 /*0xD0*/));
Ellipse element7 = ellipse1;
if (this._flappyAlive)
element7.Effect = (Effect) new DropShadowEffect()
{
Color = System.Windows.Media.Color.FromRgb((byte) 123, (byte) 92, (byte) 191),
BlurRadius = 10.0,
ShadowDepth = 0.0,
Opacity = 0.8
};
element7.RenderTransform = (Transform) new TransformGroup()
{
Children = {
(Transform) new RotateTransform(angle, 15.0, 12.75)
}
};
Canvas.SetLeft((UIElement) element7, 110.0);
Canvas.SetTop((UIElement) element7, this._birdY);
this.FlappyCanvas.Children.Add((UIElement) element7);
Ellipse ellipse2 = new Ellipse();
ellipse2.Width = 9.0;
ellipse2.Height = 9.0;
ellipse2.Fill = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 176 /*0xB0*/, (byte) 149, (byte) 232));
Ellipse element8 = ellipse2;
Canvas.SetLeft((UIElement) element8, 125.0);
Canvas.SetTop((UIElement) element8, this._birdY - 5.0);
this.FlappyCanvas.Children.Add((UIElement) element8);
Ellipse ellipse3 = new Ellipse();
ellipse3.Width = 7.0;
ellipse3.Height = 7.0;
ellipse3.Fill = (Brush) Brushes.White;
Ellipse element9 = ellipse3;
Canvas.SetLeft((UIElement) element9, 128.0);
Canvas.SetTop((UIElement) element9, this._birdY + 4.2);
this.FlappyCanvas.Children.Add((UIElement) element9);
Ellipse ellipse4 = new Ellipse();
ellipse4.Width = 4.0;
ellipse4.Height = 4.0;
ellipse4.Fill = (Brush) Brushes.Black;
Ellipse element10 = ellipse4;
Canvas.SetLeft((UIElement) element10, 129.5);
Canvas.SetTop((UIElement) element10, this._birdY + 4.2 + 1.5);
this.FlappyCanvas.Children.Add((UIElement) element10);
if (!this._flappyAlive)
{
TextBlock element11 = new TextBlock()
{
Text = "✕",
Foreground = (Brush) Brushes.Red,
FontSize = 9.0,
FontWeight = FontWeights.Bold
};
Canvas.SetLeft((UIElement) element11, 126.5);
Canvas.SetTop((UIElement) element11, this._birdY + 5.0);
this.FlappyCanvas.Children.Add((UIElement) element11);
}
if (this._flappyStarted)
return;
Border element12 = new Border()
{
Background = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromArgb((byte) 200, (byte) 12, (byte) 10, (byte) 30)),
CornerRadius = new CornerRadius(10.0),
Padding = new Thickness(24.0, 14.0, 24.0, 14.0)
};
StackPanel stackPanel1 = new StackPanel();
stackPanel1.HorizontalAlignment = HorizontalAlignment.Center;
StackPanel stackPanel2 = stackPanel1;
UIElementCollection children1 = stackPanel2.Children;
TextBlock element13 = new TextBlock();
element13.Text = "Flappy rat";
element13.Foreground = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 155, (byte) 124, (byte) 224 /*0xE0*/));
element13.FontSize = 24.0;
element13.FontWeight = FontWeights.Bold;
element13.HorizontalAlignment = HorizontalAlignment.Center;
children1.Add((UIElement) element13);
UIElementCollection children2 = stackPanel2.Children;
TextBlock element14 = new TextBlock();
element14.Text = "SPACE or Click to start";
element14.Foreground = (Brush) new SolidColorBrush(System.Windows.Media.Color.FromRgb((byte) 136, (byte) 134, (byte) 170));
element14.FontSize = 13.0;
element14.HorizontalAlignment = HorizontalAlignment.Center;
element14.Margin = new Thickness(0.0, 6.0, 0.0, 0.0);
children2.Add((UIElement) element14);
element12.Child = (UIElement) stackPanel2;
Canvas.SetLeft((UIElement) element12, num1 / 2.0 - 115.0);
Canvas.SetTop((UIElement) element12, num2 / 2.0 - 45.0);
this.FlappyCanvas.Children.Add((UIElement) element12);
}
private void FlappyFlap()
{
if (!this._flappyStarted || !this._flappyAlive)
this.FlappyReset(true);
else
this._birdVel = -9.5;
}
private void FlappyCanvas_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
this.FlappyFlap();
e.Handled = true;
}
private void FlappyCanvas_MouseDown(object sender, MouseButtonEventArgs e)
{
this.FlappyFlap();
this.FlappyCanvas.Focus();
}
private void FlappyRestart(object sender, RoutedEventArgs e) => this.FlappyReset(true);
private void ApplyDarkMode()
{
bool flag = this.IsWindowsDarkMode();
IntPtr handle = new WindowInteropHelper((Window) this).Handle;
int attrValue = flag ? 1 : 0;
Games.DwmSetWindowAttribute(handle, 20, ref attrValue, Marshal.SizeOf(typeof (int)));
}
private bool IsWindowsDarkMode()
{
using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"))
{
if (registryKey != null)
{
if (registryKey.GetValue("AppsUseLightTheme") is int num)
return num == 0;
}
}
return false;
}
private enum GamePanel
{
Snake,
Paint,
Mine,
Flappy,
}
}