⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appsettings.cs

📁 C#开发的运行于windows mobile PDA上的游戏
💻 CS
字号:
////////////////////////////////////////////////
// 
// Project: Lines.NET
// Version: 1.1
// Author:  Vladimir L.
// 
// homepage: http://www.boomsoft.org
// e-mail:   support@boomsoft.org
// 
// Copyright (c) 2003-2004, Boomsoft.org
// 

using System;
using Lines.Utils;

namespace Lines
{
	/// <summary>
	/// The application settings class.
	/// </summary>
	/// 
	/// <remarks>
	/// <p>The <b>AppSettings</b> class is implemented as a singleton, it encloses all application 
	/// settings and provides the direct access to each of them via properties of this class.</p>
	/// 
	/// <p>This class also provides facilities to serialize settings using <see cref="AppSettings.Load()"/>
	/// and <see cref="AppSettings.Save()"/> methods. The settings are loaded on start up of application 
	/// and saved when user attempts to close it. The class defines also the <b>default</b> values for 
	/// each of its settings for the case of a a first application run or if there was missing application
	/// property in a serialized version.</p>
	/// 
	/// <p>The <b>AppSettings</b> class is using <see cref="Lines.Utils.Properties"/> class to handle 
	/// properties and its serialization capabilities to serialize and deserialize them.</p>
	/// <seealso cref="Lines.Utils.Properties"/>
	/// </remarks>
	public class AppSettings
	{
		#region Default values
		/// <summary>
		/// Specifies the location of application settings file name.
		/// </summary>
		/// <remarks>
		/// The file will be looked up in the application start-up folder with a help of
		/// <see cref="Lines.Utils.PathHelper.GetAppFile(string)"/> method.
		/// </remarks>
		private const string PROPERTIES_FILENAME	= "settings.xml";

		/// <summary>
		/// Defines the default value for <see cref="BallsPerStep"/> property.
		/// </summary>
		private const int BALLS_PER_STEP			= 3;
		/// <summary>
		/// Defines the default value for <see cref="MinBallsInLine"/> property.
		/// </summary>
		private const int MIN_BALLS_IN_LINE			= 5;

		/// <summary>
		/// Defines the default value for <see cref="BoardWidth"/> property.
		/// </summary>
		private const int BOARD_WIDTH				= 9;
		/// <summary>
		/// Defines the default value for <see cref="BoardHeight"/> property.
		/// </summary>
		private const int BOARD_HEIGHT				= 9;
		/// <summary>
		/// Defines the default value for <see cref="Colors"/> property.
		/// </summary>
		private const int COLOR_AMOUNT				= 6;

		/// <summary>
		/// Defines the default value for <see cref="HiScoreListSize"/> property.
		/// </summary>
		private const int HI_SCORE_LIST_SIZE		= 10;
		/// <summary>
		/// Defines the default value for <see cref="HiScoreListFile"/> property.
		/// </summary>
		private const string HI_SCORE_FILENAME		= "hiscore.xml";

		/// <summary>
		/// Defines the default value for <see cref="PauseMoveBall"/> property.
		/// </summary>
		private const int MOVE_BALL_PAUSE			= 200;

		/// <summary>
		/// Defines the default value for <see cref="PauseDestroyBall"/> property.
		/// </summary>
		private const int DESTROY_BALL_PAUSE		= 500;

		/// <summary>
		/// Defines the default value for <see cref="PauseDestroyBall"/> property.
		/// </summary>
		private const int MAGIC_PADDING				= 24;

		/// <summary>
		/// Defines the value of <see cref="FactorPxToPt"/> property.
		/// </summary>
		private const float FACTOR_PX_TO_PT			= 1f / 96 * 72;

		/// <summary>
		/// Defines the default value for <see cref="SoundMoveFile"/> property.
		/// </summary>
		private const string SOUND_MOVE_FILENAME	= "move.wav";
		/// <summary>
		/// Defines the default value for <see cref="SoundDestroyFile"/> property.
		/// </summary>
		private const string SOUND_DESTROY_FILENAME	= "destroy.wav";
		/// <summary>
		/// Defines the default value for <see cref="SoundBlockedFile"/> property.
		/// </summary>
		private const string SOUND_BLOCKED_FILENAME	= "cantmove.wav";
		#endregion
		
