2008-06-02 22:49:35 +04:00
|
|
|
|
using System;
|
2008-06-12 05:10:22 +04:00
|
|
|
|
using System.Collections.Generic;
|
2008-07-11 00:47:38 +04:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows.Markup;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Xml;
|
2008-06-02 22:49:35 +04:00
|
|
|
|
|
|
|
|
|
namespace BabySmash
|
|
|
|
|
{
|
2008-07-11 00:47:38 +04:00
|
|
|
|
internal static class Utils
|
|
|
|
|
{
|
|
|
|
|
private static readonly Dictionary<Color, string> brushToString;
|
|
|
|
|
private static readonly Random lRandom = new Random();
|
2008-09-18 04:03:58 +04:00
|
|
|
|
|
|
|
|
|
private static readonly FunCursor1 fun1 = new FunCursor1();
|
|
|
|
|
private static readonly FunCursor2 fun2 = new FunCursor2();
|
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
2008-06-12 05:10:22 +04:00
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
public static Color GetRandomColor()
|
|
|
|
|
{
|
|
|
|
|
Color color = someColors[lRandom.Next(0, someColors.Length)];
|
|
|
|
|
return color;
|
|
|
|
|
}
|
2008-06-13 22:16:03 +04:00
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
public static Brush GetGradientBrush(Color color)
|
|
|
|
|
{
|
|
|
|
|
RadialGradientBrush myBrush = new RadialGradientBrush();
|
|
|
|
|
myBrush.GradientOrigin = new Point(0.75, 0.25);
|
2008-07-16 00:48:58 +04:00
|
|
|
|
myBrush.GradientStops.Add(new GradientStop(color.LightenOrDarken(50), 0.0));
|
2008-07-11 00:47:38 +04:00
|
|
|
|
myBrush.GradientStops.Add(new GradientStop(color, 0.5));
|
2008-07-16 00:48:58 +04:00
|
|
|
|
myBrush.GradientStops.Add(new GradientStop(color.LightenOrDarken(-50), 1.0));
|
2008-07-11 00:47:38 +04:00
|
|
|
|
return myBrush;
|
|
|
|
|
}
|
2008-06-13 22:16:03 +04:00
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
2008-06-02 22:49:35 +04:00
|
|
|
|
|
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
public static string ColorToString(Color b)
|
|
|
|
|
{
|
|
|
|
|
return brushToString[b];
|
|
|
|
|
}
|
2008-06-12 05:10:22 +04:00
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
public static string GetRandomSoundFile()
|
|
|
|
|
{
|
|
|
|
|
string retVal = sounds[lRandom.Next(0, sounds.Length)];
|
|
|
|
|
return ".Resources.Sounds." + retVal;
|
|
|
|
|
}
|
2008-06-02 22:49:35 +04:00
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
public static bool GetRandomBoolean()
|
|
|
|
|
{
|
|
|
|
|
if (lRandom.Next(0, 2) == 0)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-06-02 22:49:35 +04:00
|
|
|
|
|
2008-07-11 00:47:38 +04:00
|
|
|
|
public static int RandomBetweenTwoNumbers(int min, int max)
|
|
|
|
|
{
|
|
|
|
|
return lRandom.Next(min, max + 1);
|
|
|
|
|
}
|
2008-07-18 21:07:51 +04:00
|
|
|
|
|
|
|
|
|
internal static System.Windows.Controls.UserControl GetCursor()
|
|
|
|
|
{
|
|
|
|
|
switch (Properties.Settings.Default.CursorType)
|
|
|
|
|
{
|
|
|
|
|
case "Hand":
|
2008-09-18 04:03:58 +04:00
|
|
|
|
return fun2;
|
|
|
|
|
case "Arrow":
|
|
|
|
|
return fun1;
|
2008-07-18 21:07:51 +04:00
|
|
|
|
}
|
2008-09-18 04:03:58 +04:00
|
|
|
|
return fun1;
|
2008-07-18 21:07:51 +04:00
|
|
|
|
}
|
2008-07-11 00:47:38 +04:00
|
|
|
|
}
|
|
|
|
|
}
|