forked from ericlaw1979/babysmash
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Utils.cs
108 lines (92 loc) · 3.83 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
namespace BabySmash
{
internal static class Utils
{
private static readonly Dictionary<Color, string> brushToString;
private static readonly Random lRandom = new Random(); // BUG BUG: Believe it or not, Random is NOT THREAD SAFE!
private static readonly FunCursor1 fun1 = new FunCursor1();
private static readonly FunCursor2 fun2 = new FunCursor2();
private static readonly Color[] someColors;
private static readonly string[] sounds = {
"giggle.wav",
"babylaugh.wav",
"babygigl2.wav",
"ccgiggle.wav",
"laughingmice.wav",
"scooby2.wav",
};
static Utils()
{
brushToString = new Dictionary<Color, string>
{
{Colors.Red, "Red"},
{Colors.Blue, "Blue"},
{Colors.Yellow, "Yellow"},
{Colors.Green, "Green"},
{Colors.Purple, "Purple"},
{Colors.Pink, "Pink"},
{Colors.Orange, "Orange"},
{Colors.Tan, "Tan"},
{Colors.Gray, "Gray"}
};
someColors = new Color[brushToString.Count];
brushToString.Keys.CopyTo(someColors, 0);
}
public static Color GetRandomColor()
{
Color color = someColors[lRandom.Next(0, someColors.Length)];
return color;
}
public static Brush GetGradientBrush(Color color)
{
RadialGradientBrush myBrush = new RadialGradientBrush();
myBrush.GradientOrigin = new Point(0.75, 0.25);
myBrush.GradientStops.Add(new GradientStop(color.LightenOrDarken(50), 0.0));
myBrush.GradientStops.Add(new GradientStop(color, 0.5));
myBrush.GradientStops.Add(new GradientStop(color.LightenOrDarken(-50), 1.0));
return myBrush;
}
public static Color LightenOrDarken(this Color src, sbyte degree)
{
Color ret = new Color();
ret.A = src.A;
ret.R = (byte)Math.Max(Math.Min(src.R + degree, 255), 0);
ret.G = (byte)Math.Max(Math.Min(src.G + degree, 255), 0);
ret.B = (byte)Math.Max(Math.Min(src.B + degree, 255), 0);
return ret;
}
public static string ColorToString(Color b)
{
return brushToString[b];
}
public static string GetRandomSoundFile()
{
return sounds[lRandom.Next(0, sounds.Length)];
}
public static bool GetRandomBoolean()
{
if (lRandom.Next(0, 2) == 0)
return false;
return true;
}
public static int RandomBetweenTwoNumbers(int min, int max)
{
return lRandom.Next(min, max + 1);
}
internal static System.Windows.Controls.UserControl GetCursor()
{
switch (Properties.Settings.Default.CursorType)
{
case "Hand":
return fun2;
case "Arrow":
return fun1;
}
return fun1;
}
}
}