		#region Singleton
		/// <summary>
		/// Holds the reference to a single instance of this class for whole application.
		/// </summary>
		private static AppSettings instance;

		/// <summary>
		/// Private constructor may be used only by this class. It is a part of implementation of 
		/// singleton pattern.
		/// </summary>
		private AppSettings()
		{
			Load();
		}
		
		/// <summary>
		/// The read-only property that refers to the only instance of <b>AppSettings</b> class
		/// </summary>
		public static AppSettings Instance
		{
			get
			{
				if (instance == null)
				{
					instance = new AppSettings();
				}
				return instance;
			}
		}
		#endregion

		/// <summary>
		/// The instance of a <see cref="Utils.Properties"/> class that is used to hold and handle
		/// the application settings.
		/// </summary>
		private readonly Properties props = new Properties();

		/// <summary>
		/// Loads the properties from the application configuration file.
		/// </summary>
		public void Load()
		{
			props.Load(PathHelper.GetAppFile(PROPERTIES_FILENAME));
		}

		/// <summary>
		/// Saves the properties to the application configuration file.
		/// </summary>
		public void Save()
		{
			props.Save(PathHelper.GetAppFile(PROPERTIES_FILENAME));
		}

		/// <summary>
		/// Gets or sets the amount of new balls that will appear on each step of the game.
		/// </summary>
		public int BallsPerStep
		{
			get {return props.GetProperty("ballsPerStep", BALLS_PER_STEP);}
			set {props.SetProperty("ballsPerStep", value);}
		}

		/// <summary>
		/// Gets or sets the minimum amount of balls the same color in line to be a reason to
		/// remove (collapse, destroy) them from the board.
		/// </summary>
		public int MinBallsInLine
		{
			get {return props.GetProperty("minBallsInLine", MIN_BALLS_IN_LINE);}
			set {props.SetProperty("minBallsInLine", value);}
		}

		/// <summary>
		/// Gets or sets the length of hi score list.
		/// </summary>
		public int HiScoreListSize
		{
			get {return props.GetProperty("hiScoreListSize", HI_SCORE_LIST_SIZE);}
			set {props.SetProperty("hiScoreListSize", value);}
		}

		/// <summary>
		/// Gets or sets the name of file where hi score list is serialized.
		/// </summary>
		public string HiScoreListFile
		{
			get {return props.GetProperty("hiScoreListFile", HI_SCORE_FILENAME);}
			set {props.SetProperty("hiScoreListFile", value);}
		}

		/// <summary>
		/// Gets or sets a value of the board's width.
		/// </summary>
		public int BoardWidth
		{
			get {return props.GetProperty("boardWidth", BOARD_WIDTH);}
			set {props.SetProperty("boardWidth", value);}
		}

		/// <summary>
		/// Gets or sets a value of the board's height.
		/// </summary>
		public int BoardHeight
		{
			get {return props.GetProperty("boardHeight", BOARD_HEIGHT);}
			set {props.SetProperty("boardHeight", value);}
		}

		/// <summary>
		/// Gets or sets the amount of different ball colors for the game.
		/// </summary>
		public int Colors
		{
			get {return props.GetProperty("colors", COLOR_AMOUNT);}
			set {props.SetProperty("colors", value);}
		}

		/// <summary>
		/// Gets the factor of pixel to point transformation.
		/// </summary>
		/// <remarks>
		/// <p>The size of font in .NET Compact Framework can be defined only in pt, not 
		/// in pixels. Therefore transformation is required to fit the font size into a 
		/// certain height. 1 pt = 1 / 72 inch. Screen resolution is 96 dpi in Windows.
		/// Let's suppose it is the same for Windows CE.NET &amp; Pocket PC 2002/2003. Thus 
		/// the factor is calculated as:</p>
		/// <code>
		/// FactorPxToPt = 1f / 96 * 72;
		/// </code>
		/// </remarks>
		public float FactorPxToPt
		{
			get {return FACTOR_PX_TO_PT;}
		}

		/// <summary>
		/// Gets a value of magic padding for the game board location in pixels.
		/// <seealso cref="MainForm.menuSize"/>
		/// </summary>
		/// <remarks>
		/// Dirty but fast solution for adjusting the location of play board
		/// in Windows CE.NET where menu is placed at the top of dialog unlike 
		/// Pocket PC 2002/2003 where menu is at the bottom of screen.
		/// </remarks>
		public int MagicPadding
		{
			get {return props.GetProperty("magicPadding", MAGIC_PADDING);}
		}

		/// <summary>
		/// Gets or sets a value of delay for destroy balls worker in milliseconds.
		/// <seealso cref="Lines.Core.DestroyBallsWorker"/>
		/// </summary>
		public int PauseDestroyBall
		{
			get {return props.GetProperty("pauseDestroyBall", DESTROY_BALL_PAUSE);}
			set {props.SetProperty("pauseDestroyBall", value);}
		}

		/// <summary>
		/// Gets or sets a value of delay for move ball worker in milliseconds.
		/// <seealso cref="Lines.Core.MoveBallWorker"/>
		/// </summary>
		public int PauseMoveBall
		{
			get {return props.GetProperty("pauseMoveBall", MOVE_BALL_PAUSE);}
			set {props.SetProperty("pauseMoveBall", value);}
		}

		/// <summary>
		/// Gets or sets the file name of ball movement sound.
		/// </summary>
		/// <remarks>
		/// The file name should be defined as a relative to the application 
		/// start-up folder path.
		/// </remarks>
		public string SoundMoveFile
		{
			get {return props.GetProperty("soundMoveFile", SOUND_MOVE_FILENAME);}
			set {props.SetProperty("soundMoveFile", value);}
		}

		/// <summary>
		/// Gets or sets the file name of ball collapse sound.
		/// </summary>
		/// <remarks>
		/// The file name should be defined as a relative to the application 
		/// start-up folder path.
		/// </remarks>
		public string SoundDestroyFile
		{
			get {return props.GetProperty("soundDestroyFile", SOUND_DESTROY_FILENAME);}
			set {props.SetProperty("soundDestroyFile", value);}
		}

		/// <summary>
		/// Gets or sets the file name of blocked ball sound.
		/// </summary>
		/// <remarks>
		/// The file name should be defined as a relative to the application 
		/// start-up folder path.
		/// </remarks>
		public string SoundBlockedFile
		{
			get {return props.GetProperty("soundBlockedFile", SOUND_BLOCKED_FILENAME);}
			set {props.SetProperty("soundBlockedFile", value);}
		}

		/// <summary>
		/// Gets or sets a value of property, which defines whether to use sound during
		/// the game or not.
		/// </summary>
		public bool UseSound
		{
			get {return props.GetProperty("useSound", true);}
			set {props.SetProperty("useSound", value);}
		}

		/// <summary>
		/// Gets or sets a value that defines a way to destroy (collapse) balls.
		/// </summary>
		/// <remarks>
		/// If the value of this property is <c>true</c> then balls will be destroyed
		/// one after another, othewise they will be collapsed all at once.
		/// </remarks>
		public bool OneByOneDestroy
		{
			get {return props.GetProperty("oneByOneDestroy", true);}
			set {props.SetProperty("oneByOneDestroy", value);}
		}

		/// <summary>
		/// Returns <c>true</c> if the application is run under Pocket PC 2002/2003,
		/// <c>false</c> in case it is run under Windows CE.NET.
		/// </summary>
		/// <remarks>
		/// <p>Due to the lack of .NET Compact Framework to detect whether the application is 
		/// started under Windows CE.NET or Pocket PC 2002/2003, this property is used to 
		/// determine the OS.</p>
		/// 
		/// <p>This property must be set manually through editing the "settings.xml" file
		/// after first launch of application.</p>
		/// </remarks>
		public bool IsPocketPC
		{
			get {return props.GetProperty("isPocketPC", true);}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -